Skip to content
This repository has been archived by the owner on Jun 27, 2023. It is now read-only.

Account for incosistencies of mime-types between rww-play and banana-rdf #131

Closed
wants to merge 1 commit into from

Conversation

reederz
Copy link

@reederz reederz commented Feb 6, 2015

Needed this to get react-foaf up and running. Perhaps there's a better way to solve this and it should be reported to banana-rdf people. What do you think?

@bblfish
Copy link
Member

bblfish commented Feb 6, 2015

what inconsistencies?

@reederz
Copy link
Author

reederz commented Feb 6, 2015

Here's what banana-rdf can parse https://github.com/w3c/banana-rdf/blob/master/rdf/common/src/main/scala/org/w3/banana/io/MimeType.scala#L25-32 . As you can see, they have Ntriples mime type as "application/ntriples" whereas you have it as "text/n3". Same with RdfXml, they have "text/rdf+xml" whereas you have it as "application/rdf+xml".

@ColinMaudry
Copy link

@bblfish
Copy link
Member

bblfish commented Feb 6, 2015

The RDF 1.1 N-Triples W3C Recommendation states that the NTriples media type is application/n-triples

@ColinMaudry
Copy link

Thanks, my bad. Here is the right link http://www.w3.org/TR/n-triples/


MimeType("text", "turtle"),
MimeType("application", "rdf+xml"),
MimeType("text", "rdf+xml"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think AllRdfMimeTypes should contain only the official mime types. text/rdf+xml is an old no longer recommended one. On the other hand one could add ntriples now, as we have specialised parsers for those.

@bblfish
Copy link
Member

bblfish commented Feb 6, 2015

How did you come to the conclusion that you needed to make these exact changes to get react-foaf running?

@reederz
Copy link
Author

reederz commented Feb 6, 2015

I'll work through changes one by one.

1. text/turtle; charset=utf-8 can't be parsed because banana-rdf only has parser for text/turtle

Stack trace

Caused by: rww.ldp.ParserException: Can't parse http://bblfish.net/people/henry/card with any mime types of Set(MimeType(text,turtle,Map( charset -> utf-8))). Original contentType was Some(text/turtle; charset=utf-8)
    at rww.ldp.WSClient$$anonfun$rww$ldp$WSClient$$tryToReadAsGraph$1.applyOrElse(WebClient.scala:134) ~[na:na]
    at rww.ldp.WSClient$$anonfun$rww$ldp$WSClient$$tryToReadAsGraph$1.applyOrElse(WebClient.scala:134) ~[na:na]
    at scala.runtime.AbstractPartialFunction.apply(AbstractPartialFunction.scala:33) ~[scala-library.jar:na]
    at scala.util.Failure.recoverWith(Try.scala:172) ~[scala-library.jar:na]
    at rww.ldp.WSClient.rww$ldp$WSClient$$tryToReadAsGraph(WebClient.scala:134) ~[na:na]
    at rww.ldp.WSClient$$anonfun$fetch$1.apply(WebClient.scala:95) ~[na:na]
    ... 16 common frames omitted
Caused by: rww.ldp.MissingParserException: no RDF Reader found for mime type MimeType(text,turtle,Map( charset -> utf-8)) for reading http://bblfish.net/people/henry/card

Solution: https://github.com/jolocom/rww-play/blob/21cb9651de43a657e174c913707c0ed96d39f251/app/rww/ldp/WebClient.scala#L159

2. Can't parse application/rdf+xml because banana-rdf only has parser for text/rdf+xml

Stacktrace:

Caused by: rww.ldp.ParserException: Can't parse https://social.umeahackerspace.se/mmn/foaf with any mime types of Set(MimeType(application,rdf+xml,Map())). Original contentType was Some(application/rdf+xml)
    at rww.ldp.WSClient$$anonfun$rww$ldp$WSClient$$tryToReadAsGraph$1.applyOrElse(WebClient.scala:134) ~[na:na]
    at rww.ldp.WSClient$$anonfun$rww$ldp$WSClient$$tryToReadAsGraph$1.applyOrElse(WebClient.scala:134) ~[na:na]
    at scala.runtime.AbstractPartialFunction.apply(AbstractPartialFunction.scala:33) ~[scala-library.jar:na]
    at scala.util.Failure.recoverWith(Try.scala:172) ~[scala-library.jar:na]
    at rww.ldp.WSClient.rww$ldp$WSClient$$tryToReadAsGraph(WebClient.scala:134) ~[na:na]
    at rww.ldp.WSClient$$anonfun$fetch$1.apply(WebClient.scala:95) ~[na:na]
    ... 16 common frames omitted
Caused by: rww.ldp.MissingParserException: no RDF Reader found for mime type MimeType(application,rdf+xml,Map()) for reading https://social.umeahackerspace.se/mmn/foaf
    at rww.ldp.WSClient.rww$ldp$WSClient$$readGraph(WebClient.scala:174) ~[na:na]

Solution: https://github.com/jolocom/rww-play/blob/21cb9651de43a657e174c913707c0ed96d39f251/app/rww/ldp/WebClient.scala#L157

3. Same with text/n3 vs. application/ntriples . Although I can't reproduce it anymore, here's the solution: https://github.com/jolocom/rww-play/blob/21cb9651de43a657e174c913707c0ed96d39f251/app/rww/ldp/WebClient.scala#L158

@reederz
Copy link
Author

reederz commented Feb 6, 2015

Without the change no.1 , react-foaf won't even load. With the changes, I get your foaf graph nicely loaded in the browser:
screenshot_2015-02-06_20-05-53

@reederz
Copy link
Author

reederz commented Feb 6, 2015

@bblfish I can clean up this PR with the stuff from you comments if needed.

@bblfish
Copy link
Member

bblfish commented Feb 6, 2015

First one Caused by: rww.ldp.ParserException: Can't parse http://bblfish.net/people/henry/card with any mime types of Set(MimeType(text,turtle,Map( charset -> utf-8))). Original contentType was Some(text/turtle; charset=utf-8)
There are a couple of problems there:

  • the banana-rdf mime type parser does not trim whitecaps from the attribute=values ( and so it leaves a whitespace in " charset"->"uff-8"
  • the banana-rdf mime type parser currently removes the charset attributes, but I now think it should not do so, because otherwise there is no way to specify the encoding for the parser, so we end up probably having to assume that all rdf is in utf-8, which will be wrong.
  • that means that the parser selector may need to be rewritten.

Given that there are better libraries we want to use for all the http stuff, your solution could be a reasonable hack until we move to such a lib. But on the other hand we could try to get this right...

@antonkulaga antonkulaga added ready and removed ready labels Feb 8, 2015
@reederz reederz self-assigned this Feb 8, 2015
@ghost
Copy link

ghost commented Feb 9, 2015

better libraries we want to use for all the http stuff

What http stuff are you referring to here? eg b-rdf mime, the actual parsers, etc

@ghost
Copy link

ghost commented Feb 9, 2015

Looking at http://www.w3.org/TR/n-triples/ the content has to be UTF-8 and no optional parameters are permitted

Looking at http://www.w3.org/TR/turtle/, the content has to be UTF-8 but an optional parameter of "charset" may be provided with only the value "UTF-8".

So it looks to me, after a very quick look (ie I may be completely wrong) that the official specs are not accurately implemented in b-rdf. Iff that's the case, seems reasonable to fix it in b.rdf.

If there are other non.conforming examples there (such as instance where other charsets may be specified), they should be updated and the specific laws applied.

@reederz
Copy link
Author

reederz commented Feb 9, 2015

It seems to me that you're right. Let's see if @bblfish can second it. Perhaps then we should make an issue on b-rdf.

@bblfish
Copy link
Member

bblfish commented Feb 15, 2015

Do these latest fixes solve the problems here? banana-rdf/banana-rdf#228
My guess is that we are not dealing well enough with character encodings, but this should be ok for this version.

@reederz
Copy link
Author

reederz commented Feb 15, 2015

I still get errors about application/rss+xml; charset=UTF-8 , text/plain; charset=utf-8 . But it works for the other formats discussed in this thread. I guess we could close the issue (or do we wait until it's in w3c/banana-rdf?)

@bblfish
Copy link
Member

bblfish commented Feb 15, 2015

@reederz , that is because the first format is not rdf - it could be seen as such with the right parser, but that needs to be written - and the second is not rdf either.

@reederz
Copy link
Author

reederz commented Feb 15, 2015

both of them seem to have rdf data in them, regardless of the mime types.

@reederz reederz closed this Feb 15, 2015
@bblfish
Copy link
Member

bblfish commented Feb 15, 2015

yes, in the case of text/plain it is the server's mistake then. They should publish the info in the correct mime type. We can build something later to help notify people of these mistakes. Rss+xml if it is rss1.0 is very close to rdf... Working with other people's mistakes is something for later. :-)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants