You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@marmotta.apache.org by wi...@apache.org on 2013/09/26 17:05:49 UTC

[1/5] git commit: MARMOTTA-322: initial workaround for fixing the issue

Updated Branches:
  refs/heads/develop c576351a5 -> 7122c5150


MARMOTTA-322: initial workaround for fixing the issue


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

Branch: refs/heads/develop
Commit: aed338df683de95f7e2873c5a043e417a19bda24
Parents: c576351
Author: Sergio Fernández <wi...@apache.org>
Authored: Thu Sep 26 16:16:17 2013 +0200
Committer: Sergio Fernández <wi...@apache.org>
Committed: Thu Sep 26 16:16:17 2013 +0200

----------------------------------------------------------------------
 .../platform/sparql/api/sparql/QueryType.java   |  34 ++++
 .../sparql/api/sparql/SparqlService.java        |  37 +++-
 .../services/sparql/SparqlServiceImpl.java      | 105 +++++++++-
 .../sparqlio/rdf/SPARQLGraphResultWriter.java   | 111 +++++++++--
 .../sparql/webservices/SparqlWebService.java    | 190 +++++++++++++------
 5 files changed, 389 insertions(+), 88 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/aed338df/platform/marmotta-sparql/src/main/java/org/apache/marmotta/platform/sparql/api/sparql/QueryType.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-sparql/src/main/java/org/apache/marmotta/platform/sparql/api/sparql/QueryType.java b/platform/marmotta-sparql/src/main/java/org/apache/marmotta/platform/sparql/api/sparql/QueryType.java
new file mode 100644
index 0000000..bcd6395
--- /dev/null
+++ b/platform/marmotta-sparql/src/main/java/org/apache/marmotta/platform/sparql/api/sparql/QueryType.java
@@ -0,0 +1,34 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.marmotta.platform.sparql.api.sparql;
+
+/**
+ * SPARQL Query types
+ * 
+ * @author Sergio Fernández
+ *
+ */
+public enum QueryType {
+	
+	TUPLE,
+	
+	GRAPH,
+	
+	BOOL;
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/aed338df/platform/marmotta-sparql/src/main/java/org/apache/marmotta/platform/sparql/api/sparql/SparqlService.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-sparql/src/main/java/org/apache/marmotta/platform/sparql/api/sparql/SparqlService.java b/platform/marmotta-sparql/src/main/java/org/apache/marmotta/platform/sparql/api/sparql/SparqlService.java
index 74e7136..00730cd 100644
--- a/platform/marmotta-sparql/src/main/java/org/apache/marmotta/platform/sparql/api/sparql/SparqlService.java
+++ b/platform/marmotta-sparql/src/main/java/org/apache/marmotta/platform/sparql/api/sparql/SparqlService.java
@@ -32,6 +32,7 @@ import org.openrdf.query.QueryEvaluationException;
 import org.openrdf.query.QueryLanguage;
 import org.openrdf.query.UpdateExecutionException;
 import org.openrdf.query.resultio.BooleanQueryResultWriter;
+import org.openrdf.query.resultio.QueryResultWriter;
 import org.openrdf.query.resultio.TupleQueryResultWriter;
 import org.openrdf.repository.RepositoryException;
 
@@ -52,7 +53,15 @@ public interface SparqlService {
 	 * @throws MalformedQueryException
 	 */
 	Query parseQuery(QueryLanguage language, String query) throws RepositoryException, MalformedQueryException ;
-
+	
+	/**
+	 * Parse and return the concrete query type
+	 * 
+	 * @param language
+	 * @param query
+	 * @return
+	 */
+	QueryType getQueryType(QueryLanguage language, String query) throws MalformedQueryException;
 
 	/**
 	 * Evaluate a SPARQL query on the KiWi TripleStore. Writes the query results 
@@ -101,5 +110,31 @@ public interface SparqlService {
      */
     void update(QueryLanguage queryLanguage, String query) throws InvalidArgumentException, MarmottaException, MalformedQueryException, UpdateExecutionException;
 
+    /**
+     * Evaluate a SPARQL query, writing the results on the required writer.
+     * 
+     * @param queryLanguage
+     * @param query
+     * @param tupleWriter
+     * @param booleanWriter
+     * @param graphWriter
+     * @param timeoutInSeconds
+     * @throws MarmottaException
+     * @throws MalformedQueryException
+     * @throws QueryEvaluationException
+     * @throws TimeoutException
+     */
+    @Deprecated
     void query(QueryLanguage queryLanguage, String query, TupleQueryResultWriter tupleWriter, BooleanQueryResultWriter booleanWriter, SPARQLGraphResultWriter graphWriter, int timeoutInSeconds) throws MarmottaException, MalformedQueryException, QueryEvaluationException, TimeoutException;
+    
+    /**
+     * Evaluate a SPARQL query, writing the results on the writer.
+     * 
+     * @param queryLanguage
+     * @param query
+     * @param writer
+     * @param timeoutInSeconds
+     */
+    void query(QueryLanguage queryLanguage, String query, QueryResultWriter writer, int timeoutInSeconds) throws MarmottaException, MalformedQueryException, QueryEvaluationException, TimeoutException;
+    
 }

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/aed338df/platform/marmotta-sparql/src/main/java/org/apache/marmotta/platform/sparql/services/sparql/SparqlServiceImpl.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-sparql/src/main/java/org/apache/marmotta/platform/sparql/services/sparql/SparqlServiceImpl.java b/platform/marmotta-sparql/src/main/java/org/apache/marmotta/platform/sparql/services/sparql/SparqlServiceImpl.java
index 1384dae..f123cfa 100644
--- a/platform/marmotta-sparql/src/main/java/org/apache/marmotta/platform/sparql/services/sparql/SparqlServiceImpl.java
+++ b/platform/marmotta-sparql/src/main/java/org/apache/marmotta/platform/sparql/services/sparql/SparqlServiceImpl.java
@@ -23,7 +23,14 @@ import java.util.HashMap;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
-import java.util.concurrent.*;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
 
 import javax.annotation.PostConstruct;
 import javax.enterprise.context.ApplicationScoped;
@@ -34,10 +41,12 @@ import org.apache.marmotta.platform.core.api.templating.TemplatingService;
 import org.apache.marmotta.platform.core.api.triplestore.SesameService;
 import org.apache.marmotta.platform.core.exception.InvalidArgumentException;
 import org.apache.marmotta.platform.core.exception.MarmottaException;
+import org.apache.marmotta.platform.sparql.api.sparql.QueryType;
 import org.apache.marmotta.platform.sparql.api.sparql.SparqlService;
 import org.apache.marmotta.platform.sparql.services.sparqlio.rdf.SPARQLGraphResultWriter;
 import org.apache.marmotta.platform.sparql.services.sparqlio.sparqlhtml.SPARQLBooleanHTMLWriter;
 import org.apache.marmotta.platform.sparql.services.sparqlio.sparqlhtml.SPARQLResultsHTMLWriter;
+import org.apache.marmotta.platform.sparql.webservices.SparqlWebService;
 import org.openrdf.model.Value;
 import org.openrdf.query.Binding;
 import org.openrdf.query.BindingSet;
@@ -52,9 +61,16 @@ import org.openrdf.query.TupleQueryResult;
 import org.openrdf.query.TupleQueryResultHandlerException;
 import org.openrdf.query.Update;
 import org.openrdf.query.UpdateExecutionException;
+import org.openrdf.query.parser.ParsedBooleanQuery;
+import org.openrdf.query.parser.ParsedGraphQuery;
+import org.openrdf.query.parser.ParsedQuery;
+import org.openrdf.query.parser.ParsedTupleQuery;
+import org.openrdf.query.parser.QueryParser;
+import org.openrdf.query.parser.QueryParserUtil;
 import org.openrdf.query.resultio.BooleanQueryResultFormat;
 import org.openrdf.query.resultio.BooleanQueryResultWriter;
 import org.openrdf.query.resultio.QueryResultIO;
+import org.openrdf.query.resultio.QueryResultWriter;
 import org.openrdf.query.resultio.TupleQueryResultFormat;
 import org.openrdf.query.resultio.TupleQueryResultWriter;
 import org.openrdf.repository.RepositoryConnection;
@@ -112,13 +128,28 @@ public class SparqlServiceImpl implements SparqlService {
         }
         return sparqlQuery;
     }
+    
+    @Override
+    public QueryType getQueryType(QueryLanguage language, String query) throws MalformedQueryException {
+    	QueryParser parser = QueryParserUtil.createParser(language); 
+    	ParsedQuery parsedQuery = parser.parseQuery(query, configurationService.getServerUri() + SparqlWebService.PATH + "/" + SparqlWebService.SELECT);
+        if (parsedQuery instanceof ParsedTupleQuery) {
+            return QueryType.TUPLE;
+        } else if (parsedQuery instanceof ParsedBooleanQuery) {
+        	return QueryType.BOOL;
+        } else if (parsedQuery instanceof ParsedGraphQuery) {
+        	return QueryType.GRAPH;
+        } else {
+            return null;
+        }
+    }
 
     @Override
+    @Deprecated
     public void query(final QueryLanguage queryLanguage, final String query, final TupleQueryResultWriter tupleWriter, final BooleanQueryResultWriter booleanWriter, final SPARQLGraphResultWriter graphWriter, int timeoutInSeconds) throws MarmottaException, MalformedQueryException, QueryEvaluationException, TimeoutException {
 
         log.debug("executing SPARQL query:\n{}", query);
 
-
         Future<Boolean> future = executorService.submit(new Callable<Boolean>() {
             @Override
             public Boolean call() throws Exception {
@@ -162,11 +193,10 @@ public class SparqlServiceImpl implements SparqlService {
         });
 
         try {
-            Boolean result = future.get(timeoutInSeconds, TimeUnit.SECONDS);
+            future.get(timeoutInSeconds, TimeUnit.SECONDS);
         } catch (InterruptedException | TimeoutException e) {
             log.info("SPARQL query execution aborted due to timeout");
             future.cancel(true);
-
             throw new TimeoutException("SPARQL query execution aborted due to timeout (" + configurationService.getIntConfiguration("sparql.timeout",60)+"s)");
         } catch (ExecutionException e) {
             log.info("SPARQL query execution aborted due to exception");
@@ -179,13 +209,73 @@ public class SparqlServiceImpl implements SparqlService {
             }
         }
     }
-
+    
     @Override
-    public void query(final QueryLanguage language, final String query, final OutputStream output, final String format, int timeoutInSeconds) throws MarmottaException, TimeoutException, MalformedQueryException {
+    public  void query(final QueryLanguage queryLanguage, final String query, final QueryResultWriter writer, final int timeoutInSeconds) throws MarmottaException, MalformedQueryException, QueryEvaluationException, TimeoutException {
         log.debug("executing SPARQL query:\n{}", query);
+        Future<Boolean> future = executorService.submit(new Callable<Boolean>() {
+            @Override
+            public Boolean call() throws Exception {
+                long start = System.currentTimeMillis();
+                try {
+	                RepositoryConnection connection = sesameService.getConnection();
+	                try {
+	                    connection.begin();
+	                    Query sparqlQuery = connection.prepareQuery(queryLanguage, query);
+	
+	                    if (sparqlQuery instanceof TupleQuery) {
+	                        query((TupleQuery) sparqlQuery, (TupleQueryResultWriter)writer);
+	                    } else if (sparqlQuery instanceof BooleanQuery) {
+	                        query((BooleanQuery) sparqlQuery, (BooleanQueryResultWriter)writer);
+	                    } else if (sparqlQuery instanceof GraphQuery) {
+	                        query((GraphQuery) sparqlQuery, (SPARQLGraphResultWriter)writer);
+	                    } else {
+	                        connection.rollback();
+	                        throw new InvalidArgumentException("SPARQL query type " + sparqlQuery.getClass() + " not supported!");
+	                    }
+	
+	                    connection.commit();
+	                } catch (Exception ex) {
+	                    connection.rollback();
+	                    throw ex;
+	                } finally {
+	                    connection.close();
+	                }
+                } catch(RepositoryException e) {
+                    log.error("error while getting repository connection: {}", e);
+                    throw new MarmottaException("error while getting repository connection", e);
+                } catch (QueryEvaluationException e) {
+                    log.error("error while evaluating query: {}", e.getMessage());
+                    throw new MarmottaException("error while writing query result in format ", e);
+                }
 
+                log.debug("SPARQL execution took {}ms", System.currentTimeMillis()-start);
 
+                return Boolean.TRUE;
+            }
+        });
+
+        try {
+            future.get(timeoutInSeconds, TimeUnit.SECONDS);
+        } catch (InterruptedException | TimeoutException e) {
+            log.info("SPARQL query execution aborted due to timeout");
+            future.cancel(true);
+            throw new TimeoutException("SPARQL query execution aborted due to timeout (" + timeoutInSeconds+"s)");
+        } catch (ExecutionException e) {
+            log.info("SPARQL query execution aborted due to exception");
+            if(e.getCause() instanceof MarmottaException) {
+                throw (MarmottaException)e.getCause();
+            } else if(e.getCause() instanceof MalformedQueryException) {
+                throw (MalformedQueryException)e.getCause();
+            } else {
+                throw new MarmottaException("unknown exception while evaluating SPARQL query",e.getCause());
+            }
+        }    	
+    }
 
+	@Override
+    public void query(final QueryLanguage language, final String query, final OutputStream output, final String format, int timeoutInSeconds) throws MarmottaException, TimeoutException, MalformedQueryException {
+        log.debug("executing SPARQL query:\n{}", query);
         Future<Boolean> future = executorService.submit(new Callable<Boolean>() {
             @Override
             public Boolean call() throws Exception {
@@ -230,11 +320,10 @@ public class SparqlServiceImpl implements SparqlService {
         });
 
         try {
-            Boolean result = future.get(timeoutInSeconds, TimeUnit.SECONDS);
+            future.get(timeoutInSeconds, TimeUnit.SECONDS);
         } catch (InterruptedException | TimeoutException e) {
             log.info("SPARQL query execution aborted due to timeout");
             future.cancel(true);
-
             throw new TimeoutException("SPARQL query execution aborted due to timeout (" + configurationService.getIntConfiguration("sparql.timeout",60)+"s)");
         } catch (ExecutionException e) {
             log.info("SPARQL query execution aborted due to exception");

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/aed338df/platform/marmotta-sparql/src/main/java/org/apache/marmotta/platform/sparql/services/sparqlio/rdf/SPARQLGraphResultWriter.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-sparql/src/main/java/org/apache/marmotta/platform/sparql/services/sparqlio/rdf/SPARQLGraphResultWriter.java b/platform/marmotta-sparql/src/main/java/org/apache/marmotta/platform/sparql/services/sparqlio/rdf/SPARQLGraphResultWriter.java
index 2e7a189..b4148f0 100644
--- a/platform/marmotta-sparql/src/main/java/org/apache/marmotta/platform/sparql/services/sparqlio/rdf/SPARQLGraphResultWriter.java
+++ b/platform/marmotta-sparql/src/main/java/org/apache/marmotta/platform/sparql/services/sparqlio/rdf/SPARQLGraphResultWriter.java
@@ -19,31 +19,38 @@ package org.apache.marmotta.platform.sparql.services.sparqlio.rdf;
 
 import java.io.IOException;
 import java.io.OutputStream;
-import java.util.Map;
+import java.nio.charset.Charset;
+import java.util.Collection;
+import java.util.List;
 
+import org.openrdf.query.BindingSet;
 import org.openrdf.query.GraphQueryResult;
 import org.openrdf.query.QueryEvaluationException;
+import org.openrdf.query.QueryResultHandlerException;
+import org.openrdf.query.TupleQueryResultHandlerException;
+import org.openrdf.query.resultio.QueryResultFormat;
 import org.openrdf.query.resultio.QueryResultIO;
-import org.openrdf.repository.Repository;
-import org.openrdf.repository.RepositoryConnection;
-import org.openrdf.repository.RepositoryException;
-import org.openrdf.repository.sail.SailRepository;
+import org.openrdf.query.resultio.QueryResultWriter;
 import org.openrdf.rio.RDFFormat;
 import org.openrdf.rio.RDFHandlerException;
-import org.openrdf.rio.RDFWriter;
-import org.openrdf.rio.Rio;
-import org.openrdf.sail.memory.MemoryStore;
+import org.openrdf.rio.RioSetting;
+import org.openrdf.rio.WriterConfig;
+
+import edu.emory.mathcs.backport.java.util.Collections;
 
 /**
- * SPARQL grapg result writer for Sesam RIO
+ * SPARQL graph result writer for Sesame RIO
  * 
- * Author: Sebastian Schaffert
+ * @author Sebastian Schaffert
+ * @author Sergio Fernández
  */
-public class SPARQLGraphResultWriter {
+public class SPARQLGraphResultWriter implements QueryResultWriter {
 
     private OutputStream outputStream;
 
     private RDFFormat format;
+    
+    private WriterConfig config;
 
     public SPARQLGraphResultWriter(OutputStream outputStream) {
         this.outputStream = outputStream;
@@ -55,21 +62,93 @@ public class SPARQLGraphResultWriter {
         this.format = RDFFormat.forMIMEType(mimeType, RDFFormat.RDFXML);
     }
 
+    @Deprecated
     public void write(GraphQueryResult result) throws IOException {
-
         try {
-            QueryResultIO.write(result,format,outputStream);
-
+            QueryResultIO.write(result, format, outputStream);
             outputStream.flush();
             outputStream.close();
-
         } catch (QueryEvaluationException e) {
             throw new IOException("query result writing failed because query evaluation had a problem", e);
         } catch (RDFHandlerException e) {
             throw new IOException("query result writing failed because writer could not handle rdf data", e);
         }
+    }
 
+	@Override
+	public void endQueryResult() throws TupleQueryResultHandlerException {
+		// TODO Auto-generated method stub
+		
+	}
 
-    }
+	@Override
+	public void handleBoolean(boolean arg0) throws QueryResultHandlerException {
+		// TODO Auto-generated method stub
+		
+	}
+
+	@Override
+	public void handleLinks(List<String> arg0) throws QueryResultHandlerException {
+		// TODO Auto-generated method stub
+		
+	}
+
+	@Override
+	public void handleSolution(BindingSet arg0) throws TupleQueryResultHandlerException {
+		// TODO Auto-generated method stub
+		
+	}
+
+	@Override
+	public void startQueryResult(List<String> arg0) throws TupleQueryResultHandlerException {
+		// TODO Auto-generated method stub
+		
+	}
+
+	@Override
+	public QueryResultFormat getQueryResultFormat() {
+		return new QueryResultFormat("QueryResultFormat", format.getDefaultMIMEType(), Charset.defaultCharset(), format.getDefaultFileExtension());
+	}
+
+	@Override
+	public void handleNamespace(String prefix, String uri) throws QueryResultHandlerException {
+		
+	}
+
+	@Override
+	public void startDocument() throws QueryResultHandlerException {
+		
+	}
+
+	@Override
+	public void handleStylesheet(String stylesheetUrl) throws QueryResultHandlerException {
+		
+	}
+
+	@Override
+	public void startHeader() throws QueryResultHandlerException {
+		
+	}
+
+	@Override
+	public void endHeader() throws QueryResultHandlerException {
+		
+	}
+
+	@Override
+	public void setWriterConfig(WriterConfig config) {
+		this.config = config;
+	}
+
+	@Override
+	public WriterConfig getWriterConfig() {
+		return config;
+	}
+
+	@Override
+	@SuppressWarnings("unchecked")
+	public Collection<RioSetting<?>> getSupportedSettings() {
+		return Collections.emptyList();
+	}
     
 }

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/aed338df/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 a611cf9..bba20b4 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
@@ -17,21 +17,51 @@
  */
 package org.apache.marmotta.platform.sparql.webservices;
 
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.UnsupportedEncodingException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URLDecoder;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.TimeoutException;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.FormParam;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.StreamingOutput;
+import javax.ws.rs.core.UriBuilder;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.marmotta.commons.http.ContentType;
+import org.apache.marmotta.commons.http.LMFHttpUtils;
+import org.apache.marmotta.platform.core.api.config.ConfigurationService;
+import org.apache.marmotta.platform.core.api.exporter.ExportService;
 import org.apache.marmotta.platform.core.api.templating.TemplatingService;
+import org.apache.marmotta.platform.core.exception.InvalidArgumentException;
 import org.apache.marmotta.platform.core.exception.MarmottaException;
+import org.apache.marmotta.platform.core.util.WebServiceUtil;
+import org.apache.marmotta.platform.sparql.api.sparql.QueryType;
 import org.apache.marmotta.platform.sparql.api.sparql.SparqlService;
 import org.apache.marmotta.platform.sparql.services.sparql.SparqlWritersHelper;
 import org.apache.marmotta.platform.sparql.services.sparqlio.rdf.SPARQLGraphResultWriter;
 import org.apache.marmotta.platform.sparql.services.sparqlio.sparqlhtml.SPARQLBooleanHTMLWriter;
 import org.apache.marmotta.platform.sparql.services.sparqlio.sparqlhtml.SPARQLResultsHTMLWriter;
-import com.google.common.collect.Lists;
-import com.google.common.io.CharStreams;
-import org.apache.marmotta.platform.core.api.config.ConfigurationService;
-import org.apache.marmotta.platform.core.exception.InvalidArgumentException;
-import org.apache.marmotta.platform.core.util.WebServiceUtil;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.marmotta.commons.http.ContentType;
-import org.apache.marmotta.commons.http.LMFHttpUtils;
 import org.openrdf.query.MalformedQueryException;
 import org.openrdf.query.QueryEvaluationException;
 import org.openrdf.query.QueryLanguage;
@@ -39,31 +69,13 @@ import org.openrdf.query.UpdateExecutionException;
 import org.openrdf.query.resultio.BooleanQueryResultFormat;
 import org.openrdf.query.resultio.BooleanQueryResultWriter;
 import org.openrdf.query.resultio.QueryResultIO;
+import org.openrdf.query.resultio.QueryResultWriter;
 import org.openrdf.query.resultio.TupleQueryResultFormat;
 import org.openrdf.query.resultio.TupleQueryResultWriter;
 import org.slf4j.Logger;
 
-import javax.enterprise.context.ApplicationScoped;
-import javax.inject.Inject;
-import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.*;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.StreamingOutput;
-import javax.ws.rs.core.UriBuilder;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.UnsupportedEncodingException;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.net.URLDecoder;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.TimeoutException;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
+import com.google.common.collect.Lists;
+import com.google.common.io.CharStreams;
 
 /**
  * Execute SPARQL query (both query and update) on the LMF triple store
@@ -78,7 +90,7 @@ import java.util.regex.Pattern;
 @Path("/" + SparqlWebService.PATH)
 public class SparqlWebService {
 	
-    public final static String PATH = "sparql";
+    public static final String PATH = "sparql";
     public static final String SELECT = "/select";
     public static final String UPDATE = "/update";
     public static final String SNORQL = "/snorql";
@@ -91,6 +103,9 @@ public class SparqlWebService {
 
     @Inject
     private ConfigurationService configurationService;
+    
+    @Inject
+    private ExportService exportService;
 
     @Inject
     private TemplatingService templatingService;
@@ -149,35 +164,53 @@ public class SparqlWebService {
      */
     @GET
     @Path(SELECT)
-    public Response selectGet(@QueryParam("query") String query, @QueryParam("output") String resultType, @Context HttpServletRequest request) {
-        if(resultType == null) {
-            List<ContentType> acceptedTypes = LMFHttpUtils.parseAcceptHeader(request.getHeader("Accept"));
-            List<ContentType> offeredTypes  = LMFHttpUtils.parseStringList(Lists.newArrayList("application/sparql-results+xml","application/sparql-results+json","text/html", "application/rdf+xml", "text/csv"));
-
-            ContentType bestType = LMFHttpUtils.bestContentType(offeredTypes,acceptedTypes);
-
-            if(bestType != null) {
-                resultType = bestType.getMime();
-            }
-        }
-
-        try {
-            if(resultType != null) {
-                if (StringUtils.isNotBlank(query))
-                    return buildQueryResponse(resultType, query);
-                else {
-                    if (parseSubType(resultType).equals("html"))
-                        return Response.seeOther(new URI(configurationService.getServerUri() + "sparql/admin/snorql.html")).build();
-                    else
-                        return Response.status(Response.Status.BAD_REQUEST).entity("no SPARQL query specified").build();
-                }
-            } else
-                return Response.status(Response.Status.BAD_REQUEST).entity("no result format specified or unsupported result format").build();
-        } catch (InvalidArgumentException ex) {
-            return Response.status(Response.Status.BAD_REQUEST).entity(ex.getMessage()).build();
+    public Response selectGet(@QueryParam("query") String query, @QueryParam("output") String resultType, @Context HttpServletRequest request) {  
+    	try {
+	    	String acceptHeader = StringUtils.defaultString(request.getHeader("Accept"), "");
+	    	if (StringUtils.isBlank(query)) { //empty query
+	            if (acceptHeader.contains("html")) {
+	                return Response.seeOther(new URI(configurationService.getServerUri() + "sparql/admin/snorql.html")).build();
+	            } else {
+	            	return Response.status(Response.Status.BAD_REQUEST).entity("no SPARQL query specified").build();
+	            }
+	    	} else {
+	    		//query duck typing
+	        	QueryType queryType = sparqlService.getQueryType(QueryLanguage.SPARQL, query);
+	        	List<ContentType> acceptedTypes;
+	        	List<ContentType> offeredTypes;
+	        	if (resultType != null) {
+	        		acceptedTypes = LMFHttpUtils.parseAcceptHeader(resultType);
+	        	} else {
+	        		acceptedTypes = LMFHttpUtils.parseAcceptHeader(acceptHeader);
+	        	}
+	        	if (QueryType.TUPLE.equals(queryType)) {
+	        		offeredTypes  = LMFHttpUtils.parseStringList(Lists.newArrayList("application/sparql-results+xml","application/sparql-results+json", "text/html", "application/rdf+xml", "text/csv"));
+	        	} else if (QueryType.BOOL.equals(queryType)) {
+	        		offeredTypes  = LMFHttpUtils.parseStringList(Lists.newArrayList("application/sparql-results+xml","application/sparql-results+json", "text/html", "application/rdf+xml", "text/csv"));
+	        	} else if (QueryType.GRAPH.equals(queryType)) {
+	        		Set<String> producedTypes = new HashSet<String>(exportService.getProducedTypes());
+	        		producedTypes.remove("application/xml");
+	        		producedTypes.remove("application/xml");
+	        		producedTypes.remove("text/plain");
+	        		producedTypes.remove("text/html");
+	        		producedTypes.remove("application/xhtml+xml");
+	        		offeredTypes  = LMFHttpUtils.parseStringList(producedTypes);
+	        	} else {
+	        		return Response.status(Response.Status.BAD_REQUEST).entity("no result format specified or unsupported result format").build();
+	        	}
+	            ContentType bestType = LMFHttpUtils.bestContentType(offeredTypes, acceptedTypes);
+	            if (bestType == null) {
+	            	return Response.status(Response.Status.BAD_REQUEST).entity("no result format specified or unsupported result format").build();
+	            } else {
+	        		//return buildQueryResponse(resultType, query);
+	            	return buildQueryResponse(bestType, query, queryType);
+	            }
+	    	}
+        } catch (InvalidArgumentException e) {
+            log.error("query parsing threw an exception", e);
+            return Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build();
         } catch(Exception e) {
-            log.error("query execution threw an exception",e);
-
+            log.error("query execution threw an exception", e);
             return Response.serverError().entity("query not supported").build();
         }
     }
@@ -224,9 +257,9 @@ public class SparqlWebService {
         try {
             if(resultType == null) {
                 List<ContentType> acceptedTypes = LMFHttpUtils.parseAcceptHeader(request.getHeader("Accept"));
-                List<ContentType> offeredTypes  = LMFHttpUtils.parseStringList(Lists.newArrayList("application/sparql-results+xml","application/sparql-results+json","text/html", "application/rdf+xml", "text/csv"));
+                List<ContentType> offeredTypes  = LMFHttpUtils.parseStringList(Lists.newArrayList("application/sparql-results+xml","application/sparql-results+json", "text/html", "application/rdf+xml", "text/csv"));
 
-                ContentType bestType = LMFHttpUtils.bestContentType(offeredTypes,acceptedTypes);
+                ContentType bestType = LMFHttpUtils.bestContentType(offeredTypes, acceptedTypes);
 
                 if(bestType != null) {
                     resultType = bestType.getMime();
@@ -311,7 +344,6 @@ public class SparqlWebService {
             return buildQueryResponse(resultType, query);
         } catch(Exception e) {
             log.error("query execution threw an exception",e);
-
             return Response.serverError().entity("query not supported").build();
         }
     }
@@ -479,7 +511,39 @@ public class SparqlWebService {
         }
 		return params;
 	}
+    
+	private Response buildQueryResponse(final ContentType format, final String query, final QueryType queryType) throws Exception {		
+        StreamingOutput entity = new StreamingOutput() {
+            @Override
+            public void write(OutputStream output) throws IOException, WebApplicationException {
+        		QueryResultWriter writer = null;
+            	if (QueryType.TUPLE.equals(queryType)) {
+            		writer = getTupleResultWriter(format.getMime(), output);
+            	} else if (QueryType.BOOL.equals(queryType)) {
+            		writer = getBooleanResultWriter(format.getMime(), output);
+            	} else if (QueryType.GRAPH.equals(queryType)) {
+            		writer = getGraphResultWriter(format.getMime(), output);
+            	} else {
+            		throw new RuntimeException("Unknown result writer for query type '" + queryType + "'");
+            	}
+            	
+                try {
+                	sparqlService.query(QueryLanguage.SPARQL, query, writer, configurationService.getIntConfiguration("sparql.timeout", 60));
+                } catch (MarmottaException ex) {
+                    throw new WebApplicationException(ex.getCause(), Response.status(Response.Status.BAD_REQUEST).entity(WebServiceUtil.jsonErrorResponse(ex)).build());
+                } catch (QueryEvaluationException e) {
+                    throw new WebApplicationException(e.getCause(), Response.status(Response.Status.BAD_REQUEST).entity(WebServiceUtil.jsonErrorResponse(e)).build());
+                } catch (MalformedQueryException e) {
+                    throw new WebApplicationException(e.getCause(), Response.status(Response.Status.BAD_REQUEST).entity(WebServiceUtil.jsonErrorResponse(e)).build());
+                } catch (TimeoutException e) {
+                    throw new WebApplicationException(e.getCause(), Response.status(Response.Status.GATEWAY_TIMEOUT).entity(WebServiceUtil.jsonErrorResponse(e)).build());
+                }
+            }
+        };
+        return Response.ok().entity(entity).header("Content-Type", format.getMime()).build();
+	}
 
+    @Deprecated
 	private Response buildQueryResponse(final String resultType, final String query) throws Exception {
         StreamingOutput entity = new StreamingOutput() {
             @Override
@@ -500,7 +564,7 @@ public class SparqlWebService {
 
         //set returntype
         String s = "";
-        if(resultType ==null) {
+        if(resultType == null) {
             s = "application/sparql-results+xml;charset=utf-8";
         } else if(parseSubType(resultType).equals("html") ) {
             s = "text/html;charset=utf-8";
@@ -567,7 +631,7 @@ public class SparqlWebService {
     }
 
     protected SPARQLGraphResultWriter getGraphResultWriter(String format, OutputStream os) {
-        return new SPARQLGraphResultWriter(os,format);
+        return new SPARQLGraphResultWriter(os, format);
     }
 
 }


[4/5] git commit: MARMOTTA-322: recovered integration tests for the sparql endpoint

Posted by wi...@apache.org.
MARMOTTA-322: recovered integration tests for the sparql endpoint


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

Branch: refs/heads/develop
Commit: 5f0045d1c39a1240256bff8e05ca8929c2240d9a
Parents: d1a4ab6
Author: Sergio Fernández <wi...@apache.org>
Authored: Thu Sep 26 16:47:13 2013 +0200
Committer: Sergio Fernández <wi...@apache.org>
Committed: Thu Sep 26 16:47:13 2013 +0200

----------------------------------------------------------------------
 .../marmotta/platform/sparql/webservices/SparqlWebService.java | 3 +--
 .../platform/sparql/webservices/SparqlWebServiceTest.java      | 6 +++---
 2 files changed, 4 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/5f0045d1/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 614868b..48e6e4c 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
@@ -219,8 +219,7 @@ public class SparqlWebService {
      * @param request
      * @return
      */
-	private Response select(String query, String resultType,
-			HttpServletRequest request) {
+	private Response select(String query, String resultType, HttpServletRequest request) {
 		try {
 	    	String acceptHeader = StringUtils.defaultString(request.getHeader("Accept"), "");
 	    	if (StringUtils.isBlank(query)) { //empty query

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/5f0045d1/platform/marmotta-sparql/src/test/java/org/apache/marmotta/platform/sparql/webservices/SparqlWebServiceTest.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-sparql/src/test/java/org/apache/marmotta/platform/sparql/webservices/SparqlWebServiceTest.java b/platform/marmotta-sparql/src/test/java/org/apache/marmotta/platform/sparql/webservices/SparqlWebServiceTest.java
index 4f4d3f5..8d0486c 100644
--- a/platform/marmotta-sparql/src/test/java/org/apache/marmotta/platform/sparql/webservices/SparqlWebServiceTest.java
+++ b/platform/marmotta-sparql/src/test/java/org/apache/marmotta/platform/sparql/webservices/SparqlWebServiceTest.java
@@ -104,12 +104,12 @@ public class SparqlWebServiceTest {
     		get("/sparql/select");
     }
     
-    /*
     @Test
     public void testConstruct() throws IOException, InterruptedException {
         expect().
     	log().ifError().
     		statusCode(200).
+    		contentType("application/rdf+xml").
     	given().
     		param("query", "CONSTRUCT { <http://www.wikier.org/foaf#wikier> ?p ?o } WHERE { <http://www.wikier.org/foaf#wikier> ?p ?o }").
 		when().
@@ -137,7 +137,7 @@ public class SparqlWebServiceTest {
     		contentType("text/turtle").
     	given().
     		header("Accept", "plain/text").
-    		param("query", "CONSTRUCT { <http://www.wikier.org/foaf#wikier> ?p ?o } WHERE { <http://www.wikier.org/foaf#wikier> ?p ?o }").
+    		param("query", "CONSTRUCT { <http://www.wikier.org/foaf#wikier2> ?p ?o } WHERE { <http://www.wikier.org/foaf#wikier> ?p ?o }").
 		when().
     		get("/sparql/select");
     }
@@ -147,6 +147,7 @@ public class SparqlWebServiceTest {
         expect().
     	log().ifError().
     		statusCode(200).
+    		contentType("application/rdf+xml").
     	given().
     		param("query", "DESCRIBE <http://www.wikier.org/foaf#wikier>").
 		when().
@@ -178,6 +179,5 @@ public class SparqlWebServiceTest {
 		when().
     		get("/sparql/select");
     }
-    */
 
 }


[2/5] git commit: MARMOTTA-322: unified all select implementations in the web service

Posted by wi...@apache.org.
MARMOTTA-322: unified all select implementations in the web service


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

Branch: refs/heads/develop
Commit: b3bb9d71115132c253889c08e16fa8bfa817b4f5
Parents: aed338d
Author: Sergio Fernández <wi...@apache.org>
Authored: Thu Sep 26 16:24:39 2013 +0200
Committer: Sergio Fernández <wi...@apache.org>
Committed: Thu Sep 26 16:24:39 2013 +0200

----------------------------------------------------------------------
 .../sparql/webservices/SparqlWebService.java    | 147 ++++++++-----------
 1 file changed, 58 insertions(+), 89 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/b3bb9d71/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 bba20b4..06d281a 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
@@ -165,7 +165,63 @@ public class SparqlWebService {
     @GET
     @Path(SELECT)
     public Response selectGet(@QueryParam("query") String query, @QueryParam("output") String resultType, @Context HttpServletRequest request) {  
-    	try {
+    	return select(query, resultType, request);
+    }
+    
+    /**
+     * Execute a SPARQL 1.1 tuple query on the LMF triple store using the query passed as form parameter to the
+     * POST request. Result will be formatted using the result type passed as argument (either "html", "json" or "xml").
+     * <p/>
+     * see SPARQL 1.1 Query syntax at http://www.w3.org/TR/sparql11-query/
+     *
+     * @param query       the SPARQL 1.1 Query as a string parameter
+     * @param resultType  the format for serializing the query results ("html", "json", or "xml")
+     * @HTTP 200 in case the query was executed successfully
+     * @HTTP 500 in case there was an error during the query evaluation
+     * @return the query result in the format passed as argument
+     */
+    @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) {
+    	return select(query, resultType, request);
+    }    
+    
+    /**
+     * Execute a SPARQL 1.1 tuple query on the LMF triple store using the query passed in the body of the
+     * POST request. Result will be formatted using the result type passed as argument (either "html", "json" or "xml").
+     * <p/>
+     * see SPARQL 1.1 Query syntax at http://www.w3.org/TR/sparql11-query/
+     *
+     * @param request     the servlet request (to retrieve the SPARQL 1.1 Query passed in the body of the POST request)
+     * @param resultType  the format for serializing the query results ("html", "json", or "xml")
+     * @HTTP 200 in case the query was executed successfully
+     * @HTTP 500 in case there was an error during the query evaluation
+     * @return the query result in the format passed as argument
+     */
+    @POST
+    @Path(SELECT)
+    public Response selectPost(@QueryParam("output") String resultType, @Context HttpServletRequest request) {
+		try {
+			String query = CharStreams.toString(request.getReader());
+			return select(query, resultType, request);
+		} catch (IOException e) {
+			log.error("body not found", e);
+			return Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build();
+		}
+    }    
+
+    /**
+     * Actual SELECT implementation
+     * 
+     * @param query
+     * @param resultType
+     * @param request
+     * @return
+     */
+	private Response select(String query, String resultType,
+			HttpServletRequest request) {
+		try {
 	    	String acceptHeader = StringUtils.defaultString(request.getHeader("Accept"), "");
 	    	if (StringUtils.isBlank(query)) { //empty query
 	            if (acceptHeader.contains("html")) {
@@ -213,7 +269,7 @@ public class SparqlWebService {
             log.error("query execution threw an exception", e);
             return Response.serverError().entity("query not supported").build();
         }
-    }
+	}
 
     /**
      * For CORS operations TODO: make it more fine grained (maybe user dependent)
@@ -237,93 +293,6 @@ public class SparqlWebService {
 
     }
     */
-    
-    /**
-     * Execute a SPARQL 1.1 tuple query on the LMF triple store using the query passed as form parameter to the
-     * POST request. Result will be formatted using the result type passed as argument (either "html", "json" or "xml").
-     * <p/>
-     * see SPARQL 1.1 Query syntax at http://www.w3.org/TR/sparql11-query/
-     *
-     * @param query       the SPARQL 1.1 Query as a string parameter
-     * @param resultType  the format for serializing the query results ("html", "json", or "xml")
-     * @HTTP 200 in case the query was executed successfully
-     * @HTTP 500 in case there was an error during the query evaluation
-     * @return the query result in the format passed as argument
-     */
-    @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) {
-        try {
-            if(resultType == null) {
-                List<ContentType> acceptedTypes = LMFHttpUtils.parseAcceptHeader(request.getHeader("Accept"));
-                List<ContentType> offeredTypes  = LMFHttpUtils.parseStringList(Lists.newArrayList("application/sparql-results+xml","application/sparql-results+json", "text/html", "application/rdf+xml", "text/csv"));
-
-                ContentType bestType = LMFHttpUtils.bestContentType(offeredTypes, acceptedTypes);
-
-                if(bestType != null) {
-                    resultType = bestType.getMime();
-                }
-            }
-            if(resultType != null) {
-                if (StringUtils.isNotBlank(query))
-                    return buildQueryResponse(resultType, query);
-                else
-                    return Response.status(Response.Status.BAD_REQUEST).entity("no SPARQL query specified").build();
-            } else
-                return Response.status(Response.Status.BAD_REQUEST).entity("no result format specified or unsupported result format").build();
-        } catch (InvalidArgumentException ex) {
-            return Response.status(Response.Status.BAD_REQUEST).entity(ex.getMessage()).build();
-        } catch(Exception e) {
-            log.error("query execution threw an exception",e);
-
-            return Response.serverError().entity("query not supported").build();
-        }
-    }
-
-    /**
-     * Execute a SPARQL 1.1 tuple query on the LMF triple store using the query passed in the body of the
-     * POST request. Result will be formatted using the result type passed as argument (either "html", "json" or "xml").
-     * <p/>
-     * see SPARQL 1.1 Query syntax at http://www.w3.org/TR/sparql11-query/
-     *
-     * @param request     the servlet request (to retrieve the SPARQL 1.1 Query passed in the body of the POST request)
-     * @param resultType  the format for serializing the query results ("html", "json", or "xml")
-     * @HTTP 200 in case the query was executed successfully
-     * @HTTP 500 in case there was an error during the query evaluation
-     * @return the query result in the format passed as argument
-     */
-    @POST
-    @Path(SELECT)
-    public Response selectPost(@QueryParam("output") String resultType, @Context HttpServletRequest request) {
-        try {
-            if(resultType == null) {
-                List<ContentType> acceptedTypes = LMFHttpUtils.parseAcceptHeader(request.getHeader("Accept"));
-                List<ContentType> offeredTypes  = LMFHttpUtils.parseStringList(Lists.newArrayList("application/sparql-results+xml","application/sparql-results+json","text/html", "application/rdf+xml", "text/csv"));
-
-                ContentType bestType = LMFHttpUtils.bestContentType(offeredTypes,acceptedTypes);
-
-                if(bestType != null) {
-                    resultType = bestType.getMime();
-                }
-            }
-
-            if(resultType != null) {
-                String query = CharStreams.toString(request.getReader());
-                if (query != null && !query.equals(""))
-                    return buildQueryResponse(resultType, query);
-                else
-                    return Response.status(Response.Status.BAD_REQUEST).entity("no SPARQL query specified").build();
-            } else
-                return Response.status(Response.Status.BAD_REQUEST).entity("no result format specified or unsupported result format").build();
-        } catch (InvalidArgumentException ex) {
-            return Response.status(Response.Status.BAD_REQUEST).entity(ex.getMessage()).build();
-        } catch(Exception e) {
-            log.error("query execution threw an exception",e);
-
-            return Response.serverError().entity("query not supported").build();
-        }
-    }
 
     /**
      * Execute a SPARQL 1.1 tuple query on the LMF triple store using the query passed as form parameter to the


[5/5] git commit: MARMOTTA-322: ttd for fixzing some details in the sparql endpoint

Posted by wi...@apache.org.
MARMOTTA-322: ttd for fixzing some details in the sparql endpoint


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

Branch: refs/heads/develop
Commit: 7122c51502d9358c49806e3ee516ea22cc2679c5
Parents: 5f0045d
Author: Sergio Fernández <wi...@apache.org>
Authored: Thu Sep 26 17:05:38 2013 +0200
Committer: Sergio Fernández <wi...@apache.org>
Committed: Thu Sep 26 17:05:38 2013 +0200

----------------------------------------------------------------------
 .../marmotta/commons/http/LMFHttpUtils.java     | 148 -------------------
 .../commons/http/MarmottaHttpUtils.java         | 145 ++++++++++++++++++
 .../commons/http/ContentTypeMatchingTest.java   |   8 +-
 .../commons/http/MarmottaHttpUtilsTest.java     |  40 +++++
 .../ldclient/api/endpoint/Endpoint.java         |   2 +-
 .../services/provider/AbstractHttpProvider.java |   2 +-
 .../core/webservices/io/ExportWebService.java   |  10 +-
 .../resource/ResourceWebService.java            |  16 +-
 .../triplestore/ContextWebService.java          |  10 +-
 .../endpoint/LinkedDataEndpointServiceImpl.java |   4 +-
 .../sparql/webservices/SparqlWebService.java    |  22 +--
 .../webservices/SparqlWebServiceTest.java       |  17 ++-
 .../services/VersionSerializerServiceImpl.java  |   4 +-
 .../webservices/MementoWebService.java          |  10 +-
 14 files changed, 243 insertions(+), 195 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/7122c515/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/http/LMFHttpUtils.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/http/LMFHttpUtils.java b/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/http/LMFHttpUtils.java
deleted file mode 100644
index 503cd87..0000000
--- a/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/http/LMFHttpUtils.java
+++ /dev/null
@@ -1,148 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.marmotta.commons.http;
-
-import java.nio.charset.Charset;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-
-/**
- * Add file description here!
- * <p/>
- * Author: Sebastian Schaffert
- */
-public class LMFHttpUtils {
-
-
-
-
-
-    /**
-     * A utility method for parsing HTTP Content-Type and Accept header, taking into account different parameters that
-     * are typically passed. Recognized parameters:
-     * - charset: gives the charset of the content
-     * - q: gives the precedence of the content
-     * The result is an ordered list of content types in order of the computed preference in the header value passed as
-     * string argument.
-     * <p/>
-     * Author: Sebastian Schaffert
-     *
-     *
-     */
-    public static List<ContentType> parseAcceptHeader(String header) {
-        String[] components = header.split(",");
-        List<ContentType> contentTypes = new ArrayList<ContentType>(components.length);
-        for(String c : components) {
-            String mt[] = c.split(";");
-
-            String[] tst = mt[0].split("/");
-
-            if(tst.length == 2) {
-                ContentType type = parseContentType(c);
-                if(type != null) {
-                    contentTypes.add(type);
-                }
-            }
-        }
-
-        Collections.sort(contentTypes);
-
-        return contentTypes;
-    }
-
-
-    public static List<ContentType> parseStringList(Collection<String> types) {
-        List<ContentType> contentTypes = new ArrayList<ContentType>(types.size());
-        for(String c : types) {
-            ContentType type = parseContentType(c);
-            if(type != null) {
-                contentTypes.add(type);
-            }
-        }
-        return contentTypes;
-    }
-
-
-    public static ContentType parseContentType(String c) {
-        String mt[] = c.split(";");
-
-        String[] tst = mt[0].split("/");
-
-        if(tst.length == 2) {
-            ContentType type = new ContentType(tst[0],tst[1]);
-
-            // add parameters
-            for(int i=1; i<mt.length; i++) {
-                String[] kv = mt[i].split("=");
-                if(kv.length == 2) {
-                    type.setParameter(kv[0].trim(),kv[1].trim());
-
-                    if("charset".equalsIgnoreCase(kv[0].trim())) {
-                        type.setCharset(Charset.forName(kv[1].trim()));
-                    }
-                }
-            }
-
-            return type;
-        } else {
-            return null;
-        }
-    }
-
-    /**
-     * Determine the best content type out of the selection of content types we offer and the ordered list of content
-     * types requested by the peer.
-     *
-     * TODO: implement remove variant selection algorithm (RFC 2296, http://tools.ietf.org/html/rfc2296)
-     *
-     * @param offeredTypes list of offered types in order of precedence
-     * @param requestedTypes list of requested types in order of precedence - may contain wildcards
-     * @return
-     */
-    public static ContentType bestContentType(List<ContentType> offeredTypes, List<ContentType> requestedTypes) {
-        // check for directly matching types
-        for(ContentType requested : requestedTypes) {
-            for(ContentType offered : offeredTypes) {
-                if(requested.matches(offered)) {
-                    return offered;
-                }
-            }
-        }
-        // check for qualified subtypes also
-        for(ContentType requested : requestedTypes) {
-            for(ContentType offered : offeredTypes) {
-                if(requested.matchesSubtype(offered)) {
-                    return offered;
-                }
-            }
-        }
-
-        // check for wildcard matching types
-        for(ContentType requested : requestedTypes) {
-            for(ContentType offered : offeredTypes) {
-                if(requested.matchesWildcard(offered)) {
-                    return offered;
-                }
-            }
-        }
-        return null;
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/7122c515/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/http/MarmottaHttpUtils.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/http/MarmottaHttpUtils.java b/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/http/MarmottaHttpUtils.java
new file mode 100644
index 0000000..3fedb6c
--- /dev/null
+++ b/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/http/MarmottaHttpUtils.java
@@ -0,0 +1,145 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.marmotta.commons.http;
+
+import java.nio.charset.Charset;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * Add file description here!
+ * <p/>
+ * Author: Sebastian Schaffert
+ */
+public class MarmottaHttpUtils {
+
+    /**
+     * A utility method for parsing HTTP Content-Type and Accept header, taking into account different parameters that
+     * are typically passed. Recognized parameters:
+     * - charset: gives the charset of the content
+     * - q: gives the precedence of the content
+     * The result is an ordered list of content types in order of the computed preference in the header value passed as
+     * string argument.
+     * <p/>
+     * Author: Sebastian Schaffert
+     *
+     *
+     */
+    public static List<ContentType> parseAcceptHeader(String header) {
+        String[] components = header.split(",");
+        List<ContentType> contentTypes = new ArrayList<ContentType>(components.length);
+        for(String c : components) {
+            String mt[] = c.split(";");
+
+            String[] tst = mt[0].split("/");
+
+            if(tst.length == 2) {
+                ContentType type = parseContentType(c);
+                if(type != null) {
+                    contentTypes.add(type);
+                }
+            }
+        }
+
+        Collections.sort(contentTypes);
+
+        return contentTypes;
+    }
+
+
+    public static List<ContentType> parseStringList(Collection<String> types) {
+        List<ContentType> contentTypes = new ArrayList<ContentType>(types.size());
+        for(String c : types) {
+            ContentType type = parseContentType(c);
+            if(type != null) {
+                contentTypes.add(type);
+            }
+        }
+        return contentTypes;
+    }
+
+
+    public static ContentType parseContentType(String c) {
+        String mt[] = c.split(";");
+
+        String[] tst = mt[0].split("/");
+
+        if(tst.length == 2) {
+            ContentType type = new ContentType(tst[0],tst[1]);
+
+            // add parameters
+            for(int i=1; i<mt.length; i++) {
+                String[] kv = mt[i].split("=");
+                if(kv.length == 2) {
+                    type.setParameter(kv[0].trim(),kv[1].trim());
+
+                    if("charset".equalsIgnoreCase(kv[0].trim())) {
+                        type.setCharset(Charset.forName(kv[1].trim()));
+                    }
+                }
+            }
+
+            return type;
+        } else {
+            return null;
+        }
+    }
+
+    /**
+     * Determine the best content type out of the selection of content types we offer and the ordered list of content
+     * types requested by the peer.
+     *
+     * TODO: implement remove variant selection algorithm (RFC 2296, http://tools.ietf.org/html/rfc2296)
+     *
+     * @param offeredTypes list of offered types in order of precedence
+     * @param requestedTypes list of requested types in order of precedence - may contain wildcards
+     * @return
+     */
+    public static ContentType bestContentType(List<ContentType> offeredTypes, List<ContentType> requestedTypes) {
+        // check for directly matching types
+        for(ContentType requested : requestedTypes) {
+            for(ContentType offered : offeredTypes) {
+                if(requested.matches(offered)) {
+                    return offered;
+                }
+            }
+        }
+        // check for qualified subtypes also
+        for(ContentType requested : requestedTypes) {
+            for(ContentType offered : offeredTypes) {
+                if(requested.matchesSubtype(offered)) {
+                    return offered;
+                }
+            }
+        }
+
+        // check for wildcard matching types
+        for(ContentType requested : requestedTypes) {
+            for(ContentType offered : offeredTypes) {
+                if(requested.matchesWildcard(offered)) {
+                    return offered;
+                }
+            }
+        }
+        
+        return null;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/7122c515/commons/marmotta-commons/src/test/java/org/apache/marmotta/commons/http/ContentTypeMatchingTest.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/test/java/org/apache/marmotta/commons/http/ContentTypeMatchingTest.java b/commons/marmotta-commons/src/test/java/org/apache/marmotta/commons/http/ContentTypeMatchingTest.java
index 90e60c6..23931b3 100644
--- a/commons/marmotta-commons/src/test/java/org/apache/marmotta/commons/http/ContentTypeMatchingTest.java
+++ b/commons/marmotta-commons/src/test/java/org/apache/marmotta/commons/http/ContentTypeMatchingTest.java
@@ -18,7 +18,7 @@
 package org.apache.marmotta.commons.http;
 
 import org.apache.marmotta.commons.http.ContentType;
-import org.apache.marmotta.commons.http.LMFHttpUtils;
+import org.apache.marmotta.commons.http.MarmottaHttpUtils;
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -100,7 +100,7 @@ public class ContentTypeMatchingTest {
         accepted.add(accepted1);
         accepted.add(accepted2);
 
-        Assert.assertEquals(offered2, LMFHttpUtils.bestContentType(offered,accepted));
+        Assert.assertEquals(offered2, MarmottaHttpUtils.bestContentType(offered,accepted));
     }
 
     @Test
@@ -120,7 +120,7 @@ public class ContentTypeMatchingTest {
         accepted.add(accepted1);
         accepted.add(accepted2);
 
-        Assert.assertEquals(offered1, LMFHttpUtils.bestContentType(offered,accepted));
+        Assert.assertEquals(offered1, MarmottaHttpUtils.bestContentType(offered,accepted));
     }
 
     @Test
@@ -140,7 +140,7 @@ public class ContentTypeMatchingTest {
         accepted.add(accepted1);
         accepted.add(accepted2);
 
-        Assert.assertEquals(offered3, LMFHttpUtils.bestContentType(offered,accepted));
+        Assert.assertEquals(offered3, MarmottaHttpUtils.bestContentType(offered,accepted));
     }
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/7122c515/commons/marmotta-commons/src/test/java/org/apache/marmotta/commons/http/MarmottaHttpUtilsTest.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/test/java/org/apache/marmotta/commons/http/MarmottaHttpUtilsTest.java b/commons/marmotta-commons/src/test/java/org/apache/marmotta/commons/http/MarmottaHttpUtilsTest.java
new file mode 100644
index 0000000..260b7bd
--- /dev/null
+++ b/commons/marmotta-commons/src/test/java/org/apache/marmotta/commons/http/MarmottaHttpUtilsTest.java
@@ -0,0 +1,40 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.marmotta.commons.http;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+import com.google.common.collect.ImmutableList;
+
+/**
+ * MarmottaHttpUtils tests
+ * 
+ * @author Sergio Fernández
+ */
+public class MarmottaHttpUtilsTest {
+
+    @Test
+    public void testConentTypeMatching() throws Exception {
+        assertEquals("application/rdf+xml", MarmottaHttpUtils.bestContentType(ImmutableList.of(new ContentType("application", "rdf+xml")), ImmutableList.of(new ContentType("application", "rdf+xml"))).getMime());
+        assertEquals("application/rdf+xml", MarmottaHttpUtils.bestContentType(ImmutableList.of(new ContentType("application", "rdf+xml")), ImmutableList.of(new ContentType("application", "xml"))).getMime());
+        assertEquals(null, MarmottaHttpUtils.bestContentType(ImmutableList.of(new ContentType("text", "tutle")), ImmutableList.of(new ContentType("text", "plain"))));
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/7122c515/libraries/ldclient/ldclient-api/src/main/java/org/apache/marmotta/ldclient/api/endpoint/Endpoint.java
----------------------------------------------------------------------
diff --git a/libraries/ldclient/ldclient-api/src/main/java/org/apache/marmotta/ldclient/api/endpoint/Endpoint.java b/libraries/ldclient/ldclient-api/src/main/java/org/apache/marmotta/ldclient/api/endpoint/Endpoint.java
index 16759d8..45be4e3 100644
--- a/libraries/ldclient/ldclient-api/src/main/java/org/apache/marmotta/ldclient/api/endpoint/Endpoint.java
+++ b/libraries/ldclient/ldclient-api/src/main/java/org/apache/marmotta/ldclient/api/endpoint/Endpoint.java
@@ -26,7 +26,7 @@ import java.util.Set;
 import java.util.regex.Pattern;
 import java.util.regex.PatternSyntaxException;
 
-import static org.apache.marmotta.commons.http.LMFHttpUtils.parseAcceptHeader;
+import static org.apache.marmotta.commons.http.MarmottaHttpUtils.parseAcceptHeader;
 
 /**
  * Definition of a Linked Data Endpoint. Contains information how to query the

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/7122c515/libraries/ldclient/ldclient-core/src/main/java/org/apache/marmotta/ldclient/services/provider/AbstractHttpProvider.java
----------------------------------------------------------------------
diff --git a/libraries/ldclient/ldclient-core/src/main/java/org/apache/marmotta/ldclient/services/provider/AbstractHttpProvider.java b/libraries/ldclient/ldclient-core/src/main/java/org/apache/marmotta/ldclient/services/provider/AbstractHttpProvider.java
index ef89751..8f45da0 100644
--- a/libraries/ldclient/ldclient-core/src/main/java/org/apache/marmotta/ldclient/services/provider/AbstractHttpProvider.java
+++ b/libraries/ldclient/ldclient-core/src/main/java/org/apache/marmotta/ldclient/services/provider/AbstractHttpProvider.java
@@ -51,7 +51,7 @@ import java.util.List;
 import java.util.Queue;
 import java.util.Set;
 
-import static org.apache.marmotta.commons.http.LMFHttpUtils.parseContentType;
+import static org.apache.marmotta.commons.http.MarmottaHttpUtils.parseContentType;
 
 /**
  * Add file description here!

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/7122c515/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/io/ExportWebService.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/io/ExportWebService.java b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/io/ExportWebService.java
index 36e0c4f..caad296 100644
--- a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/io/ExportWebService.java
+++ b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/io/ExportWebService.java
@@ -25,7 +25,7 @@ import org.apache.marmotta.platform.core.api.exporter.ExportService;
 import org.apache.marmotta.platform.core.api.triplestore.SesameService;
 import org.apache.marmotta.platform.core.exception.io.UnsupportedExporterException;
 import org.apache.marmotta.commons.http.ContentType;
-import org.apache.marmotta.commons.http.LMFHttpUtils;
+import org.apache.marmotta.commons.http.MarmottaHttpUtils;
 import org.openrdf.model.URI;
 import org.openrdf.repository.RepositoryConnection;
 import org.openrdf.repository.RepositoryException;
@@ -97,13 +97,13 @@ public class ExportWebService {
     public Response downloadData(@HeaderParam("Accept") String types, @QueryParam("format") String qFormat, @QueryParam("context") String context_string) throws IOException {
         List<ContentType> acceptedTypes;
         if(qFormat != null) {
-            acceptedTypes = LMFHttpUtils.parseAcceptHeader(qFormat);
+            acceptedTypes = MarmottaHttpUtils.parseAcceptHeader(qFormat);
         } else {
-            acceptedTypes = LMFHttpUtils.parseAcceptHeader(types);
+            acceptedTypes = MarmottaHttpUtils.parseAcceptHeader(types);
         }
-        List<ContentType> offeredTypes  = LMFHttpUtils.parseStringList(exportService.getProducedTypes());
+        List<ContentType> offeredTypes  = MarmottaHttpUtils.parseStringList(exportService.getProducedTypes());
 
-        final ContentType bestType = LMFHttpUtils.bestContentType(offeredTypes,acceptedTypes);
+        final ContentType bestType = MarmottaHttpUtils.bestContentType(offeredTypes,acceptedTypes);
 
         // create a file name for the export, preferrably with a good extension ...
         String fileName;

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/7122c515/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/resource/ResourceWebService.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/resource/ResourceWebService.java b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/resource/ResourceWebService.java
index f2e76eb..3de0d7d 100644
--- a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/resource/ResourceWebService.java
+++ b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/resource/ResourceWebService.java
@@ -46,7 +46,7 @@ import javax.ws.rs.core.Response.Status;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.marmotta.commons.http.ContentType;
 import org.apache.marmotta.commons.http.ETagGenerator;
-import org.apache.marmotta.commons.http.LMFHttpUtils;
+import org.apache.marmotta.commons.http.MarmottaHttpUtils;
 import org.apache.marmotta.commons.http.UriUtil;
 import org.apache.marmotta.commons.sesame.repository.ResourceUtils;
 import org.apache.marmotta.platform.core.api.config.ConfigurationService;
@@ -389,13 +389,13 @@ public class ResourceWebService {
                 // FIXME String appendix = uuid == null ? "?uri=" + URLEncoder.encode(uri, "utf-8") :
                 // "/" + uuid;
 
-                List<ContentType> offeredTypes  = LMFHttpUtils.parseStringList(kiWiIOService.getProducedTypes());
+                List<ContentType> offeredTypes  = MarmottaHttpUtils.parseStringList(kiWiIOService.getProducedTypes());
                 for(ContentType t : offeredTypes) {
                 	t.setParameter("rel", "meta");
                 }
                 String contentmime = contentService.getContentType(r);
                 if(contentmime != null) {
-                	ContentType tContent = LMFHttpUtils.parseContentType(contentmime);
+                	ContentType tContent = MarmottaHttpUtils.parseContentType(contentmime);
                 	tContent.setParameter("rel", "content");
                 	offeredTypes.add(0,tContent);
                 }
@@ -404,8 +404,8 @@ public class ResourceWebService {
                 	return build406(Collections.<ContentType>emptyList(), offeredTypes);
                 }
 
-                List<ContentType> acceptedTypes = LMFHttpUtils.parseAcceptHeader(types);
-                ContentType bestType = LMFHttpUtils.bestContentType(offeredTypes,acceptedTypes);
+                List<ContentType> acceptedTypes = MarmottaHttpUtils.parseAcceptHeader(types);
+                ContentType bestType = MarmottaHttpUtils.bestContentType(offeredTypes,acceptedTypes);
 
                 log.debug("identified best type: {}",bestType);
 
@@ -516,7 +516,7 @@ public class ResourceWebService {
 
             // the offered types are those sent by the client in the Content-Type header; if the rel attribute is not
             // given, we add the default rel value
-            List<ContentType> types = LMFHttpUtils.parseAcceptHeader(mimetype);
+            List<ContentType> types = MarmottaHttpUtils.parseAcceptHeader(mimetype);
             for(ContentType type : types) {
                 if(type.getParameter("rel") == null) {
                     type.setParameter("rel",configurationService.getStringConfiguration("linkeddata.mime.rel.default", "meta"));
@@ -525,7 +525,7 @@ public class ResourceWebService {
 
             // the acceptable types are all types for content and the meta types we have parsers for; we do not care so
             // much about the order ...
-            List<ContentType> acceptable = LMFHttpUtils.parseStringList(kiWiIOService.getProducedTypes());
+            List<ContentType> acceptable = MarmottaHttpUtils.parseStringList(kiWiIOService.getProducedTypes());
             for(ContentType a : acceptable) {
                 a.setParameter("rel", "meta");
             }
@@ -534,7 +534,7 @@ public class ResourceWebService {
             acceptable.add(0,allContent);
 
             // determine the best match between the offered types and the acceptable types
-            ContentType bestType = LMFHttpUtils.bestContentType(types,acceptable);
+            ContentType bestType = MarmottaHttpUtils.bestContentType(types,acceptable);
 
             if (bestType != null) {
                 if (configurationService.getBooleanConfiguration("linkeddata.redirect.put", true)) {

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/7122c515/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/triplestore/ContextWebService.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/triplestore/ContextWebService.java b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/triplestore/ContextWebService.java
index 9e7e413..b61651f 100644
--- a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/triplestore/ContextWebService.java
+++ b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/triplestore/ContextWebService.java
@@ -46,7 +46,7 @@ import javax.ws.rs.core.Response.Status;
 
 import org.apache.commons.lang3.StringUtils;
 import org.apache.marmotta.commons.http.ContentType;
-import org.apache.marmotta.commons.http.LMFHttpUtils;
+import org.apache.marmotta.commons.http.MarmottaHttpUtils;
 import org.apache.marmotta.platform.core.api.config.ConfigurationService;
 import org.apache.marmotta.platform.core.api.exporter.ExportService;
 import org.apache.marmotta.platform.core.api.triplestore.ContextService;
@@ -198,13 +198,13 @@ public class ContextWebService {
     private URI buildExportUri(String uri, String accept, String format) throws URISyntaxException {
         List<ContentType> acceptedTypes;
         if(format != null) {
-            acceptedTypes = LMFHttpUtils.parseAcceptHeader(format);
+            acceptedTypes = MarmottaHttpUtils.parseAcceptHeader(format);
         } else {
-            acceptedTypes = LMFHttpUtils.parseAcceptHeader(accept);
+            acceptedTypes = MarmottaHttpUtils.parseAcceptHeader(accept);
         }
-        List<ContentType> offeredTypes  = LMFHttpUtils.parseStringList(exportService.getProducedTypes());
+        List<ContentType> offeredTypes  = MarmottaHttpUtils.parseStringList(exportService.getProducedTypes());
         offeredTypes.removeAll(Collections.unmodifiableList(Arrays.asList(new ContentType("text", "html"), new ContentType("application", "xhtml+xml"))));
-        final ContentType bestType = LMFHttpUtils.bestContentType(offeredTypes, acceptedTypes);
+        final ContentType bestType = MarmottaHttpUtils.bestContentType(offeredTypes, acceptedTypes);
         return new URI(configurationService.getBaseUri() + "export/download?context=" + uri + "&format=" + bestType.getMime());
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/7122c515/platform/marmotta-ldcache/src/main/java/org/apache/marmotta/platform/ldcache/services/endpoint/LinkedDataEndpointServiceImpl.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-ldcache/src/main/java/org/apache/marmotta/platform/ldcache/services/endpoint/LinkedDataEndpointServiceImpl.java b/platform/marmotta-ldcache/src/main/java/org/apache/marmotta/platform/ldcache/services/endpoint/LinkedDataEndpointServiceImpl.java
index 2f426c8..5fc55fa 100644
--- a/platform/marmotta-ldcache/src/main/java/org/apache/marmotta/platform/ldcache/services/endpoint/LinkedDataEndpointServiceImpl.java
+++ b/platform/marmotta-ldcache/src/main/java/org/apache/marmotta/platform/ldcache/services/endpoint/LinkedDataEndpointServiceImpl.java
@@ -21,7 +21,7 @@ import org.apache.marmotta.platform.ldcache.api.endpoint.LinkedDataEndpointServi
 import com.google.common.base.Joiner;
 import org.apache.marmotta.platform.core.api.config.ConfigurationService;
 import org.apache.marmotta.commons.http.ContentType;
-import org.apache.marmotta.commons.http.LMFHttpUtils;
+import org.apache.marmotta.commons.http.MarmottaHttpUtils;
 import org.apache.marmotta.ldclient.api.endpoint.Endpoint;
 import org.openrdf.model.URI;
 import org.slf4j.Logger;
@@ -191,7 +191,7 @@ public class LinkedDataEndpointServiceImpl implements LinkedDataEndpointService
         endpoint.setDefaultExpiry(configurationService.getLongConfiguration("ldcache.endpoint." + label + ".expiry"));
         endpoint.setActive(configurationService.getBooleanConfiguration("ldcache.endpoint." + label + ".active"));
         endpoint.setContentTypes(new HashSet<ContentType>(
-                LMFHttpUtils.parseAcceptHeader(
+                MarmottaHttpUtils.parseAcceptHeader(
                         configurationService.getStringConfiguration("ldcache.endpoint." + label + ".contenttype",""))
         ));
 

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/7122c515/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 48e6e4c..06ab136 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
@@ -49,7 +49,7 @@ import javax.ws.rs.core.UriBuilder;
 
 import org.apache.commons.lang3.StringUtils;
 import org.apache.marmotta.commons.http.ContentType;
-import org.apache.marmotta.commons.http.LMFHttpUtils;
+import org.apache.marmotta.commons.http.MarmottaHttpUtils;
 import org.apache.marmotta.platform.core.api.config.ConfigurationService;
 import org.apache.marmotta.platform.core.api.exporter.ExportService;
 import org.apache.marmotta.platform.core.api.templating.TemplatingService;
@@ -234,14 +234,14 @@ public class SparqlWebService {
 	        	List<ContentType> acceptedTypes;
 	        	List<ContentType> offeredTypes;
 	        	if (resultType != null) {
-	        		acceptedTypes = LMFHttpUtils.parseAcceptHeader(resultType);
+	        		acceptedTypes = MarmottaHttpUtils.parseAcceptHeader(resultType);
 	        	} else {
-	        		acceptedTypes = LMFHttpUtils.parseAcceptHeader(acceptHeader);
+	        		acceptedTypes = MarmottaHttpUtils.parseAcceptHeader(acceptHeader);
 	        	}
 	        	if (QueryType.TUPLE.equals(queryType)) {
-	        		offeredTypes  = LMFHttpUtils.parseStringList(Lists.newArrayList("application/sparql-results+xml","application/sparql-results+json", "text/html", "application/rdf+xml", "text/csv"));
+	        		offeredTypes  = MarmottaHttpUtils.parseStringList(Lists.newArrayList("application/sparql-results+xml","application/sparql-results+json", "text/html", "application/rdf+xml", "text/csv"));
 	        	} else if (QueryType.BOOL.equals(queryType)) {
-	        		offeredTypes  = LMFHttpUtils.parseStringList(Lists.newArrayList("application/sparql-results+xml","application/sparql-results+json", "text/html", "application/rdf+xml", "text/csv"));
+	        		offeredTypes  = MarmottaHttpUtils.parseStringList(Lists.newArrayList("application/sparql-results+xml","application/sparql-results+json", "text/html", "application/rdf+xml", "text/csv"));
 	        	} else if (QueryType.GRAPH.equals(queryType)) {
 	        		Set<String> producedTypes = new HashSet<String>(exportService.getProducedTypes());
 	        		producedTypes.remove("application/xml");
@@ -249,13 +249,13 @@ public class SparqlWebService {
 	        		producedTypes.remove("text/plain");
 	        		producedTypes.remove("text/html");
 	        		producedTypes.remove("application/xhtml+xml");
-	        		offeredTypes  = LMFHttpUtils.parseStringList(producedTypes);
+	        		offeredTypes  = MarmottaHttpUtils.parseStringList(producedTypes);
 	        	} else {
 	        		return Response.status(Response.Status.BAD_REQUEST).entity("no result format specified or unsupported result format").build();
 	        	}
-	            ContentType bestType = LMFHttpUtils.bestContentType(offeredTypes, acceptedTypes);
+	            ContentType bestType = MarmottaHttpUtils.bestContentType(offeredTypes, acceptedTypes);
 	            if (bestType == null) {
-	            	return Response.status(Response.Status.BAD_REQUEST).entity("no result format specified or unsupported result format").build();
+	            	return Response.status(Response.Status.UNSUPPORTED_MEDIA_TYPE).entity("no result format specified or unsupported result format").build();
 	            } else {
 	        		//return buildQueryResponse(resultType, query);
 	            	return buildQueryResponse(bestType, query, queryType);
@@ -397,9 +397,9 @@ public class SparqlWebService {
                 return Response.ok().build();
             } else {
                 if (resultType == null) {
-                    List<ContentType> acceptedTypes = LMFHttpUtils.parseAcceptHeader(request.getHeader("Accept"));
-                    List<ContentType> offeredTypes = LMFHttpUtils.parseStringList(Lists.newArrayList("*/*", "text/html"));
-                    ContentType bestType = LMFHttpUtils.bestContentType(offeredTypes, acceptedTypes);
+                    List<ContentType> acceptedTypes = MarmottaHttpUtils.parseAcceptHeader(request.getHeader("Accept"));
+                    List<ContentType> offeredTypes = MarmottaHttpUtils.parseStringList(Lists.newArrayList("*/*", "text/html"));
+                    ContentType bestType = MarmottaHttpUtils.bestContentType(offeredTypes, acceptedTypes);
                     if (bestType != null) {
                         resultType = bestType.getMime();
                     }

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/7122c515/platform/marmotta-sparql/src/test/java/org/apache/marmotta/platform/sparql/webservices/SparqlWebServiceTest.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-sparql/src/test/java/org/apache/marmotta/platform/sparql/webservices/SparqlWebServiceTest.java b/platform/marmotta-sparql/src/test/java/org/apache/marmotta/platform/sparql/webservices/SparqlWebServiceTest.java
index 8d0486c..006c9a6 100644
--- a/platform/marmotta-sparql/src/test/java/org/apache/marmotta/platform/sparql/webservices/SparqlWebServiceTest.java
+++ b/platform/marmotta-sparql/src/test/java/org/apache/marmotta/platform/sparql/webservices/SparqlWebServiceTest.java
@@ -133,10 +133,22 @@ public class SparqlWebServiceTest {
     public void testConstructContentNegotiationPlain() throws IOException, InterruptedException {
         expect().
         	log().ifError().
+    		statusCode(415).
+    	given().
+    		header("Accept", "text/plain").
+    		param("query", "CONSTRUCT { <http://www.wikier.org/foaf#wikier2> ?p ?o } WHERE { <http://www.wikier.org/foaf#wikier> ?p ?o }").
+		when().
+    		get("/sparql/select");
+    }
+    
+    @Test
+    public void testConstructContentNegotiationTurtle() throws IOException, InterruptedException {
+        expect().
+        	log().ifError().
     		statusCode(200).
     		contentType("text/turtle").
     	given().
-    		header("Accept", "plain/text").
+    		header("Accept", "text/turtle").
     		param("query", "CONSTRUCT { <http://www.wikier.org/foaf#wikier2> ?p ?o } WHERE { <http://www.wikier.org/foaf#wikier> ?p ?o }").
 		when().
     		get("/sparql/select");
@@ -171,8 +183,7 @@ public class SparqlWebServiceTest {
     public void testDescribeContentNegotiationPlain() throws IOException, InterruptedException {
         expect().
         	log().ifError().
-    		statusCode(200).
-    		contentType("text/turle").
+    		statusCode(415).
     	given().
     		header("Accept", "plain/text").
     		param("query", "DESCRIBE <http://www.wikier.org/foaf#wikier>").

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/7122c515/platform/marmotta-versioning/src/main/java/org/apache/marmotta/platform/versioning/services/VersionSerializerServiceImpl.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-versioning/src/main/java/org/apache/marmotta/platform/versioning/services/VersionSerializerServiceImpl.java b/platform/marmotta-versioning/src/main/java/org/apache/marmotta/platform/versioning/services/VersionSerializerServiceImpl.java
index 9eefe34..c288f67 100644
--- a/platform/marmotta-versioning/src/main/java/org/apache/marmotta/platform/versioning/services/VersionSerializerServiceImpl.java
+++ b/platform/marmotta-versioning/src/main/java/org/apache/marmotta/platform/versioning/services/VersionSerializerServiceImpl.java
@@ -20,7 +20,7 @@ package org.apache.marmotta.platform.versioning.services;
 import org.apache.marmotta.platform.versioning.api.VersionSerializerService;
 import org.apache.marmotta.platform.versioning.io.VersionSerializer;
 import org.apache.marmotta.commons.http.ContentType;
-import org.apache.marmotta.commons.http.LMFHttpUtils;
+import org.apache.marmotta.commons.http.MarmottaHttpUtils;
 
 import javax.enterprise.context.ApplicationScoped;
 import javax.enterprise.inject.Any;
@@ -49,7 +49,7 @@ public class VersionSerializerServiceImpl implements VersionSerializerService {
     @Override
     public VersionSerializer getSerializer(List<ContentType> type) throws IOException {
         for(VersionSerializer serializer : serializers) {
-            if(LMFHttpUtils.bestContentType(serializer.getContentTypes(),type) != null) return serializer;
+            if(MarmottaHttpUtils.bestContentType(serializer.getContentTypes(),type) != null) return serializer;
         }
         throw new IOException("Cannot find serializer for " + type);
     }

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/7122c515/platform/marmotta-versioning/src/main/java/org/apache/marmotta/platform/versioning/webservices/MementoWebService.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-versioning/src/main/java/org/apache/marmotta/platform/versioning/webservices/MementoWebService.java b/platform/marmotta-versioning/src/main/java/org/apache/marmotta/platform/versioning/webservices/MementoWebService.java
index 2661fea..fc12de1 100644
--- a/platform/marmotta-versioning/src/main/java/org/apache/marmotta/platform/versioning/webservices/MementoWebService.java
+++ b/platform/marmotta-versioning/src/main/java/org/apache/marmotta/platform/versioning/webservices/MementoWebService.java
@@ -38,7 +38,7 @@ import org.apache.marmotta.platform.core.api.config.ConfigurationService;
 import org.apache.marmotta.platform.core.api.triplestore.SesameService;
 import org.apache.marmotta.commons.collections.CollectionUtils;
 import org.apache.marmotta.commons.http.ContentType;
-import org.apache.marmotta.commons.http.LMFHttpUtils;
+import org.apache.marmotta.commons.http.MarmottaHttpUtils;
 import org.apache.marmotta.kiwi.versioning.model.Version;
 import org.openrdf.model.URI;
 import org.openrdf.repository.RepositoryConnection;
@@ -263,7 +263,7 @@ public class MementoWebService {
 
                 final URI resource = ResourceUtils.getUriResource(conn, resource_string);
 
-                List<ContentType> types = LMFHttpUtils.parseAcceptHeader(types_string);
+                List<ContentType> types = MarmottaHttpUtils.parseAcceptHeader(types_string);
 
                 //get versions
                 final RepositoryResult<Version> versions = versioningService.listVersions(resource);
@@ -315,9 +315,9 @@ public class MementoWebService {
      * @throws IllegalArgumentException if no type is supported
      */
     private ContentType getContentType(String types) throws IllegalArgumentException {
-        List<ContentType> acceptedTypes = LMFHttpUtils.parseAcceptHeader(types);
-        List<ContentType> offeredTypes  = LMFHttpUtils.parseStringList(lmfIOService.getProducedTypes());
-        ContentType type = LMFHttpUtils.bestContentType(offeredTypes,acceptedTypes);
+        List<ContentType> acceptedTypes = MarmottaHttpUtils.parseAcceptHeader(types);
+        List<ContentType> offeredTypes  = MarmottaHttpUtils.parseStringList(lmfIOService.getProducedTypes());
+        ContentType type = MarmottaHttpUtils.bestContentType(offeredTypes,acceptedTypes);
         if(type == null) throw new IllegalArgumentException("Requested type is not supported");
         return type;
     }


[3/5] git commit: MARMOTTA-322: unified all update implementations in the web service too

Posted by wi...@apache.org.
MARMOTTA-322: unified all update implementations in the web service too


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

Branch: refs/heads/develop
Commit: d1a4ab682652b456a8b60f375a01dd68210e43f4
Parents: b3bb9d7
Author: Sergio Fernández <wi...@apache.org>
Authored: Thu Sep 26 16:33:38 2013 +0200
Committer: Sergio Fernández <wi...@apache.org>
Committed: Thu Sep 26 16:33:38 2013 +0200

----------------------------------------------------------------------
 .../sparql/webservices/SparqlWebService.java    | 141 +++++++++----------
 1 file changed, 64 insertions(+), 77 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/d1a4ab68/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 06d281a..614868b 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
@@ -332,12 +332,69 @@ public class SparqlWebService {
      */
     @GET
     @Path(UPDATE)
-    public Response updateGet(@QueryParam("update") String update, @QueryParam("query") String query, @QueryParam("output") String resultType,
-            @Context HttpServletRequest request) {
-        try {
-            String q = getUpdateQuery(update, query);
-            if (StringUtils.isNotBlank(q)) {
-                sparqlService.update(QueryLanguage.SPARQL, q);
+    public Response updateGet(@QueryParam("update") String update, @QueryParam("query") String query, @QueryParam("output") String resultType, @Context HttpServletRequest request) {
+    	String q = getUpdateQuery(update, query);
+        return update(q, resultType, request);
+    }
+    
+    /**
+     * Execute a SPARQL 1.1 Update request using update via POST directly; 
+     * see details at http://www.w3.org/TR/sparql11-protocol/\#update-operation
+     * 
+     * @param request the servlet request (to retrieve the SPARQL 1.1 Update query passed in the
+     *            body of the POST request)
+     * @HTTP 200 in case the update was carried out successfully
+     * @HTTP 400 in case the update query is missing or invalid
+     * @HTTP 500 in case the update was not successful
+     * @return empty content in case the update was successful, the error message in case an error
+     *         occurred
+     */
+    @POST
+    @Path(UPDATE)
+    @Consumes("application/sparql-update")
+    public Response updatePostDirectly(@Context HttpServletRequest request, @QueryParam("output") String resultType) {
+		try {
+			String q = CharStreams.toString(request.getReader());
+	        return update(q, resultType, request);
+		} catch (IOException e) {
+			return Response.serverError().entity(WebServiceUtil.jsonErrorResponse(e)).build();
+		}
+    }
+    
+    /**
+     * Execute a SPARQL 1.1 Update request using update via URL-encoded POST; 
+     * see details at http://www.w3.org/TR/sparql11-protocol/\#update-operation
+     * 
+     * @param request the servlet request (to retrieve the SPARQL 1.1 Update query passed in the
+     *            body of the POST request)
+     * @HTTP 200 in case the update was carried out successfully
+     * @HTTP 400 in case the update query is missing or invalid
+     * @HTTP 500 in case the update was not successful
+     * @return empty content in case the update was successful, the error message in case an error
+     *         occurred
+     */
+    @POST
+    @Path(UPDATE)
+    @Consumes({"application/x-www-url-form-urlencoded", "application/x-www-form-urlencoded"})
+    public Response updatePostUrlEncoded(@Context HttpServletRequest request) {
+    	try {
+	    	Map<String,String> params = parseEncodedQueryParameters(CharStreams.toString(request.getReader()));  
+			String q = StringUtils.defaultString(params.get("update"));
+			String resultType = StringUtils.defaultString(params.get("output"));
+	        return update(q, resultType, request);
+    	} catch (IOException e) {
+			return Response.serverError().entity(WebServiceUtil.jsonErrorResponse(e)).build();
+		}
+    }    
+
+    /**
+     * Actual update implementation
+     * 
+     */
+	private Response update(String update, String resultType, HttpServletRequest request) {
+		try {
+            if (StringUtils.isNotBlank(update)) {
+                sparqlService.update(QueryLanguage.SPARQL, update);
                 return Response.ok().build();
             } else {
                 if (resultType == null) {
@@ -363,7 +420,7 @@ public class SparqlWebService {
         } catch (URISyntaxException e) {
             return Response.serverError().entity(WebServiceUtil.jsonErrorResponse(e)).build();
         }
-    }
+	}
 
     /**
      * Get right update query from both possible parameters, for keeping
@@ -381,76 +438,6 @@ public class SparqlWebService {
             return query;
         } else
             return null;
-    }
-
-    /**
-     * Execute a SPARQL 1.1 Update request using update via POST directly; 
-     * see details at http://www.w3.org/TR/sparql11-protocol/\#update-operation
-     * 
-     * @param request the servlet request (to retrieve the SPARQL 1.1 Update query passed in the
-     *            body of the POST request)
-     * @HTTP 200 in case the update was carried out successfully
-     * @HTTP 400 in case the update query is missing or invalid
-     * @HTTP 500 in case the update was not successful
-     * @return empty content in case the update was successful, the error message in case an error
-     *         occurred
-     */
-    @POST
-    @Path(UPDATE)
-    @Consumes("application/sparql-update")
-    public Response updatePostDirectly(@Context HttpServletRequest request) {
-        try {
-            String query = CharStreams.toString(request.getReader());
-            if (StringUtils.isNotBlank(query)) {
-                sparqlService.update(QueryLanguage.SPARQL, query);
-                return Response.ok().build();
-            } else
-                return Response.status(Response.Status.BAD_REQUEST).entity("no SPARQL query given").build();
-        } catch (MalformedQueryException e) {
-            return Response.status(Response.Status.BAD_REQUEST).entity(WebServiceUtil.jsonErrorResponse(e)).build();
-        } catch(UpdateExecutionException e) {
-            log.error("update execution threw an exception", e);
-            return Response.serverError().entity(WebServiceUtil.jsonErrorResponse(e)).build();
-        } catch (MarmottaException e) {
-            return Response.serverError().entity(WebServiceUtil.jsonErrorResponse(e)).build();
-        } catch (IOException e) {
-            return Response.serverError().entity(WebServiceUtil.jsonErrorResponse(e)).build();
-        }
-    }
-    
-    /**
-     * Execute a SPARQL 1.1 Update request using update via URL-encoded POST; 
-     * see details at http://www.w3.org/TR/sparql11-protocol/\#update-operation
-     * 
-     * @param request the servlet request (to retrieve the SPARQL 1.1 Update query passed in the
-     *            body of the POST request)
-     * @HTTP 200 in case the update was carried out successfully
-     * @HTTP 400 in case the update query is missing or invalid
-     * @HTTP 500 in case the update was not successful
-     * @return empty content in case the update was successful, the error message in case an error
-     *         occurred
-     */
-    @POST
-    @Path(UPDATE)
-    @Consumes({"application/x-www-url-form-urlencoded", "application/x-www-form-urlencoded"})
-    public Response updatePostUrlEncoded(@Context HttpServletRequest request) {
-        try {
-            Map<String,String> params = parseEncodedQueryParameters(CharStreams.toString(request.getReader()));           
-            if (params.containsKey("update") && StringUtils.isNotBlank(params.get("update"))) {
-                sparqlService.update(QueryLanguage.SPARQL, params.get("update"));
-                return Response.ok().build();
-            } else
-                return Response.status(Response.Status.BAD_REQUEST).entity("no SPARQL query given").build();
-        } catch (MalformedQueryException e) {
-            return Response.status(Response.Status.BAD_REQUEST).entity(WebServiceUtil.jsonErrorResponse(e)).build();
-        } catch(UpdateExecutionException e) {
-            log.error("update execution threw an exception", e);
-            return Response.serverError().entity(WebServiceUtil.jsonErrorResponse(e)).build();
-        } catch (MarmottaException e) {
-            return Response.serverError().entity(WebServiceUtil.jsonErrorResponse(e)).build();
-        } catch (IOException e) {
-            return Response.serverError().entity(WebServiceUtil.jsonErrorResponse(e)).build();
-        }
     }    
 
     /**