You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Sarven Capadisli <in...@csarven.ca> on 2012/07/02 11:23:45 UTC

Fuseki and JSONP

Hi,

I was recently told that the callback parameter for a Fuseki service 
request doesn't properly wrap the brackets e.g.,

http://worldbank.270a.info/sparql?query=SELECT%20DISTINCT%20*%20WHERE%20%7B%3Chttp%3A%2F%2Fworldbank.270a.info%2Fclassification%2Fvariable%2Fpr%3E%20%3Fproperty%20%3Fobject%7D&output=json&callback=lodlive

Note the missing closing bracket, ')'.

I've briefly checked:

src/main/java/org/apache/jena/fuseki/servlets/ResponseResultSet.java

Not tested: Should the closing bracket line be out.println(")") ?

-Sarven

Re: Fuseki and JSONP

Posted by Andy Seaborne <an...@apache.org>.
On 02/07/12 10:23, Sarven Capadisli wrote:
> Hi,
>
> I was recently told that the callback parameter for a Fuseki service
> request doesn't properly wrap the brackets e.g.,
>
> http://worldbank.270a.info/sparql?query=SELECT%20DISTINCT%20*%20WHERE%20%7B%3Chttp%3A%2F%2Fworldbank.270a.info%2Fclassification%2Fvariable%2Fpr%3E%20%3Fproperty%20%3Fobject%7D&output=json&callback=lodlive
>
>
> Note the missing closing bracket, ')'.
>
> I've briefly checked:
>
> src/main/java/org/apache/jena/fuseki/servlets/ResponseResultSet.java
>
> Not tested: Should the closing bracket line be out.println(")") ?

No - it's much, much weirder than that!

The code has:

             if ( callback != null )
             {
                 out.print(")") ;
                 out.println() ;
             }

so that's OK.

Or is it?!

Your HTTP request allowed for gzip (Accept-Encoding: gzip, deflate).  So 
the stream is gzip'ed.

It seems that Jetty closes gzip'ed streams when you flush an HTTP 
response.  It merely flushes an un-compressed stream.

Jetty's GzipResponseWrapper ==>

	public void flushBuffer() throws IOException
         {
             if (_writer!=null)
                 _writer.flush();
             if (_gzStream!=null)
                 _gzStream.finish();   <--********
             else
                 getResponse().flushBuffer();
         }



So "out", or the underlying stream, is closed and that code throws an 
IOException.  But can't set the HTTP status code because 
HttpServletResponse.flushBuffer has been called and the 200 already 
sent.  This is a Jetty bug - the servletAPI documentation does not say 
that flushBuffer is the end of the request.

If you don't set Accept-Encoding it works just fine - flush means flush 
and the trailing")" is written just fine.

Oddly: Tomcat6:
https://issues.apache.org/bugzilla/show_bug.cgi?id=48738

Yuk.

Thanks for the report ... need to code round this.

	Andy

>
> -Sarven