Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HttpLoader: Suppress HTTP Content-Type validation #132

Closed
jmvanel opened this issue Dec 25, 2020 · 6 comments · Fixed by #157
Closed

HttpLoader: Suppress HTTP Content-Type validation #132

jmvanel opened this issue Dec 25, 2020 · 6 comments · Fixed by #157
Labels
enhancement New feature or request
Milestone

Comments

@jmvanel
Copy link
Contributor

jmvanel commented Dec 25, 2020

Feature request is related to a problem

I'm frustrated when a JSON-LD source has a linked @context whose MIME type is not one of the JSON expected types.
In this case it is a raw github URL, that says test/plain .
This, or a file, is very convenient to develop and debug a new @context .
Moreover, being explicitly loaded as a @context , is is supposed to be application/ld+json .
I deserves a warning for sure, but not a blocking exception.

scala> JsonLd.toRdf("https://geb.ffspeleo.fr/api/api/v2/").get()
com.apicatalog.jsonld.JsonLdError: There was a problem encountered loading a remote context [code=LOADING_REMOTE_CONTEXT_FAILED].
  at com.apicatalog.jsonld.context.ActiveContextBuilder.fetch(ActiveContextBuilder.java:523)
  at com.apicatalog.jsonld.context.ActiveContextBuilder.create(ActiveContextBuilder.java:173)
  at com.apicatalog.jsonld.expansion.ObjectExpansion.initLocalContext(ObjectExpansion.java:202)
  at com.apicatalog.jsonld.expansion.ObjectExpansion.expand(ObjectExpansion.java:101)
  at com.apicatalog.jsonld.expansion.Expansion.compute(Expansion.java:116)
  at com.apicatalog.jsonld.processor.ExpansionProcessor.expand(ExpansionProcessor.java:124)
  at com.apicatalog.jsonld.processor.ToRdfProcessor.toRdf(ToRdfProcessor.java:69)
  at com.apicatalog.jsonld.processor.ToRdfProcessor.toRdf(ToRdfProcessor.java:58)
  at com.apicatalog.jsonld.api.ToRdfApi.get(ToRdfApi.java:175)
  ... 31 elided
Caused by: com.apicatalog.jsonld.JsonLdError: Unsupported media type 'text/plain'. Supported content types are [application/ld+json, application/json, +json, application/n-quads]
  at com.apicatalog.jsonld.document.DocumentParser.fireUnsupportedMediaType(DocumentParser.java:99)
  at com.apicatalog.jsonld.document.DocumentParser.parse(DocumentParser.java:60)
  at com.apicatalog.jsonld.loader.HttpLoader.createDocument(HttpLoader.java:242)
  at com.apicatalog.jsonld.loader.HttpLoader.loadDocument(HttpLoader.java:202)
  at com.apicatalog.jsonld.loader.SchemeRouter.loadDocument(SchemeRouter.java:62)
  at com.apicatalog.jsonld.context.ActiveContextBuilder.fetch(ActiveContextBuilder.java:519)
  ... 39 more

Other JSON-LD engines

JENA (with jsonld-java) processes such JSON-LD source well :
$JENA/bin/riot --output=turtle --syntax=jsonld https://geb.ffspeleo.fr/api/api/v2/
The Playground also accepts such input:

{
  "@context": "https://raw.githubusercontent.com/jmvanel/Karstlink-ontology/master/geb.ffspeleo.fr_context.jsonld",
  "@graph": [
    {
      "@id": "321",
      "@type": "UndergroundCavity",
      "name": "Biefs Bousset",
      "latitude": "46.99406",
      "longitude": "6.07472",
      "altitude": "770",
      "locates": [
        {
          "@id": "628",
          "@type": "geo:Point",
          "label": "station_321-590",
          "dwc:Occurrence": [
            {
              "@id": "4278",
              "@type": "dwc:Occurrence",
              "event date": "2010-03-07",
              "associated taxa": "Amilenus aurantiacus",
              "dwci:toTaxon": "http://taxref.mnhn.fr/lod/taxon/337326/13.0"
            }
            ]
        }
      ]
    }
  ]  
}
@filip26
Copy link
Owner

filip26 commented Dec 25, 2020

JSON-LD 1.1 specification is quite strict on how to deal with content type that does not represent the content.

  1. Otherwise, the retrieved document's Content-Type is neither application/json, application/ld+json, nor any other media type using a +json suffix as defined in [RFC6839]. Reject the promise passing a loading document failed error.

9.4.1. LoadDocumentCallback

FYI: Jena does not support JSON-LD 1.1 but 1.0

You can download the content on your side or you can implement an interceptor replacing wrong content type header.

@filip26 filip26 added the wontfix This will not be worked on label Dec 25, 2020
@filip26 filip26 closed this as completed Dec 25, 2020
@jmvanel
Copy link
Contributor Author

jmvanel commented Dec 25, 2020

The spec. is indeed clear, but a Feature can be an extension to the spec. , as Playground does ( silently , which is not good ).
I mean, an explicit option could be set in the API, plus a warning at runtime.

@filip26 filip26 changed the title Linked @context whose MIME type is not one of the JSON expected types HttpLoader: Suppress HTTP Content-Type validation Dec 25, 2020
@filip26 filip26 added enhancement New feature or request and removed wontfix This will not be worked on labels Dec 25, 2020
@filip26 filip26 reopened this Dec 25, 2020
@github-actions
Copy link

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days

@github-actions github-actions bot added the Stale label Jan 25, 2021
@filip26 filip26 removed the Stale label Jan 25, 2021
@github-actions
Copy link

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days

@github-actions github-actions bot added the Stale label Feb 25, 2021
@filip26 filip26 removed the Stale label Feb 25, 2021
@github-actions
Copy link

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days

@github-actions github-actions bot added the Stale label Mar 28, 2021
@filip26 filip26 removed the Stale label Mar 28, 2021
@filip26 filip26 added this to the 1.1.0 milestone Apr 24, 2021
filip26 added a commit that referenced this issue Apr 24, 2021
@filip26 filip26 linked a pull request Apr 24, 2021 that will close this issue
@filip26
Copy link
Owner

filip26 commented Apr 25, 2021

Since 1.1.0 you can create your own instance of HttpLoader and set fallback content type.

e.g.

HttpLoader lodaer = new HttpLoader(DefaultHttpClient.defaultInstance());
loader.setFallbackContentType(MediaType.JSON);
...
options.setDocumentLoader(loader);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants