marmotta-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wik...@apache.org
Subject marmotta git commit: MARMOTTA-651: trying all alternatives in case jax-rs doesn't route to the expected method
Date Tue, 26 Jul 2016 08:35:34 GMT
Repository: marmotta
Updated Branches:
  refs/heads/develop 6f8039f9b -> ffd00144b


MARMOTTA-651: trying all alternatives in case jax-rs doesn't route to the expected method


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

Branch: refs/heads/develop
Commit: ffd00144bde44609ff708fc903020d6eb8fcbc39
Parents: 6f8039f
Author: Sergio Fernández <wikier@apache.org>
Authored: Tue Jul 26 09:58:57 2016 +0200
Committer: Sergio Fernández <wikier@apache.org>
Committed: Tue Jul 26 10:34:54 2016 +0200

----------------------------------------------------------------------
 .../sparql/webservices/SparqlWebService.java    | 25 +++++++++++++-------
 1 file changed, 16 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/marmotta/blob/ffd00144/platform/marmotta-sparql/src/main/java/org/apache/marmotta/platform/sparql/webservices/SparqlWebService.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-sparql/src/main/java/org/apache/marmotta/platform/sparql/webservices/SparqlWebService.java
b/platform/marmotta-sparql/src/main/java/org/apache/marmotta/platform/sparql/webservices/SparqlWebService.java
index 7d5f76b..34f0c4b 100644
--- a/platform/marmotta-sparql/src/main/java/org/apache/marmotta/platform/sparql/webservices/SparqlWebService.java
+++ b/platform/marmotta-sparql/src/main/java/org/apache/marmotta/platform/sparql/webservices/SparqlWebService.java
@@ -20,6 +20,7 @@ package org.apache.marmotta.platform.sparql.webservices;
 import com.google.common.collect.Lists;
 import com.google.common.io.CharStreams;
 import org.apache.commons.collections.EnumerationUtils;
+import org.apache.commons.io.IOUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.marmotta.commons.http.ContentType;
 import org.apache.marmotta.commons.http.MarmottaHttpUtils;
@@ -190,9 +191,17 @@ public class SparqlWebService {
     @POST
     @Consumes({"application/x-www-url-form-urlencoded", "application/x-www-form-urlencoded"})
     @Path(SELECT)
-    public Response selectPostForm(@FormParam("query") String query, @QueryParam("output")
String resultType, @Context HttpServletRequest request) {
-        if(resultType != null && outputMapper.containsKey(resultType)) resultType
= outputMapper.get(resultType);
-        return select(query, resultType, request);
+    public Response selectPostForm(@FormParam("query") String query,
+                                   @QueryParam("output") String resultType,
+                                   @Context HttpServletRequest request) {
+        if (StringUtils.isBlank(query)) {
+            // query might be in the body request... (MARMOTTA-651)
+            // jax-rs doesn't go to selectPost() method
+            return selectPost(resultType, request);
+        } else {
+            if (resultType != null && outputMapper.containsKey(resultType)) resultType
= outputMapper.get(resultType);
+            return select(query, resultType, request);
+        }
     }    
     
     /**
@@ -208,16 +217,14 @@ public class SparqlWebService {
      * @return the query result in the format passed as argument
      */
     @POST
+    @Consumes("*/*")
     @Path(SELECT)
     public Response selectPost(@QueryParam("output") String resultType, @Context HttpServletRequest
request) {
         try {
             if (resultType != null && outputMapper.containsKey(resultType)) resultType
= outputMapper.get(resultType);
-            if (request.getCharacterEncoding() == null) {
-                request.setCharacterEncoding("utf-8");
-            }
-            String query = CharStreams.toString(request.getReader());
-            //String query = IOUtils.toString(request.getInputStream(),"utf-8");
-            log.debug("Query: {}", query);
+            if (request.getCharacterEncoding() == null) { request.setCharacterEncoding("utf-8");
}
+            final String query = CharStreams.toString(request.getReader());
+            log.debug("SPARQL Query: {}", query);
             return select(query, resultType, request);
         } catch (IOException e) {
             log.error("body not found", e);


Mime
View raw message