You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2013/04/17 22:09:21 UTC

svn commit: r1469055 - /jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/ResponseResultSet.java

Author: andy
Date: Wed Apr 17 20:09:20 2013
New Revision: 1469055

URL: http://svn.apache.org/r1469055
Log:
Improve handling of query timeouts.
1/ Send dev/debugging explanation after stopping sending streamed results 
2/ Copy result set early for text output to generate the right
   HTTP status code - do before starting to format results.
   

Modified:
    jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/ResponseResultSet.java

Modified: jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/ResponseResultSet.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/ResponseResultSet.java?rev=1469055&r1=1469054&r2=1469055&view=diff
==============================================================================
--- jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/ResponseResultSet.java (original)
+++ jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/ResponseResultSet.java Wed Apr 17 20:09:20 2013
@@ -28,6 +28,7 @@ import javax.servlet.http.HttpServletReq
 import javax.servlet.http.HttpServletResponse ;
 
 import org.apache.commons.lang.StringUtils ;
+import org.apache.jena.atlas.io.IO ;
 import org.apache.jena.atlas.web.AcceptList ;
 import org.apache.jena.atlas.web.MediaType ;
 import org.apache.jena.fuseki.DEF ;
@@ -39,7 +40,9 @@ import static org.apache.jena.atlas.lib.
 import org.slf4j.Logger ;
 import org.slf4j.LoggerFactory ;
 
+import com.hp.hpl.jena.query.QueryCancelledException ;
 import com.hp.hpl.jena.query.ResultSet ;
+import com.hp.hpl.jena.query.ResultSetFactory ;
 import com.hp.hpl.jena.query.ResultSetFormatter ;
 import com.hp.hpl.jena.sparql.core.Prologue ;
 
@@ -161,21 +164,28 @@ public class ResponseResultSet
                     }
                 }, request, response) ;
             }
+            catch (QueryCancelledException ex)
+            { 
+                // Bother.  Status code 200 already sent.
+                // 
+                log.info("") ; }
             // This catches things like NIO exceptions.
             catch (Exception ex) { log.debug("Exception [SELECT/JSON] "+ex, ex) ; } 
             return ;
         }
 
         // ---- Form: text
+        // Text is not streaming.
         if ( equal(serializationType, WebContent.contentTypeTextPlain) )
         {
             try {
+                final ResultSet rs = (resultSet != null ) ? ResultSetFactory.makeRewindable(resultSet) : null ;
                 textOutput(contentType, new OutputContent(){
                     @Override
                     public void output(ServletOutputStream out)
                     {
-                        if ( resultSet != null )
-                            ResultSetFormatter.out(out, resultSet, qPrologue) ;
+                        if ( rs != null )
+                            ResultSetFormatter.out(out, rs, qPrologue) ;
                         if (  booleanResult != null )
                             ResultSetFormatter.out(out, booleanResult.booleanValue()) ;
                     }
@@ -188,6 +198,13 @@ public class ResponseResultSet
 //                else
 //                    log.debug("IOException [SELECT/Text] (ignored) "+ioEx, ioEx) ;
 //            }
+            catch (QueryCancelledException ex)
+            {
+                log.info("[SELECT/Text] Query timeout during execution") ;
+                try {
+                    response.sendError(HttpSC.SERVICE_UNAVAILABLE_503, "Query timeout during execution") ;
+                } catch (IOException ex2) { IO.exception(ex2) ; }
+            }
             // This catches things like NIO exceptions.
             catch (Exception ex) { log.debug("Exception [SELECT/Text] "+ex, ex) ; } 
             return ;
@@ -250,11 +267,22 @@ public class ResponseResultSet
             setHttpResponse(httpRequest, httpResponse, contentType, charset) ; 
             httpResponse.setStatus(HttpSC.OK_200) ;
             ServletOutputStream out = httpResponse.getOutputStream() ;
-            proc.output(out) ;
+            try
+            {
+                proc.output(out) ;
+            } catch (QueryCancelledException ex)
+            {
+                out.println() ;
+                out.println("##  Query cancelled due to timeout during execution   ##") ;
+                out.println("##  ****          Incomplete results           ****   ##") ;
+                out.flush() ;
+                errorOccurred(ex) ;
+            }
             out.flush() ;
             // Do not call httpResponse.flushBuffer(); here - Jetty closes the stream if it is a gzip stream
             // then the JSON callback closing details can't be added. 
-        } catch (IOException ex) { errorOccurred(ex) ; }
+        } 
+        catch (IOException ex) { errorOccurred(ex) ; }
     }
 
     public static void setHttpResponse(HttpServletRequest httpRequest,