read-write-web / rww-play

read write web Play
59 stars 19 forks source link

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

Closed reederz closed 9 years ago

reederz commented 9 years ago

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 commented 9 years ago

what inconsistencies?

reederz commented 9 years ago

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 commented 9 years ago

For the record, W3C says the MIME type of N-triples is text/plain and the MIME type of RDF/XML is application/rdf+xml.

bblfish commented 9 years ago

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

ColinMaudry commented 9 years ago

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

bblfish commented 9 years ago

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

reederz commented 9 years ago

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 commented 9 years ago

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 commented 9 years ago

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

bblfish commented 9 years ago

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:

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...

ghost commented 9 years ago

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 commented 9 years ago

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 commented 9 years ago

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 commented 9 years ago

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

reederz commented 9 years ago

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 commented 9 years ago

@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 commented 9 years ago

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

bblfish commented 9 years ago

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. :-)