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 2015/05/28 21:35:11 UTC

[4/7] jena git commit: JENA-950 : Generate bad request on runtime parser errors.

JENA-950 : Generate bad request on runtime parser errors.

Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/7f806f73
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/7f806f73
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/7f806f73

Branch: refs/heads/master
Commit: 7f806f737f217e0d8c60e751b47409b3d1ffdd11
Parents: 50c63f6
Author: Andy Seaborne <an...@apache.org>
Authored: Thu May 28 20:20:03 2015 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Thu May 28 20:20:03 2015 +0100

----------------------------------------------------------------------
 .../org/apache/jena/fuseki/servlets/SPARQL_Protocol.java    | 9 ++++-----
 .../java/org/apache/jena/fuseki/servlets/SPARQL_Query.java  | 9 +++++++--
 .../java/org/apache/jena/fuseki/servlets/SPARQL_Update.java | 7 ++++---
 3 files changed, 15 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/7f806f73/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Protocol.java
----------------------------------------------------------------------
diff --git a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Protocol.java b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Protocol.java
index 0be8b6c..f605060 100644
--- a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Protocol.java
+++ b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Protocol.java
@@ -24,14 +24,14 @@ import static org.apache.jena.riot.web.HttpNames.paramNamedGraphURI ;
 import java.util.Arrays ;
 import java.util.Collections ;
 import java.util.List ;
-import java.util.function.Predicate;
+import java.util.function.Predicate ;
 
 import javax.servlet.http.HttpServletRequest ;
 
 import org.apache.jena.atlas.iterator.Iter ;
 import org.apache.jena.atlas.lib.Lib ;
 import org.apache.jena.query.Query ;
-import org.apache.jena.query.QueryParseException ;
+import org.apache.jena.query.QueryException ;
 import org.apache.jena.sparql.core.DatasetDescription ;
 
 /** Support for the SPARQL protocol (SPARQL Query, SPARQL Update)
@@ -40,9 +40,8 @@ public  abstract class SPARQL_Protocol extends ActionSPARQL
 {
     protected SPARQL_Protocol() { super() ; }
 
-    protected static String messageForQPE(QueryParseException ex)
-    {
-        if ( ex.getMessage() != null )
+    protected static String messageForQueryException(QueryException ex)
+    { if ( ex.getMessage() != null )
             return ex.getMessage() ;
         if ( ex.getCause() != null )
             return Lib.classShortName(ex.getCause().getClass()) ;

http://git-wip-us.apache.org/repos/asf/jena/blob/7f806f73/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Query.java
----------------------------------------------------------------------
diff --git a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Query.java b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Query.java
index 28212a8..c411989 100644
--- a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Query.java
+++ b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Query.java
@@ -239,7 +239,7 @@ public abstract class SPARQL_Query extends SPARQL_Protocol
         } catch (ActionErrorException ex) {
             throw ex ;
         } catch (QueryParseException ex) {
-            ServletOps.errorBadRequest("Parse error: \n" + queryString + "\n\r" + messageForQPE(ex)) ;
+            ServletOps.errorBadRequest("Parse error: \n" + queryString + "\n\r" + messageForQueryException(ex)) ;
         }
         // Should not happen.
         catch (QueryException ex) {
@@ -255,7 +255,12 @@ public abstract class SPARQL_Query extends SPARQL_Protocol
                 // Deals with exceptions itself.
                 sendResults(action, result, query.getPrologue()) ;
             }
-        } catch (QueryCancelledException ex) {
+        } 
+        catch (QueryParseException ex) {
+            // Late stage static error (e.g. bad fixed Lucene query string). 
+            ServletOps.errorBadRequest("Query parse error: \n" + queryString + "\n\r" + messageForQueryException(ex)) ;
+        }
+        catch (QueryCancelledException ex) {
             // Additional counter information.
             incCounter(action.getEndpoint().getCounters(), QueryTimeouts) ;
             throw ex ;

http://git-wip-us.apache.org/repos/asf/jena/blob/7f806f73/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Update.java
----------------------------------------------------------------------
diff --git a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Update.java b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Update.java
index 52ba1a5..1750a1d 100644
--- a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Update.java
+++ b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Update.java
@@ -51,6 +51,7 @@ import org.apache.jena.fuseki.FusekiLib ;
 import org.apache.jena.graph.Node ;
 import org.apache.jena.graph.NodeFactory ;
 import org.apache.jena.iri.IRI ;
+import org.apache.jena.query.QueryBuildException ;
 import org.apache.jena.query.QueryParseException ;
 import org.apache.jena.query.Syntax ;
 import org.apache.jena.riot.system.IRIResolver ;
@@ -210,7 +211,7 @@ public class SPARQL_Update extends SPARQL_Protocol
                 req = UpdateFactory.read(usingList, input, UpdateParseBase, Syntax.syntaxARQ);
             }
             catch (UpdateException ex) { ServletOps.errorBadRequest(ex.getMessage()) ; return ; }
-            catch (QueryParseException ex) { ServletOps.errorBadRequest(messageForQPE(ex)) ; return ; }
+            catch (QueryParseException ex) { ServletOps.errorBadRequest(messageForQueryException(ex)) ; return ; }
         }
         
         action.beginWrite() ;
@@ -224,10 +225,10 @@ public class SPARQL_Update extends SPARQL_Protocol
             action.abort() ;
             incCounter(action.getEndpoint().getCounters(), UpdateExecErrors) ;
             ServletOps.errorOccurred(ex.getMessage()) ;
-        } catch (QueryParseException ex) {
+        } catch (QueryParseException|QueryBuildException ex) {
             action.abort() ;
             // Counter inc'ed further out.
-            ServletOps.errorBadRequest(messageForQPE(ex)) ;
+            ServletOps.errorBadRequest(messageForQueryException(ex)) ;
         } catch (Throwable ex) {
             if ( ! ( ex instanceof ActionErrorException ) )
             {