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/10/23 22:38:10 UTC

[09/13] jena git commit: JENA-1055: Handle OPTIONS for query and update.

JENA-1055: Handle OPTIONS for query and update.


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

Branch: refs/heads/master
Commit: e9ef60b30bfc92dc00bd2d895f2d38cbf35d8510
Parents: 9af00ab
Author: Andy Seaborne <an...@apache.org>
Authored: Fri Oct 23 17:37:32 2015 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Fri Oct 23 19:47:46 2015 +0100

----------------------------------------------------------------------
 .../jena/fuseki/servlets/SPARQL_Query.java      | 70 ++++++++++++--------
 .../jena/fuseki/servlets/SPARQL_Update.java     | 18 ++++-
 2 files changed, 59 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/e9ef60b3/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 55225c9..33b2b91 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
@@ -71,6 +71,8 @@ public abstract class SPARQL_Query extends SPARQL_Protocol
     }
 
     // Choose REST verbs to support.
+    
+    // doMethod : Not used with UberServlet dispatch.
 
     @Override
     protected void doPost(HttpServletRequest request, HttpServletResponse response) {
@@ -82,40 +84,15 @@ public abstract class SPARQL_Query extends SPARQL_Protocol
         doCommon(request, response) ;
     }
 
-    // HEAD
-
     @Override
     protected void doOptions(HttpServletRequest request, HttpServletResponse response) {
         setCommonHeadersForOptions(response) ;
         response.setHeader(HttpNames.hAllow, "GET,OPTIONS,POST") ;
         response.setHeader(HttpNames.hContentLengh, "0") ;
     }
-
-    @Override
-    protected final void perform(HttpAction action) {
-        // GET
-        if ( action.request.getMethod().equals(HttpNames.METHOD_GET) ) {
-            executeWithParameter(action) ;
-            return ;
-        }
-
-        ContentType ct = FusekiLib.getContentType(action) ;
-
-        // POST application/x-www-form-url
-        // POST ?query= and no Content-Type
-        if ( ct == null || isHtmlForm(ct) ) {
-            // validation checked that if no Content-type, then its a POST with ?query=
-            executeWithParameter(action) ;
-            return ;
-        }
-
-        // POST application/sparql-query
-        if ( matchContentType(ct, ctSPARQLQuery) ) {
-            executeBody(action) ;
-            return ;
-        }
-
-        ServletOps.error(HttpSC.UNSUPPORTED_MEDIA_TYPE_415, "Bad content type: " + ct.getContentType()) ;
+    
+    protected void doOptions(HttpAction action) {
+        doOptions(action.request, action.response) ;
     }
 
     // All the params we support
@@ -131,6 +108,9 @@ public abstract class SPARQL_Query extends SPARQL_Protocol
     @Override
     protected void validate(HttpAction action) {
         String method = action.request.getMethod().toUpperCase(Locale.ROOT) ;
+        
+        if ( HttpNames.METHOD_OPTIONS.equals(method) )
+            return ;
 
         if ( !HttpNames.METHOD_POST.equals(method) && !HttpNames.METHOD_GET.equals(method) )
             ServletOps.errorMethodNotAllowed("Not a GET or POST request") ;
@@ -207,6 +187,40 @@ public abstract class SPARQL_Query extends SPARQL_Protocol
         }
     }
 
+    @Override
+    protected final void perform(HttpAction action) {
+        // OPTIONS
+        if ( action.request.getMethod().equals(HttpNames.METHOD_OPTIONS) ) {
+            // Share with update via SPARQL_Protocol.
+            doOptions(action) ;
+            return ;
+        }
+        
+        // GET
+        if ( action.request.getMethod().equals(HttpNames.METHOD_GET) ) {
+            executeWithParameter(action) ;
+            return ;
+        }
+
+        ContentType ct = FusekiLib.getContentType(action) ;
+    
+        // POST application/x-www-form-url
+        // POST ?query= and no Content-Type
+        if ( ct == null || isHtmlForm(ct) ) {
+            // validation checked that if no Content-type, then its a POST with ?query=
+            executeWithParameter(action) ;
+            return ;
+        }
+    
+        // POST application/sparql-query
+        if ( matchContentType(ct, ctSPARQLQuery) ) {
+            executeBody(action) ;
+            return ;
+        }
+    
+        ServletOps.error(HttpSC.UNSUPPORTED_MEDIA_TYPE_415, "Bad content type: " + ct.getContentType()) ;
+    }
+
     private void executeWithParameter(HttpAction action) {
         String queryString = action.request.getParameter(paramQuery) ;
         execute(queryString, action) ;

http://git-wip-us.apache.org/repos/asf/jena/blob/e9ef60b3/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 297cd17..d01bb31 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
@@ -72,6 +72,8 @@ public class SPARQL_Update extends SPARQL_Protocol
     public SPARQL_Update()
     { super() ; }
 
+    // doMethod : Not used with UberServlet dispatch.
+    
     @Override
     protected void doGet(HttpServletRequest request, HttpServletResponse response) 
             throws ServletException, IOException {
@@ -90,6 +92,10 @@ public class SPARQL_Update extends SPARQL_Protocol
         response.setHeader(HttpNames.hAllow, "OPTIONS,POST") ;
         response.setHeader(HttpNames.hContentLengh, "0") ;
     }
+    
+    protected void doOptions(HttpAction action) {
+        doOptions(action.request, action.response) ;
+    }
 
     @Override
     protected void perform(HttpAction action) {
@@ -115,8 +121,11 @@ public class SPARQL_Update extends SPARQL_Protocol
     @Override
     protected void validate(HttpAction action) {
         HttpServletRequest request = action.request ;
+        
+        if ( HttpNames.METHOD_OPTIONS.equals(request.getMethod()) )
+            return ;
 
-        if ( !HttpNames.METHOD_POST.equalsIgnoreCase(request.getMethod()) )
+        if ( ! HttpNames.METHOD_POST.equalsIgnoreCase(request.getMethod()) )
             ServletOps.errorMethodNotAllowed("SPARQL Update : use POST") ;
 
         ContentType ct = FusekiLib.getContentType(action) ;
@@ -198,6 +207,13 @@ public class SPARQL_Update extends SPARQL_Protocol
     }
     
     private void execute(HttpAction action, InputStream input) {
+        // OPTIONS
+        if ( action.request.getMethod().equals(HttpNames.METHOD_OPTIONS) ) {
+            // Share with update via SPARQL_Protocol.
+            doOptions(action) ;
+            return ;
+        }
+        
         UsingList usingList = processProtocol(action.request) ;
         
         // If the dsg is transactional, then we can parse and execute the update in a streaming fashion.