You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2015/08/20 13:08:32 UTC
[01/16] jena git commit: JENA-491 Fuseki Support: repair formatting
of SPARQL_Query.java and TestQuery.java
Repository: jena
Updated Branches:
refs/heads/JENA-491-construct-quads 3ac6a5af4 -> 444a6c9cb
JENA-491 Fuseki Support: repair formatting of SPARQL_Query.java and
TestQuery.java
Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/c7dedb2b
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/c7dedb2b
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/c7dedb2b
Branch: refs/heads/JENA-491-construct-quads
Commit: c7dedb2b5b3455b2a4d62c58c138fc690d8ea383
Parents: 69f1ee2
Author: confidencesun <co...@gmail.com>
Authored: Mon Aug 17 21:12:01 2015 +0800
Committer: confidencesun <co...@gmail.com>
Committed: Mon Aug 17 21:12:01 2015 +0800
----------------------------------------------------------------------
.../jena/fuseki/servlets/SPARQL_Query.java | 748 +++++++++----------
.../java/org/apache/jena/fuseki/TestQuery.java | 193 +++--
2 files changed, 461 insertions(+), 480 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jena/blob/c7dedb2b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Query.java
----------------------------------------------------------------------
diff --git a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Query.java b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Query.java
index bed63da..8a2195e 100644
--- a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Query.java
+++ b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Query.java
@@ -16,7 +16,7 @@
* limitations under the License.
*/
-package org.apache.jena.fuseki.servlets;
+package org.apache.jena.fuseki.servlets ;
import static java.lang.String.format;
import static org.apache.jena.fuseki.server.CounterName.QueryTimeouts;
@@ -74,405 +74,355 @@ import org.apache.jena.sparql.core.Prologue;
import org.apache.jena.sparql.resultset.SPARQLResult;
import org.apache.jena.web.HttpSC;
-/**
- * Handle SPARQL Query requests overt eh SPARQL Protocol. Subclasses provide
- * this algorithm with the actual dataset to query, whether a dataset hosted by
- * this server ({@link SPARQL_QueryDataset}) or speciifed in the protocol
- * request ({@link SPARQL_QueryGeneral}).
- */
-public abstract class SPARQL_Query extends SPARQL_Protocol {
- private static final String QueryParseBase = Fuseki.BaseParserSPARQL;
-
- public SPARQL_Query() {
- super();
- }
-
- // Choose REST verbs to support.
-
- @Override
- protected void doPost(HttpServletRequest request,
- HttpServletResponse response) {
- doCommon(request, response);
- }
-
- @Override
- protected void doGet(HttpServletRequest request,
- HttpServletResponse response) {
- doCommon(request, response);
- }
-
- // HEAD
-
- @Override
- protected void doOptions(HttpServletRequest request,
- HttpServletResponse response) {
- setCommonHeadersForOptions(response);
- response.setHeader(HttpNames.hAllow, "GET,OPTIONS,POST");
- response.setHeader(HttpNames.hContentLengh, "0");
- }
-
- @Override
- protected final void perform(HttpAction action) {
- // GET
- if (action.request.getMethod().equals(HttpNames.METHOD_GET)) {
- executeWithParameter(action);
- return;
- }
-
- ContentType ct = FusekiLib.getContentType(action);
-
- // POST application/x-www-form-url
- // POST ?query= and no Content-Type
- if (ct == null || isHtmlForm(ct)) {
- // validation checked that if no Content-type, then its a POST with
- // ?query=
- executeWithParameter(action);
- return;
- }
-
- // POST application/sparql-query
- if (matchContentType(ct, ctSPARQLQuery)) {
- executeBody(action);
- return;
- }
-
- ServletOps.error(HttpSC.UNSUPPORTED_MEDIA_TYPE_415,
- "Bad content type: " + ct.getContentType());
- }
-
- // All the params we support
-
- protected static List<String> allParams = Arrays.asList(paramQuery,
- paramDefaultGraphURI, paramNamedGraphURI, paramQueryRef,
- paramStyleSheet, paramAccept, paramOutput1, paramOutput2,
- paramCallback, paramForceAccept, paramTimeout);
-
- /**
- * Validate the request, checking HTTP method and HTTP Parameters.
- *
- * @param action
- * HTTP Action
- */
- @Override
- protected void validate(HttpAction action) {
- String method = action.request.getMethod().toUpperCase(Locale.ROOT);
-
- if (!HttpNames.METHOD_POST.equals(method)
- && !HttpNames.METHOD_GET.equals(method))
- ServletOps.errorMethodNotAllowed("Not a GET or POST request");
-
- if (HttpNames.METHOD_GET.equals(method)
- && action.request.getQueryString() == null) {
- ServletOps.warning(action, "Service Description / SPARQL Query / "
- + action.request.getRequestURI());
- ServletOps.errorNotFound("Service Description: "
- + action.request.getRequestURI());
- }
-
- // Use of the dataset describing parameters is check later.
- try {
- validateParams(action, allParams);
- validateRequest(action);
- } catch (ActionErrorException ex) {
- throw ex;
- }
- // Query not yet parsed.
- }
-
- /**
- * Validate the request after checking HTTP method and HTTP Parameters.
- *
- * @param action
- * HTTP Action
- */
- protected abstract void validateRequest(HttpAction action);
-
- /**
- * Helper method for validating request.
- *
- * @param request
- * HTTP request
- * @param params
- * parameters in a collection of Strings
- */
- protected void validateParams(HttpAction action, Collection<String> params) {
- HttpServletRequest request = action.request;
- ContentType ct = FusekiLib.getContentType(request);
- boolean mustHaveQueryParam = true;
- if (ct != null) {
- String incoming = ct.getContentType();
-
- if (matchContentType(ctSPARQLQuery, ct)) {
- mustHaveQueryParam = false;
- // Drop through.
- } else if (matchContentType(ctHTMLForm, ct)) {
- // Nothing specific to do
- } else
- ServletOps.error(HttpSC.UNSUPPORTED_MEDIA_TYPE_415,
- "Unsupported: " + incoming);
- }
-
- // GET/POST of a form at this point.
-
- if (mustHaveQueryParam) {
- int N = countParamOccurences(request, paramQuery);
-
- if (N == 0)
- ServletOps
- .errorBadRequest("SPARQL Query: No 'query=' parameter");
- if (N > 1)
- ServletOps
- .errorBadRequest("SPARQL Query: Multiple 'query=' parameters");
-
- // application/sparql-query does not use a query param.
- String queryStr = request.getParameter(HttpNames.paramQuery);
-
- if (queryStr == null)
- ServletOps
- .errorBadRequest("SPARQL Query: No query specified (no 'query=' found)");
- if (queryStr.isEmpty())
- ServletOps.errorBadRequest("SPARQL Query: Empty query string");
- }
-
- if (params != null) {
- Enumeration<String> en = request.getParameterNames();
- for (; en.hasMoreElements();) {
- String name = en.nextElement();
- if (!params.contains(name))
- ServletOps.warning(action,
- "SPARQL Query: Unrecognize request parameter (ignored): "
- + name);
- }
- }
- }
-
- private void executeWithParameter(HttpAction action) {
- String queryString = action.request.getParameter(paramQuery);
- execute(queryString, action);
- }
-
- private void executeBody(HttpAction action) {
- String queryString = null;
- try {
- InputStream input = action.request.getInputStream();
- queryString = IO.readWholeFileAsUTF8(input);
- } catch (IOException ex) {
- ServletOps.errorOccurred(ex);
- }
- execute(queryString, action);
- }
-
- private void execute(String queryString, HttpAction action) {
- String queryStringLog = ServletOps.formatForLog(queryString);
- if (action.verbose)
- action.log
- .info(format("[%d] Query = \n%s", action.id, queryString));
- else
- action.log
- .info(format("[%d] Query = %s", action.id, queryStringLog));
-
- Query query = null;
- try {
- // NB syntax is ARQ (a superset of SPARQL)
- query = QueryFactory.create(queryString, QueryParseBase,
- Syntax.syntaxARQ);
- queryStringLog = formatForLog(query);
- validateQuery(action, query);
- } catch (ActionErrorException ex) {
- throw ex;
- } catch (QueryParseException ex) {
- ServletOps.errorBadRequest("Parse error: \n" + queryString + "\n\r"
- + messageForQueryException(ex));
- }
- // Should not happen.
- catch (QueryException ex) {
- ServletOps.errorBadRequest("Error: \n" + queryString + "\n\r"
- + ex.getMessage());
- }
-
- // Assumes finished whole thing by end of sendResult.
- try {
- action.beginRead();
- Dataset dataset = decideDataset(action, query, queryStringLog);
- try (QueryExecution qExec = createQueryExecution(query, dataset);) {
- SPARQLResult result = executeQuery(action, qExec, query,
- queryStringLog);
- // Deals with exceptions itself.
- sendResults(action, result, query.getPrologue());
- }
- } catch (QueryParseException ex) {
- // Late stage static error (e.g. bad fixed Lucene query string).
- ServletOps.errorBadRequest("Query parse error: \n" + queryString
- + "\n\r" + messageForQueryException(ex));
- } catch (QueryCancelledException ex) {
- // Additional counter information.
- incCounter(action.getEndpoint().getCounters(), QueryTimeouts);
- throw ex;
- } finally {
- action.endRead();
- }
- }
-
- /**
- * Check the query - if unacceptable, throw ActionErrorException or call
- * super.error
- *
- * @param action
- * HTTP Action
- * @param query
- * SPARQL Query
- */
- protected abstract void validateQuery(HttpAction action, Query query);
-
- /**
- * Create the {@link QueryExecution} for this operation.
- *
- * @param query
- * @param dataset
- * @return QueryExecution
- */
- protected QueryExecution createQueryExecution(Query query, Dataset dataset) {
- return QueryExecutionFactory.create(query, dataset);
- }
-
- /**
- * Perform the {@link QueryExecution} once.
- *
- * @param action
- * @param queryExecution
- * @param query
- * @param queryStringLog
- * Informational string created from the initial query.
- * @return
- */
- protected SPARQLResult executeQuery(HttpAction action,
- QueryExecution queryExecution, Query query, String queryStringLog) {
- setAnyTimeouts(queryExecution, action);
-
- if (query.isSelectType()) {
- ResultSet rs = queryExecution.execSelect();
-
- // Force some query execution now.
- //
- // If the timeout-first-row goes off, the output stream has not
- // been started so the HTTP error code is sent.
-
- rs.hasNext();
-
- // If we wanted perfect query time cancellation, we could consume
- // the result now
- // to see if the timeout-end-of-query goes off.
-
- // rs = ResultSetFactory.copyResults(rs) ;
-
- action.log.info(format("[%d] exec/select", action.id));
- return new SPARQLResult(rs);
- }
-
- if (query.isConstructType()) {
-
- MediaType rdfMediaType = AcceptList.match( DEF.pureRdfOffer, new AcceptList( WebLib.getAccept(action.getRequest())));
-
+/** Handle SPARQL Query requests overt eh SPARQL Protocol.
+ * Subclasses provide this algorithm with the actual dataset to query, whether
+ * a dataset hosted by this server ({@link SPARQL_QueryDataset}) or
+ * speciifed in the protocol request ({@link SPARQL_QueryGeneral}).
+ */
+public abstract class SPARQL_Query extends SPARQL_Protocol
+{
+ private static final String QueryParseBase = Fuseki.BaseParserSPARQL ;
+
+ public SPARQL_Query() {
+ super() ;
+ }
+
+ // Choose REST verbs to support.
+
+ @Override
+ protected void doPost(HttpServletRequest request, HttpServletResponse response) {
+ doCommon(request, response) ;
+ }
+
+ @Override
+ protected void doGet(HttpServletRequest request, HttpServletResponse response) {
+ doCommon(request, response) ;
+ }
+
+ // HEAD
+
+ @Override
+ protected void doOptions(HttpServletRequest request, HttpServletResponse response) {
+ setCommonHeadersForOptions(response) ;
+ response.setHeader(HttpNames.hAllow, "GET,OPTIONS,POST") ;
+ response.setHeader(HttpNames.hContentLengh, "0") ;
+ }
+
+ @Override
+ protected final void perform(HttpAction action) {
+ // GET
+ if ( action.request.getMethod().equals(HttpNames.METHOD_GET) ) {
+ executeWithParameter(action) ;
+ return ;
+ }
+
+ ContentType ct = FusekiLib.getContentType(action) ;
+
+ // POST application/x-www-form-url
+ // POST ?query= and no Content-Type
+ if ( ct == null || isHtmlForm(ct) ) {
+ // validation checked that if no Content-type, then its a POST with ?query=
+ executeWithParameter(action) ;
+ return ;
+ }
+
+ // POST application/sparql-query
+ if ( matchContentType(ct, ctSPARQLQuery) ) {
+ executeBody(action) ;
+ return ;
+ }
+
+ ServletOps.error(HttpSC.UNSUPPORTED_MEDIA_TYPE_415, "Bad content type: " + ct.getContentType()) ;
+ }
+
+ // All the params we support
+
+ protected static List<String> allParams = Arrays.asList(paramQuery, paramDefaultGraphURI, paramNamedGraphURI,
+ paramQueryRef, paramStyleSheet, paramAccept, paramOutput1,
+ paramOutput2, paramCallback, paramForceAccept, paramTimeout) ;
+
+ /**
+ * Validate the request, checking HTTP method and HTTP Parameters.
+ * @param action HTTP Action
+ */
+ @Override
+ protected void validate(HttpAction action) {
+ String method = action.request.getMethod().toUpperCase(Locale.ROOT) ;
+
+ if ( !HttpNames.METHOD_POST.equals(method) && !HttpNames.METHOD_GET.equals(method) )
+ ServletOps.errorMethodNotAllowed("Not a GET or POST request") ;
+
+ if ( HttpNames.METHOD_GET.equals(method) && action.request.getQueryString() == null ) {
+ ServletOps.warning(action, "Service Description / SPARQL Query / " + action.request.getRequestURI()) ;
+ ServletOps.errorNotFound("Service Description: " + action.request.getRequestURI()) ;
+ }
+
+ // Use of the dataset describing parameters is check later.
+ try {
+ validateParams(action, allParams) ;
+ validateRequest(action) ;
+ } catch (ActionErrorException ex) {
+ throw ex ;
+ }
+ // Query not yet parsed.
+ }
+
+ /**
+ * Validate the request after checking HTTP method and HTTP Parameters.
+ * @param action HTTP Action
+ */
+ protected abstract void validateRequest(HttpAction action) ;
+
+ /**
+ * Helper method for validating request.
+ * @param request HTTP request
+ * @param params parameters in a collection of Strings
+ */
+ protected void validateParams(HttpAction action, Collection<String> params) {
+ HttpServletRequest request = action.request ;
+ ContentType ct = FusekiLib.getContentType(request) ;
+ boolean mustHaveQueryParam = true ;
+ if ( ct != null ) {
+ String incoming = ct.getContentType() ;
+
+ if ( matchContentType(ctSPARQLQuery, ct) ) {
+ mustHaveQueryParam = false ;
+ // Drop through.
+ } else if ( matchContentType(ctHTMLForm, ct)) {
+ // Nothing specific to do
+ }
+ else
+ ServletOps.error(HttpSC.UNSUPPORTED_MEDIA_TYPE_415, "Unsupported: " + incoming) ;
+ }
+
+ // GET/POST of a form at this point.
+
+ if ( mustHaveQueryParam ) {
+ int N = countParamOccurences(request, paramQuery) ;
+
+ if ( N == 0 )
+ ServletOps.errorBadRequest("SPARQL Query: No 'query=' parameter") ;
+ if ( N > 1 )
+ ServletOps.errorBadRequest("SPARQL Query: Multiple 'query=' parameters") ;
+
+ // application/sparql-query does not use a query param.
+ String queryStr = request.getParameter(HttpNames.paramQuery) ;
+
+ if ( queryStr == null )
+ ServletOps.errorBadRequest("SPARQL Query: No query specified (no 'query=' found)") ;
+ if ( queryStr.isEmpty() )
+ ServletOps.errorBadRequest("SPARQL Query: Empty query string") ;
+ }
+
+ if ( params != null ) {
+ Enumeration<String> en = request.getParameterNames() ;
+ for (; en.hasMoreElements();) {
+ String name = en.nextElement() ;
+ if ( !params.contains(name) )
+ ServletOps.warning(action, "SPARQL Query: Unrecognize request parameter (ignored): " + name) ;
+ }
+ }
+ }
+
+ private void executeWithParameter(HttpAction action) {
+ String queryString = action.request.getParameter(paramQuery) ;
+ execute(queryString, action) ;
+ }
+
+ private void executeBody(HttpAction action) {
+ String queryString = null ;
+ try {
+ InputStream input = action.request.getInputStream() ;
+ queryString = IO.readWholeFileAsUTF8(input) ;
+ } catch (IOException ex) {
+ ServletOps.errorOccurred(ex) ;
+ }
+ execute(queryString, action) ;
+ }
+
+ private void execute(String queryString, HttpAction action) {
+ String queryStringLog = ServletOps.formatForLog(queryString) ;
+ if ( action.verbose )
+ action.log.info(format("[%d] Query = \n%s", action.id, queryString)) ;
+ else
+ action.log.info(format("[%d] Query = %s", action.id, queryStringLog)) ;
+
+ Query query = null ;
+ try {
+ // NB syntax is ARQ (a superset of SPARQL)
+ query = QueryFactory.create(queryString, QueryParseBase, Syntax.syntaxARQ) ;
+ queryStringLog = formatForLog(query) ;
+ validateQuery(action, query) ;
+ } catch (ActionErrorException ex) {
+ throw ex ;
+ } catch (QueryParseException ex) {
+ ServletOps.errorBadRequest("Parse error: \n" + queryString + "\n\r" + messageForQueryException(ex)) ;
+ }
+ // Should not happen.
+ catch (QueryException ex) {
+ ServletOps.errorBadRequest("Error: \n" + queryString + "\n\r" + ex.getMessage()) ;
+ }
+
+ // Assumes finished whole thing by end of sendResult.
+ try {
+ action.beginRead() ;
+ Dataset dataset = decideDataset(action, query, queryStringLog) ;
+ try ( QueryExecution qExec = createQueryExecution(query, dataset) ; ) {
+ SPARQLResult result = executeQuery(action, qExec, query, queryStringLog) ;
+ // Deals with exceptions itself.
+ sendResults(action, result, query.getPrologue()) ;
+ }
+ }
+ catch (QueryParseException ex) {
+ // Late stage static error (e.g. bad fixed Lucene query string).
+ ServletOps.errorBadRequest("Query parse error: \n" + queryString + "\n\r" + messageForQueryException(ex)) ;
+ }
+ catch (QueryCancelledException ex) {
+ // Additional counter information.
+ incCounter(action.getEndpoint().getCounters(), QueryTimeouts) ;
+ throw ex ;
+ } finally { action.endRead() ; }
+ }
+
+ /**
+ * Check the query - if unacceptable, throw ActionErrorException or call
+ * super.error
+ * @param action HTTP Action
+ * @param query SPARQL Query
+ */
+ protected abstract void validateQuery(HttpAction action, Query query) ;
+
+ /** Create the {@link QueryExecution} for this operation.
+ * @param query
+ * @param dataset
+ * @return QueryExecution
+ */
+ protected QueryExecution createQueryExecution(Query query, Dataset dataset) {
+ return QueryExecutionFactory.create(query, dataset) ;
+ }
+
+ /** Perform the {@link QueryExecution} once.
+ * @param action
+ * @param queryExecution
+ * @param query
+ * @param queryStringLog Informational string created from the initial query.
+ * @return
+ */
+ protected SPARQLResult executeQuery(HttpAction action, QueryExecution queryExecution, Query query, String queryStringLog) {
+ setAnyTimeouts(queryExecution, action) ;
+
+ if ( query.isSelectType() ) {
+ ResultSet rs = queryExecution.execSelect() ;
+
+ // Force some query execution now.
+ //
+ // If the timeout-first-row goes off, the output stream has not
+ // been started so the HTTP error code is sent.
+
+ rs.hasNext() ;
+
+ // If we wanted perfect query time cancellation, we could consume
+ // the result now
+ // to see if the timeout-end-of-query goes off.
+
+ // rs = ResultSetFactory.copyResults(rs) ;
+
+ action.log.info(format("[%d] exec/select", action.id)) ;
+ return new SPARQLResult(rs) ;
+ }
+
+ if ( query.isConstructType() ) {
+
+ MediaType rdfMediaType = AcceptList.match( DEF.pureRdfOffer, new AcceptList( WebLib.getAccept(action.getRequest())));
+
if ( ! rdfMediaType.getType().equals("*") ) {
- Model model = queryExecution.execConstruct();
- action.log.info(format("[%d] exec/construct/model", action.id));
- return new SPARQLResult(model);
+ Model model = queryExecution.execConstruct();
+ action.log.info(format("[%d] exec/construct/model", action.id));
+ return new SPARQLResult(model);
} else {
- Dataset dataset = queryExecution.execConstructDataset();
- action.log
- .info(format("[%d] exec/construct/dataset", action.id));
- return new SPARQLResult(dataset);
- }
- }
-
- if (query.isDescribeType()) {
- Model model = queryExecution.execDescribe();
- action.log.info(format("[%d] exec/describe", action.id));
- return new SPARQLResult(model);
- }
-
- if (query.isAskType()) {
- boolean b = queryExecution.execAsk();
- action.log.info(format("[%d] exec/ask", action.id));
- return new SPARQLResult(b);
- }
-
- ServletOps.errorBadRequest("Unknown query type - " + queryStringLog);
- return null;
- }
-
- private void setAnyTimeouts(QueryExecution qexec, HttpAction action) {
- // if ( !(action.getDataService().allowTimeoutOverride) )
- // return ;
-
- long desiredTimeout = Long.MAX_VALUE;
- String timeoutHeader = action.request.getHeader("Timeout");
- String timeoutParameter = action.request.getParameter("timeout");
- if (timeoutHeader != null) {
- try {
- desiredTimeout = (int) (Float.parseFloat(timeoutHeader) * 1000);
- } catch (NumberFormatException e) {
- throw new FusekiException("Timeout header must be a number", e);
- }
- } else if (timeoutParameter != null) {
- try {
- desiredTimeout = (int) (Float.parseFloat(timeoutParameter) * 1000);
- } catch (NumberFormatException e) {
- throw new FusekiException("timeout parameter must be a number",
- e);
- }
- }
-
- // desiredTimeout =
- // Math.min(action.getDataService().maximumTimeoutOverride,
- // desiredTimeout) ;
- if (desiredTimeout != Long.MAX_VALUE)
- qexec.setTimeout(desiredTimeout);
- }
-
- /**
- * Choose the dataset for this SPARQL Query request.
- *
- * @param action
- * @param query
- * @param queryStringLog
- * @return {@link Dataset}
- */
- protected abstract Dataset decideDataset(HttpAction action, Query query,
- String queryStringLog);
-
- /**
- * Ship the results to the remote caller.
- *
- * @param action
- * @param result
- * @param qPrologue
- */
- protected void sendResults(HttpAction action, SPARQLResult result,
- Prologue qPrologue) {
- if (result.isResultSet())
- ResponseResultSet.doResponseResultSet(action,
- result.getResultSet(), qPrologue);
- else if (result.isGraph()) {
- ResponseModel.doResponseModel(action, result.getModel());
- } else if (result.isBoolean())
- ResponseResultSet.doResponseResultSet(action,
- result.getBooleanResult());
- else if (result.isDataset()) {
- ResponseDataset.doResponseDataset(action, result.getDataset());
- } else
- ServletOps.errorOccurred("Unknown or invalid result type");
- }
-
- private String formatForLog(Query query) {
- IndentedLineBuffer out = new IndentedLineBuffer();
- out.setFlatMode(true);
- query.serialize(out);
- return out.asString();
- }
-
- private String getRemoteString(String queryURI) {
- return HttpOp.execHttpGetString(queryURI);
- }
+ Dataset dataset = queryExecution.execConstructDataset();
+ action.log.info(format("[%d] exec/construct/dataset", action.id));
+ return new SPARQLResult(dataset);
+ }
+ }
+
+ if ( query.isDescribeType() ) {
+ Model model = queryExecution.execDescribe() ;
+ action.log.info(format("[%d] exec/describe", action.id)) ;
+ return new SPARQLResult(model) ;
+ }
+
+ if ( query.isAskType() ) {
+ boolean b = queryExecution.execAsk() ;
+ action.log.info(format("[%d] exec/ask", action.id)) ;
+ return new SPARQLResult(b) ;
+ }
+
+ ServletOps.errorBadRequest("Unknown query type - " + queryStringLog) ;
+ return null ;
+ }
+
+ private void setAnyTimeouts(QueryExecution qexec, HttpAction action) {
+// if ( !(action.getDataService().allowTimeoutOverride) )
+// return ;
+
+ long desiredTimeout = Long.MAX_VALUE ;
+ String timeoutHeader = action.request.getHeader("Timeout") ;
+ String timeoutParameter = action.request.getParameter("timeout") ;
+ if ( timeoutHeader != null ) {
+ try {
+ desiredTimeout = (int)(Float.parseFloat(timeoutHeader) * 1000) ;
+ } catch (NumberFormatException e) {
+ throw new FusekiException("Timeout header must be a number", e) ;
+ }
+ } else if ( timeoutParameter != null ) {
+ try {
+ desiredTimeout = (int)(Float.parseFloat(timeoutParameter) * 1000) ;
+ } catch (NumberFormatException e) {
+ throw new FusekiException("timeout parameter must be a number", e) ;
+ }
+ }
+
+// desiredTimeout = Math.min(action.getDataService().maximumTimeoutOverride, desiredTimeout) ;
+ if ( desiredTimeout != Long.MAX_VALUE )
+ qexec.setTimeout(desiredTimeout) ;
+ }
+
+ /** Choose the dataset for this SPARQL Query request.
+ * @param action
+ * @param query Query - this may be modified to remove a DatasetDescription.
+ * @param queryStringLog
+ * @return {@link Dataset}
+ */
+ protected abstract Dataset decideDataset(HttpAction action, Query query, String queryStringLog) ;
+
+ /** Ship the results to the remote caller.
+ * @param action
+ * @param result
+ * @param qPrologue
+ */
+ protected void sendResults(HttpAction action, SPARQLResult result, Prologue qPrologue) {
+ if ( result.isResultSet() )
+ ResponseResultSet.doResponseResultSet(action, result.getResultSet(), qPrologue) ;
+ else if ( result.isGraph() )
+ ResponseModel.doResponseModel(action, result.getModel()) ;
+ else if ( result.isBoolean() )
+ ResponseResultSet.doResponseResultSet(action, result.getBooleanResult()) ;
+ else if ( result.isDataset() )
+ ResponseDataset.doResponseDataset(action, result.getDataset());
+ else
+ ServletOps.errorOccurred("Unknown or invalid result type") ;
+ }
+
+ private String formatForLog(Query query) {
+ IndentedLineBuffer out = new IndentedLineBuffer() ;
+ out.setFlatMode(true) ;
+ query.serialize(out) ;
+ return out.asString() ;
+ }
+
+ private String getRemoteString(String queryURI) {
+ return HttpOp.execHttpGetString(queryURI) ;
+ }
}
http://git-wip-us.apache.org/repos/asf/jena/blob/c7dedb2b/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestQuery.java
----------------------------------------------------------------------
diff --git a/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestQuery.java b/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestQuery.java
index 911d105..21f89fc 100644
--- a/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestQuery.java
+++ b/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestQuery.java
@@ -16,95 +16,137 @@
* limitations under the License.
*/
-package org.apache.jena.fuseki;
-
-import static org.apache.jena.fuseki.ServerTest.gn1;
-import static org.apache.jena.fuseki.ServerTest.model1;
-import static org.apache.jena.fuseki.ServerTest.model2;
-import static org.apache.jena.fuseki.ServerTest.serviceQuery;
-import static org.apache.jena.fuseki.ServerTest.serviceREST;
-
-import java.io.IOException;
-import java.net.HttpURLConnection;
-import java.net.URL;
-import java.util.Iterator;
-
-import org.apache.jena.atlas.junit.BaseTest;
-import org.apache.jena.graph.Triple;
-import org.apache.jena.query.DatasetAccessor;
-import org.apache.jena.query.DatasetAccessorFactory;
-import org.apache.jena.query.Query;
-import org.apache.jena.query.QueryExecution;
-import org.apache.jena.query.QueryExecutionFactory;
-import org.apache.jena.query.QueryFactory;
-import org.apache.jena.query.ResultSet;
-import org.apache.jena.query.ResultSetFormatter;
-import org.apache.jena.query.Syntax;
-import org.apache.jena.sparql.core.Quad;
-import org.apache.jena.sparql.core.Var;
-import org.apache.jena.sparql.engine.binding.Binding;
-import org.apache.jena.sparql.resultset.ResultSetCompare;
-import org.apache.jena.sparql.sse.Item;
-import org.apache.jena.sparql.sse.SSE;
-import org.apache.jena.sparql.sse.builders.BuilderResultSet;
-import org.apache.jena.sparql.util.Convert;
-import org.junit.AfterClass;
-import org.junit.Assert;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-public class TestQuery extends BaseTest
-{
- protected static ResultSet rs1 = null ;
+package org.apache.jena.fuseki ;
+
+import static org.apache.jena.fuseki.ServerTest.gn1 ;
+import static org.apache.jena.fuseki.ServerTest.gn2 ;
+import static org.apache.jena.fuseki.ServerTest.model1 ;
+import static org.apache.jena.fuseki.ServerTest.model2 ;
+import static org.apache.jena.fuseki.ServerTest.serviceQuery ;
+import static org.apache.jena.fuseki.ServerTest.serviceREST ;
+
+import java.io.IOException ;
+import java.net.HttpURLConnection ;
+import java.net.URL ;
+import java.util.Iterator ;
+
+import org.apache.jena.atlas.junit.BaseTest ;
+import org.apache.jena.graph.Node ;
+import org.apache.jena.graph.Triple ;
+import org.apache.jena.query.* ;
+import org.apache.jena.sparql.core.Quad ;
+import org.apache.jena.sparql.core.Var ;
+import org.apache.jena.sparql.engine.binding.Binding ;
+import org.apache.jena.sparql.resultset.ResultSetCompare ;
+import org.apache.jena.sparql.sse.Item ;
+import org.apache.jena.sparql.sse.SSE ;
+import org.apache.jena.sparql.sse.builders.BuilderResultSet ;
+import org.apache.jena.sparql.util.Convert ;
+import org.junit.AfterClass ;
+import org.junit.Assert ;
+import org.junit.BeforeClass ;
+import org.junit.Test ;
+
+public class TestQuery extends BaseTest {
+ protected static ResultSet rs1 = null ;
static {
Item item = SSE.parseItem("(resultset (?s ?p ?o) (row (?s <x>)(?p <p>)(?o 1)))") ;
rs1 = BuilderResultSet.build(item) ;
}
-
- @BeforeClass public static void beforeClass()
- {
+
+ @BeforeClass
+ public static void beforeClass() {
ServerTest.allocServer() ;
ServerTest.resetServer() ;
DatasetAccessor du = DatasetAccessorFactory.createHTTP(serviceREST) ;
du.putModel(model1) ;
du.putModel(gn1, model2) ;
}
-
- @AfterClass public static void afterClass()
- {
+
+ @AfterClass
+ public static void afterClass() {
DatasetAccessor du = DatasetAccessorFactory.createHTTP(serviceREST) ;
du.deleteDefault() ;
ServerTest.freeServer() ;
}
-
- @Test public void query_01()
- {
+
+ @Test
+ public void query_01() {
execQuery("SELECT * {?s ?p ?o}", 1) ;
}
-
- @Test public void query_recursive_01()
- {
- String query = "SELECT * WHERE { SERVICE <" + serviceQuery + "> { ?s ?p ?o . BIND(?o AS ?x) } }";
- try ( QueryExecution qExec = QueryExecutionFactory.sparqlService(serviceQuery, query) ) {
- ResultSet rs = qExec.execSelect();
- Var x = Var.alloc("x");
+
+ @Test
+ public void query_recursive_01() {
+ String query = "SELECT * WHERE { SERVICE <" + serviceQuery + "> { ?s ?p ?o . BIND(?o AS ?x) } }" ;
+ try (QueryExecution qExec = QueryExecutionFactory.sparqlService(serviceQuery, query)) {
+ ResultSet rs = qExec.execSelect() ;
+ Var x = Var.alloc("x") ;
while (rs.hasNext()) {
- Binding b = rs.nextBinding();
- Assert.assertNotNull(b.get(x));
+ Binding b = rs.nextBinding() ;
+ Assert.assertNotNull(b.get(x)) ;
+ }
+ }
+ }
+
+ @Test
+ public void query_with_params_01() {
+ String query = "ASK { }" ;
+ try (QueryExecution qExec = QueryExecutionFactory.sparqlService(serviceQuery + "?output=json", query)) {
+ boolean result = qExec.execAsk() ;
+ Assert.assertTrue(result) ;
+ }
+ }
+
+ @Test
+ public void request_id_header_01() throws IOException {
+ String qs = Convert.encWWWForm("ASK{}") ;
+ URL u = new URL(serviceQuery + "?query=" + qs) ;
+ HttpURLConnection conn = (HttpURLConnection)u.openConnection() ;
+ Assert.assertTrue(conn.getHeaderField("Fuseki-Request-ID") != null) ;
+ }
+
+ @Test
+ public void query_dynamic_dataset_01() {
+ DatasetAccessor du = DatasetAccessorFactory.createHTTP(serviceREST) ;
+ du.putModel(model1);
+ du.putModel(gn1, model2);
+ {
+ String query = "SELECT * { ?s ?p ?o }" ;
+ try (QueryExecution qExec = QueryExecutionFactory.sparqlService(serviceQuery + "?output=json", query)) {
+ ResultSet rs = qExec.execSelect() ;
+ Node o = rs.next().getLiteral("o").asNode() ;
+ Node n = SSE.parseNode("1") ;
+ assertEquals(n, o) ;
+ }
+ }
+ {
+
+ String query = "SELECT * FROM <" + gn1 + "> { ?s ?p ?o }" ;
+ try (QueryExecution qExec = QueryExecutionFactory.sparqlService(serviceQuery + "?output=json", query)) {
+ ResultSet rs = qExec.execSelect() ;
+ Node o = rs.next().getLiteral("o").asNode() ;
+ Node n = SSE.parseNode("2") ;
+ assertEquals(n, o) ;
}
}
}
- @Test public void query_with_params_01()
- {
- String query = "ASK { }";
- try ( QueryExecution qExec = QueryExecutionFactory.sparqlService(serviceQuery + "?output=json", query) ) {
- boolean result = qExec.execAsk();
- Assert.assertTrue(result);
+ @Test
+ public void query_dynamic_dataset_02() {
+ DatasetAccessor du = DatasetAccessorFactory.createHTTP(serviceREST) ;
+ du.putModel(model1);
+ du.putModel(gn1, model1);
+ du.putModel(gn2, model2);
+ String query = "SELECT * FROM <"+gn1+"> FROM <"+gn2+"> { ?s ?p ?o }" ;
+ try (QueryExecution qExec = QueryExecutionFactory.sparqlService(serviceQuery + "?output=json", query)) {
+ ResultSet rs = qExec.execSelect() ;
+ int n = ResultSetFormatter.consume(rs) ;
+ assertEquals(2, n) ;
}
}
- @Test public void query_construct_quad_01()
+ @Test
+ public void query_construct_quad_01()
{
String queryString = " CONSTRUCT { GRAPH <http://eg/g> {?s ?p ?oq} } WHERE {?s ?p ?oq}" ;
Query query = QueryFactory.create(queryString, Syntax.syntaxARQ);
@@ -117,7 +159,8 @@ public class TestQuery extends BaseTest
}
}
- @Test public void query_construct_01()
+ @Test
+ public void query_construct_01()
{
String query = " CONSTRUCT {?s ?p ?o} WHERE {?s ?p ?o}" ;
try ( QueryExecution qExec = QueryExecutionFactory.sparqlService(serviceQuery, query) ) {
@@ -125,27 +168,15 @@ public class TestQuery extends BaseTest
Assert.assertTrue(result.hasNext());
}
}
-
-
-
- @Test public void request_id_header_01() throws IOException
- {
- String qs = Convert.encWWWForm("ASK{}") ;
- URL u = new URL(serviceQuery+"?query="+qs);
- HttpURLConnection conn = (HttpURLConnection) u.openConnection();
- Assert.assertTrue(conn.getHeaderField("Fuseki-Request-ID") != null);
- }
- private void execQuery(String queryString, int exceptedRowCount)
- {
+ private void execQuery(String queryString, int exceptedRowCount) {
QueryExecution qExec = QueryExecutionFactory.sparqlService(serviceQuery, queryString) ;
ResultSet rs = qExec.execSelect() ;
int x = ResultSetFormatter.consume(rs) ;
assertEquals(exceptedRowCount, x) ;
}
-
- private void execQuery(String queryString, ResultSet expectedResultSet)
- {
+
+ private void execQuery(String queryString, ResultSet expectedResultSet) {
QueryExecution qExec = QueryExecutionFactory.sparqlService(serviceQuery, queryString) ;
ResultSet rs = qExec.execSelect() ;
boolean b = ResultSetCompare.equalsByTerm(rs, expectedResultSet) ;
[09/16] jena git commit: Add execConstructDadset(Dataset)
Posted by an...@apache.org.
Add execConstructDadset(Dataset)
Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/62bc52f8
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/62bc52f8
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/62bc52f8
Branch: refs/heads/JENA-491-construct-quads
Commit: 62bc52f87acd77156d18e42a541d00074c8178e3
Parents: fe19b4b
Author: Andy Seaborne <an...@apache.org>
Authored: Thu Aug 20 11:28:13 2015 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Thu Aug 20 11:28:13 2015 +0100
----------------------------------------------------------------------
.../org/apache/jena/query/QueryExecution.java | 20 +++++++++++++++++---
1 file changed, 17 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jena/blob/62bc52f8/jena-arq/src/main/java/org/apache/jena/query/QueryExecution.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/query/QueryExecution.java b/jena-arq/src/main/java/org/apache/jena/query/QueryExecution.java
index 2707675..5322ddd 100644
--- a/jena-arq/src/main/java/org/apache/jena/query/QueryExecution.java
+++ b/jena-arq/src/main/java/org/apache/jena/query/QueryExecution.java
@@ -102,15 +102,29 @@ public interface QueryExecution extends AutoCloseable
public Iterator<Triple> execConstructTriples();
/**
- * Similar to execConstructTriples(), except that constructing {@link Quad}.
+ * Execute a CONSTRUCT query, returning the results as an iterator of {@link Quad}.
+ * <p>
+ * <b>Caution:</b> This method may return duplicate Quads. This method may be useful if you only
+ * need the results for stream processing, as it can avoid having to place the results in a Model.
+ * </p>
+ * @return An iterator of Quad objects (possibly containing duplicates) generated
+ * by applying the CONSTRUCT template of the query to the bindings in the WHERE clause.
+ * </p>
+ * <p>
+ * See {@link #execConstructTriples} for usage and features.
*/
public Iterator<Quad> execConstructQuads();
- /**
- * Similar to execConstructTriples(), except that constructing {@link Dataset}.
+ /** Execute a CONSTRUCT query, putting the statements into 'dataset'.
+ * This maybe an exetended synatx query (if supported).
*/
public Dataset execConstructDataset();
+ /** Execute a CONSTRUCT query, putting the statements into 'dataset'.
+ * This maybe an exetended synatx query (if supported).
+ */
+ public Dataset execConstructDataset(Dataset dataset);
+
/** Execute a DESCRIBE query */
public Model execDescribe();
[15/16] jena git commit: Correct log message
Posted by an...@apache.org.
Correct log message
Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/f308d435
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/f308d435
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/f308d435
Branch: refs/heads/JENA-491-construct-quads
Commit: f308d43555d5c32edc90a6551851f3f0e2dcd934
Parents: 4ddf9ec
Author: Andy Seaborne <an...@apache.org>
Authored: Thu Aug 20 11:32:49 2015 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Thu Aug 20 11:32:49 2015 +0100
----------------------------------------------------------------------
.../main/java/org/apache/jena/fuseki/servlets/SPARQL_Query.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jena/blob/f308d435/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Query.java
----------------------------------------------------------------------
diff --git a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Query.java b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Query.java
index 8e81426..c43b257 100644
--- a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Query.java
+++ b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Query.java
@@ -316,7 +316,7 @@ public abstract class SPARQL_Query extends SPARQL_Protocol
if ( query.isConstructType() ) {
Dataset dataset = queryExecution.execConstructDataset();
- action.log.info(format("[%d] exec/construct/dataset", action.id));
+ action.log.info(format("[%d] exec/construct", action.id));
return new SPARQLResult(dataset);
}
[07/16] jena git commit: Reworking CONSTRUCT for quads.
Posted by an...@apache.org.
Reworking CONSTRUCT for quads.
GSOC JENA 491 final.
Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/077a4136
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/077a4136
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/077a4136
Branch: refs/heads/JENA-491-construct-quads
Commit: 077a413662c19f8ac063e236d7bdd5f652fef3cb
Parents: 3ac6a5a 602e3c0
Author: Andy Seaborne <an...@apache.org>
Authored: Thu Aug 20 09:39:26 2015 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Thu Aug 20 09:39:43 2015 +0100
----------------------------------------------------------------------
.../org/apache/jena/atlas/web/AcceptList.java | 145 ++--
.../sparql/engine/http/QueryEngineHTTP.java | 43 +-
.../main/java/org/apache/jena/fuseki/DEF.java | 17 +-
.../jena/fuseki/servlets/ResponseDataset.java | 20 +-
.../jena/fuseki/servlets/ResponseModel.java | 5 +
.../jena/fuseki/servlets/SPARQL_Query.java | 838 +++++++++----------
.../java/org/apache/jena/fuseki/TestQuery.java | 260 ++++--
7 files changed, 699 insertions(+), 629 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jena/blob/077a4136/jena-arq/src/main/java/org/apache/jena/atlas/web/AcceptList.java
----------------------------------------------------------------------
diff --cc jena-arq/src/main/java/org/apache/jena/atlas/web/AcceptList.java
index 8801016,e3eb290..1d251c8
--- a/jena-arq/src/main/java/org/apache/jena/atlas/web/AcceptList.java
+++ b/jena-arq/src/main/java/org/apache/jena/atlas/web/AcceptList.java
@@@ -54,27 -54,27 +54,24 @@@ public class AcceptLis
* @param acceptItems
*/
-- public static AcceptList create(MediaType...acceptItems)
-- {
-- AcceptList accepList = new AcceptList() ;
++ public static AcceptList create(MediaType... acceptItems) {
++ AcceptList accepList = new AcceptList();
for ( MediaType mtype : acceptItems )
-- accepList.ranges.add(new MediaRange(mtype)) ;
-- return accepList ;
-- }
++ accepList.ranges.add(new MediaRange(mtype));
++ return accepList;
++ }
/**
* Create a list of accept items from strings.
* @param acceptStrings
*/
-- public static AcceptList create(String... acceptStrings)
-- {
-- AcceptList accepList = new AcceptList() ;
-- for ( String acceptString : acceptStrings )
-- {
-- accepList.ranges.add( new MediaRange( acceptString ) );
++ public static AcceptList create(String... acceptStrings) {
++ AcceptList accepList = new AcceptList();
++ for ( String acceptString : acceptStrings ) {
++ accepList.ranges.add(new MediaRange(acceptString));
}
-- return accepList ;
++ return accepList;
}
/**
@@@ -82,26 -82,26 +79,23 @@@
* @param headerString
*/
-- public AcceptList(String headerString)
-- {
++ public AcceptList(String headerString) {
try {
-- ranges = stringToAcceptList(headerString) ;
-- } catch (Exception ex)
-- {
-- ex.printStackTrace(System.err) ;
-- Log.warn(this, "Unrecognized accept string (ignored): "+headerString) ;
-- ranges = new ArrayList<>() ;
++ ranges = stringToAcceptList(headerString);
++ }
++ catch (Exception ex) {
++ ex.printStackTrace(System.err);
++ Log.warn(this, "Unrecognized accept string (ignored): " + headerString);
++ ranges = new ArrayList<>();
}
}
--
-- private /*public*/ boolean accepts(MediaRange aItem)
-- {
-- return match(aItem) != null ;
++
++ private /* public */ boolean accepts(MediaRange aItem) {
++ return match(aItem) != null;
}
- private List<MediaRange> entries()
- public List<MediaRange> entries()
-- {
-- return Collections.unmodifiableList(ranges) ;
++ public List<MediaRange> entries() {
++ return Collections.unmodifiableList(ranges);
}
private final static MediaRangeCompare comparator = new MediaRangeCompare() ;
@@@ -119,11 -119,11 +113,9 @@@
double weight = -1 ;
int exact = -1 ;
-- for ( MediaRange acceptItem : ranges )
-- {
-- if ( acceptItem.accepts(offer) )
-- {
-- boolean newChoice = false;
++ for ( MediaRange acceptItem : ranges ) {
++ if ( acceptItem.accepts(offer) ) {
++ boolean newChoice = false;
if ( choice == null )
// First possibility.
newChoice = true ;
@@@ -134,12 -134,12 +126,11 @@@
// New possibility has same weight but better exactness.
newChoice = true ;
-- if ( newChoice )
-- {
-- choice = acceptItem ;
-- weight = acceptItem.get_q() ;
-- exact = acceptItem.subweight() ;
-- continue ;
++ if ( newChoice ) {
++ choice = acceptItem;
++ weight = acceptItem.get_q();
++ exact = acceptItem.subweight();
++ continue;
}
//if ( weight == acceptItem.get_q() && !exact &&
}
@@@ -157,19 -157,19 +148,17 @@@
* @return MediaType
*/
-- static public MediaType match(AcceptList proposalList, AcceptList offerList)
-- {
-- MediaRange cause = null ;
++ static public MediaType match(AcceptList proposalList, AcceptList offerList) {
++ MediaRange cause = null;
MediaRange choice = null ; // From the proposalList
double weight = -1 ;
int exactness = -1 ;
-- for ( MediaRange offer : offerList.entries() )
-- {
-- MediaRange m = proposalList.match(offer) ;
++ for ( MediaRange offer : offerList.entries() ) {
++ MediaRange m = proposalList.match(offer);
if ( m == null )
-- continue ;
-- boolean newChoice = false ;
++ continue;
++ boolean newChoice = false;
if ( choice == null )
newChoice = true ;
@@@ -185,51 -185,51 +174,43 @@@
}
}
--
if ( choice == null )
return null ;
return new MediaType(choice);
}
-- public MediaRange first()
-- {
-- MediaRange choice = null ;
-- for ( MediaRange acceptItem : ranges )
-- {
++ public MediaRange first() {
++ MediaRange choice = null;
++ for ( MediaRange acceptItem : ranges ) {
if ( choice != null && choice.get_q() >= acceptItem.get_q() )
-- continue ;
-- choice = acceptItem ;
++ continue;
++ choice = acceptItem;
}
-- return choice ;
++ return choice;
}
--
++
@Override
public String toString() { return ranges.toString() ; }
-- private static List<MediaRange> stringToAcceptList(String s)
-- {
-- List<MediaRange> ranges = new ArrayList<>() ;
++ private static List<MediaRange> stringToAcceptList(String s) {
++ List<MediaRange> ranges = new ArrayList<>();
if ( s == null )
-- return ranges ;
++ return ranges;
-- String[] x = s.split(",") ;
-- for ( String aX : x )
-- {
-- if ( aX.equals( "" ) )
-- {
++ String[] x = s.split(",");
++ for ( String aX : x ) {
++ if ( aX.equals("") ) {
continue;
}
-- MediaRange mType = new MediaRange( aX );
-- ranges.add( mType );
++ MediaRange mType = new MediaRange(aX);
++ ranges.add(mType);
}
-- return ranges ;
++ return ranges;
}
-- private static class MediaRangeCompare implements Comparator<MediaRange>
-- {
++ private static class MediaRangeCompare implements Comparator<MediaRange> {
@Override
-- public int compare(MediaRange mType1, MediaRange mType2)
-- {
++ public int compare(MediaRange mType1, MediaRange mType2) {
int r = Double.compare(mType1.get_q(), mType2.get_q()) ;
if ( r == 0 )
@@@ -238,8 -238,8 +219,7 @@@
if ( r == 0 )
r = subCompare(mType1.getSubType(), mType2.getSubType()) ;
--// if ( r == 0 )
--// {
++// if ( r == 0 ) {
// // This reverses the input order so that the rightmost elements is the
// // greatest and hence is the first mentioned in the accept range.
//
@@@ -254,19 -254,19 +234,18 @@@
return r ;
}
-- public int subCompare(String a, String b)
-- {
++ public int subCompare(String a, String b) {
if ( a == null )
-- return 1 ;
++ return 1;
if ( b == null )
-- return -1 ;
++ return -1;
if ( a.equals("*") && b.equals("*") )
-- return 0 ;
++ return 0;
if ( a.equals("*") )
-- return -1 ;
++ return -1;
if ( b.equals("*") )
-- return 1 ;
-- return 0 ;
++ return 1;
++ return 0;
}
}
}
http://git-wip-us.apache.org/repos/asf/jena/blob/077a4136/jena-arq/src/main/java/org/apache/jena/sparql/engine/http/QueryEngineHTTP.java
----------------------------------------------------------------------
diff --cc jena-arq/src/main/java/org/apache/jena/sparql/engine/http/QueryEngineHTTP.java
index cab831f,abe4d1f..2fa9602
--- a/jena-arq/src/main/java/org/apache/jena/sparql/engine/http/QueryEngineHTTP.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/engine/http/QueryEngineHTTP.java
@@@ -85,6 -87,9 +87,10 @@@ public class QueryEngineHTTP implement
private String selectContentType = defaultSelectHeader();
private String askContentType = defaultAskHeader();
private String modelContentType = defaultConstructHeader();
+ private String datasetContentType = WebContent.defaultDatasetAcceptHeader;
+
- private String httpResponseContentType;
++ // Received content type
++ private String httpResponseContentType = null ;
/**
* Supported content types for SELECT queries
*/
@@@ -332,7 -337,11 +338,12 @@@
this.authenticator = authenticator;
}
- @Override
++ /** The Content-Type response header received (null before the remote operation is attempted). */
+ public String getHttpResponseContentType() {
+ return httpResponseContentType;
+ }
+
+ @Override
public ResultSet execSelect() {
checkNotClosed() ;
ResultSet rs = execResultSetInner() ;
@@@ -355,9 -364,10 +366,10 @@@
retainedConnection = in; // This will be closed on close()
retainedClient = httpQuery.shouldShutdownClient() ? httpQuery.getClient() : null;
-- // Don't assume the endpoint actually gives back the content type we
-- // asked for
++ // Don't assume the endpoint actually gives back the
++ // content type we asked for
String actualContentType = httpQuery.getContentType();
+ httpResponseContentType = actualContentType;
// If the server fails to return a Content-Type then we will assume
// the server returned the type we asked for
@@@ -399,7 -409,20 +411,14 @@@
@Override
public Dataset execConstructDataset(){
- return null;
-
- DatasetGraph graph = DatasetGraphFactory.createMem();
-
+ checkNotClosed() ;
- try
- {
- execConstructQuads().forEachRemaining(graph::add);
- }
- finally
- {
++ DatasetGraph dataset = DatasetGraphFactory.createMem();
++ try {
++ execConstructQuads().forEachRemaining(dataset::add);
++ } finally {
+ this.close();
+ }
- return DatasetFactory.create(graph);
-
++ return DatasetFactory.create(dataset);
}
@Override
http://git-wip-us.apache.org/repos/asf/jena/blob/077a4136/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/ResponseDataset.java
----------------------------------------------------------------------
diff --cc jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/ResponseDataset.java
index e12493d,5242f4b..1464b99
--- a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/ResponseDataset.java
+++ b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/ResponseDataset.java
@@@ -18,7 -18,15 +18,8 @@@
package org.apache.jena.fuseki.servlets;
--import static org.apache.jena.riot.WebContent.charsetUTF8;
-import static org.apache.jena.riot.WebContent.contentTypeNQuads;
-import static org.apache.jena.riot.WebContent.contentTypeTriG;
-import static org.apache.jena.riot.WebContent.contentTypeJSONLD;
-import static org.apache.jena.riot.WebContent.contentTypeNTriples;
-import static org.apache.jena.riot.WebContent.contentTypeRDFJSON;
-import static org.apache.jena.riot.WebContent.contentTypeRDFXML;
-import static org.apache.jena.riot.WebContent.contentTypeTurtle;
++import static org.apache.jena.riot.WebContent.* ;
+
import java.util.HashMap;
import java.util.Map;
@@@ -41,17 -48,31 +42,28 @@@ import org.apache.jena.web.HttpSC
public class ResponseDataset
{
// Short names for "output="
- private static final String contentOutputTriG = "trig" ;
- private static final String contentOutputNQuads = "n-quads" ;
+ private static final String contentOutputJSONLD = "json-ld" ;
+ private static final String contentOutputJSONRDF = "json-rdf" ;
+ private static final String contentOutputJSON = "json" ;
+ private static final String contentOutputXML = "xml" ;
+ private static final String contentOutputText = "text" ;
+ private static final String contentOutputTTL = "ttl" ;
+ private static final String contentOutputNT = "nt" ;
-
+ private static final String contentOutputTriG = "trig" ;
+ private static final String contentOutputNQuads = "n-quads" ;
-
public static Map<String,String> shortNamesModel = new HashMap<String, String>() ;
static {
--
// Some short names. keys are lowercase.
--
- ResponseOps.put(shortNamesModel, contentOutputNQuads, contentTypeNQuads) ;
- ResponseOps.put(shortNamesModel, contentOutputTriG, contentTypeTriG) ;
+ ResponseOps.put(shortNamesModel, contentOutputJSONLD, contentTypeJSONLD) ;
+ ResponseOps.put(shortNamesModel, contentOutputJSONRDF, contentTypeRDFJSON) ;
+ ResponseOps.put(shortNamesModel, contentOutputJSON, contentTypeJSONLD) ;
+ ResponseOps.put(shortNamesModel, contentOutputXML, contentTypeRDFXML) ;
+ ResponseOps.put(shortNamesModel, contentOutputText, contentTypeTurtle) ;
+ ResponseOps.put(shortNamesModel, contentOutputTTL, contentTypeTurtle) ;
+ ResponseOps.put(shortNamesModel, contentOutputNT, contentTypeNTriples) ;
+ ResponseOps.put(shortNamesModel, contentOutputNQuads, WebContent.contentTypeNQuads) ;
+ ResponseOps.put(shortNamesModel, contentOutputTriG, WebContent.contentTypeTriG) ;
}
public static void doResponseDataset(HttpAction action, Dataset dataset)
http://git-wip-us.apache.org/repos/asf/jena/blob/077a4136/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/ResponseModel.java
----------------------------------------------------------------------
diff --cc jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/ResponseModel.java
index 68cf016,0000000..e46fbe6
mode 100644,000000..100644
--- a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/ResponseModel.java
+++ b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/ResponseModel.java
@@@ -1,135 -1,0 +1,140 @@@
+/*
+ * 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.jena.fuseki.servlets;
+
+import java.util.HashMap ;
+import java.util.Map ;
+
+import javax.servlet.ServletOutputStream ;
+import javax.servlet.http.HttpServletRequest ;
+import javax.servlet.http.HttpServletResponse ;
+
+import org.apache.jena.atlas.web.MediaType ;
+import org.apache.jena.fuseki.DEF ;
+import org.apache.jena.fuseki.Fuseki ;
+import org.apache.jena.fuseki.conneg.ConNeg ;
+import org.apache.jena.fuseki.conneg.WebLib ;
+import org.apache.jena.rdf.model.Model ;
+import org.apache.jena.riot.Lang ;
+import org.apache.jena.riot.RDFDataMgr ;
+import org.apache.jena.riot.RDFLanguages ;
+import static org.apache.jena.riot.WebContent.* ;
+import org.apache.jena.web.HttpSC ;
+
++// REPLACED by RssponseDataset
++// Kept here in case we need to revert it (Aug 2015)
++// Delete after release of Fusek 2.3.1 or earlier if specific confirmation
++// the new code is OK.
++
+public class ResponseModel
+{
+ // Short names for "output="
+ private static final String contentOutputJSONLD = "json-ld" ;
+ private static final String contentOutputJSONRDF = "json-rdf" ;
+ private static final String contentOutputJSON = "json" ;
+ private static final String contentOutputXML = "xml" ;
+ private static final String contentOutputText = "text" ;
+ private static final String contentOutputTTL = "ttl" ;
+ private static final String contentOutputNT = "nt" ;
+
+ public static Map<String,String> shortNamesModel = new HashMap<String, String>() ;
+ static {
+
+ // Some short names. keys are lowercase.
+ ResponseOps.put(shortNamesModel, contentOutputJSONLD, contentTypeJSONLD) ;
+ ResponseOps.put(shortNamesModel, contentOutputJSONRDF, contentTypeRDFJSON) ;
+ ResponseOps.put(shortNamesModel, contentOutputJSON, contentTypeJSONLD) ;
+ ResponseOps.put(shortNamesModel, contentOutputXML, contentTypeRDFXML) ;
+ ResponseOps.put(shortNamesModel, contentOutputText, contentTypeTurtle) ;
+ ResponseOps.put(shortNamesModel, contentOutputTTL, contentTypeTurtle) ;
+ ResponseOps.put(shortNamesModel, contentOutputNT, contentTypeNTriples) ;
+ }
+
+ public static void doResponseModel(HttpAction action, Model model)
+ {
+ HttpServletRequest request = action.request ;
+ HttpServletResponse response = action.response ;
+
+ String mimeType = null ; // Header request type
+
+ // TODO Use MediaType throughout.
+ MediaType i = ConNeg.chooseContentType(request, DEF.rdfOffer, DEF.acceptRDFXML) ;
+ if ( i != null )
+ mimeType = i.getContentType() ;
+
+ String outputField = ResponseOps.paramOutput(request, shortNamesModel) ;
+ if ( outputField != null )
+ mimeType = outputField ;
+
+ String writerMimeType = mimeType ;
+
+ if ( mimeType == null )
+ {
+ Fuseki.actionLog.warn("Can't find MIME type for response") ;
+ String x = WebLib.getAccept(request) ;
+ String msg ;
+ if ( x == null )
+ msg = "No Accept: header" ;
+ else
+ msg = "Accept: "+x+" : Not understood" ;
+ ServletOps.error(HttpSC.NOT_ACCEPTABLE_406, msg) ;
+ }
+
+ String contentType = mimeType ;
+ String charset = charsetUTF8 ;
+
+ String forceAccept = ResponseOps.paramForceAccept(request) ;
+ if ( forceAccept != null )
+ {
+ contentType = forceAccept ;
+ charset = charsetUTF8 ;
+ }
+
+ Lang lang = RDFLanguages.contentTypeToLang(contentType) ;
+ if ( lang == null )
+ ServletOps.errorBadRequest("Can't determine output content type: "+contentType) ;
+
+// if ( rdfw instanceof RDFXMLWriterI )
+// rdfw.setProperty("showXmlDeclaration", "true") ;
+
+ // // Write locally to check it's possible.
+ // // Time/space tradeoff.
+ // try {
+ // OutputStream out = new NullOutputStream() ;
+ // RDFDataMgr.write(out, model, lang) ;
+ // IO.flush(out) ;
+ // } catch (JenaException ex)
+ // {
+ // SPARQL_ServletBase.errorOccurred(ex) ;
+ // }
+
+ try {
+ ResponseResultSet.setHttpResponse(action, contentType, charset) ;
+ response.setStatus(HttpSC.OK_200) ;
+ ServletOutputStream out = response.getOutputStream() ;
+ RDFDataMgr.write(out, model, lang) ;
+ out.flush() ;
+ }
+ catch (Exception ex) {
+ action.log.info("Exception while writing the response model: "+ex.getMessage(), ex) ;
+ ServletOps.errorOccurred("Exception while writing the response model: "+ex.getMessage(), ex) ;
+ }
+ }
+}
+
http://git-wip-us.apache.org/repos/asf/jena/blob/077a4136/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestQuery.java
----------------------------------------------------------------------
diff --cc jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestQuery.java
index 911d105,5a57da3..1c496f0
--- a/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestQuery.java
+++ b/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestQuery.java
@@@ -126,18 -187,47 +187,46 @@@ public class TestQuery extends BaseTes
}
}
-
+ @Test
+ public void query_construct_02()
+ {
+ String query = " CONSTRUCT {?s ?p ?o} WHERE {?s ?p ?o}" ;
+ try ( QueryExecution qExec = QueryExecutionFactory.sparqlService(serviceQuery, query) ) {
+ Model result = qExec.execConstruct();
+ assertEquals(1, result.size());
+ }
+ }
- @Test public void request_id_header_01() throws IOException
+ @Test
+ public void query_construct_conneg()
{
- String qs = Convert.encWWWForm("ASK{}") ;
- URL u = new URL(serviceQuery+"?query="+qs);
- HttpURLConnection conn = (HttpURLConnection) u.openConnection();
- Assert.assertTrue(conn.getHeaderField("Fuseki-Request-ID") != null);
+ String query = " CONSTRUCT {?s ?p ?o} WHERE {?s ?p ?o}" ;
+ for (MediaType type: DEF.rdfOffer.entries()){
+ String contentType = type.toHeaderString();
+ try ( QueryEngineHTTP qExec = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(serviceQuery, query) ) {
+ qExec.setModelContentType(initConstructContentTypes( contentType ) );
+ qExec.execConstruct();
+ assertEquals( contentType , qExec.getHttpResponseContentType());
+ }
+ }
}
-
- private void execQuery(String queryString, int exceptedRowCount)
+
+ @Test
+ public void query_construct_quad_conneg()
{
+ String queryString = " CONSTRUCT { GRAPH ?g {?s ?p ?o} } WHERE { GRAPH ?g {?s ?p ?o}}" ;
+ Query query = QueryFactory.create(queryString, Syntax.syntaxARQ);
+ for (MediaType type: DEF.quadsOffer.entries()){
+ String contentType = type.toHeaderString();
+ try ( QueryEngineHTTP qExec = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(serviceQuery, query) ) {
+ qExec.setDatasetContentType(initConstructContentTypes( contentType ) );
+ qExec.execConstructQuads();
+ assertEquals( contentType , qExec.getHttpResponseContentType());
+ }
+ }
+ }
-
+
+ private void execQuery(String queryString, int exceptedRowCount) {
QueryExecution qExec = QueryExecutionFactory.sparqlService(serviceQuery, queryString) ;
ResultSet rs = qExec.execSelect() ;
int x = ResultSetFormatter.consume(rs) ;
[06/16] jena git commit: JENA-491 Fuseki Support: Hack on
QueryEngineHTTP, so that we can test the conneg of Construct Quad.
Posted by an...@apache.org.
JENA-491 Fuseki Support: Hack on QueryEngineHTTP, so that we can test
the conneg of Construct Quad.
Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/602e3c02
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/602e3c02
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/602e3c02
Branch: refs/heads/JENA-491-construct-quads
Commit: 602e3c02779366ef9c2654aaf6bb0f1159801012
Parents: 75a7a77
Author: confidencesun <co...@gmail.com>
Authored: Wed Aug 19 21:55:56 2015 +0800
Committer: confidencesun <co...@gmail.com>
Committed: Wed Aug 19 21:55:56 2015 +0800
----------------------------------------------------------------------
.../org/apache/jena/atlas/web/AcceptList.java | 2 +-
.../sparql/engine/http/QueryEngineHTTP.java | 26 +++++++++-
.../java/org/apache/jena/fuseki/TestQuery.java | 52 ++++++++++++++++++++
3 files changed, 77 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jena/blob/602e3c02/jena-arq/src/main/java/org/apache/jena/atlas/web/AcceptList.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/atlas/web/AcceptList.java b/jena-arq/src/main/java/org/apache/jena/atlas/web/AcceptList.java
index 8801016..e3eb290 100644
--- a/jena-arq/src/main/java/org/apache/jena/atlas/web/AcceptList.java
+++ b/jena-arq/src/main/java/org/apache/jena/atlas/web/AcceptList.java
@@ -99,7 +99,7 @@ public class AcceptList
return match(aItem) != null ;
}
- private List<MediaRange> entries()
+ public List<MediaRange> entries()
{
return Collections.unmodifiableList(ranges) ;
}
http://git-wip-us.apache.org/repos/asf/jena/blob/602e3c02/jena-arq/src/main/java/org/apache/jena/sparql/engine/http/QueryEngineHTTP.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/engine/http/QueryEngineHTTP.java b/jena-arq/src/main/java/org/apache/jena/sparql/engine/http/QueryEngineHTTP.java
index 84c2c10..abe4d1f 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/engine/http/QueryEngineHTTP.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/engine/http/QueryEngineHTTP.java
@@ -87,6 +87,9 @@ public class QueryEngineHTTP implements QueryExecution {
private String selectContentType = defaultSelectHeader();
private String askContentType = defaultAskHeader();
private String modelContentType = defaultConstructHeader();
+ private String datasetContentType = WebContent.defaultDatasetAcceptHeader;
+
+ private String httpResponseContentType;
/**
* Supported content types for SELECT queries
*/
@@ -334,7 +337,11 @@ public class QueryEngineHTTP implements QueryExecution {
this.authenticator = authenticator;
}
- @Override
+ public String getHttpResponseContentType() {
+ return httpResponseContentType;
+ }
+
+ @Override
public ResultSet execSelect() {
checkNotClosed() ;
ResultSet rs = execResultSetInner() ;
@@ -360,6 +367,7 @@ public class QueryEngineHTTP implements QueryExecution {
// Don't assume the endpoint actually gives back the content type we
// asked for
String actualContentType = httpQuery.getContentType();
+ httpResponseContentType = actualContentType;
// If the server fails to return a Content-Type then we will assume
// the server returned the type we asked for
@@ -441,6 +449,7 @@ public class QueryEngineHTTP implements QueryExecution {
// Don't assume the endpoint actually gives back the content type we
// asked for
String actualContentType = httpQuery.getContentType();
+ httpResponseContentType = actualContentType;
// If the server fails to return a Content-Type then we will assume
// the server returned the type we asked for
@@ -468,6 +477,7 @@ public class QueryEngineHTTP implements QueryExecution {
// Don't assume the endpoint actually gives back the content type we
// asked for
String actualContentType = httpQuery.getContentType();
+ httpResponseContentType = actualContentType;
// If the server fails to return a Content-Type then we will assume
// the server returned the type we asked for
@@ -488,12 +498,13 @@ public class QueryEngineHTTP implements QueryExecution {
private Iterator<Quad> execQuads() {
checkNotClosed() ;
HttpQuery httpQuery = makeHttpQuery();
- httpQuery.setAccept(WebContent.defaultDatasetAcceptHeader);
+ httpQuery.setAccept(datasetContentType);
InputStream in = httpQuery.exec();
// Don't assume the endpoint actually gives back the content type we
// asked for
String actualContentType = httpQuery.getContentType();
+ httpResponseContentType = actualContentType;
// If the server fails to return a Content-Type then we will assume
// the server returned the type we asked for
@@ -520,6 +531,7 @@ public class QueryEngineHTTP implements QueryExecution {
// Don't assume the endpoint actually gives back the content type we
// asked for
String actualContentType = httpQuery.getContentType();
+ httpResponseContentType = actualContentType;
// If the server fails to return a Content-Type then we will assume
// the server returned the type we asked for
@@ -795,6 +807,16 @@ public class QueryEngineHTTP implements QueryExecution {
modelContentType = contentType;
}
+ public void setDatasetContentType(String contentType) {
+ // Check that this is a valid setting
+ Lang lang = RDFLanguages.contentTypeToLang(contentType);
+ if (lang == null)
+ throw new IllegalArgumentException("Given Content Type '" + contentType + "' is not supported by RIOT");
+ if (!RDFLanguages.isQuads(lang))
+ throw new IllegalArgumentException("Given Content Type '" + contentType + "' is not a RDF Dataset format");
+ datasetContentType = contentType;
+ }
+
private static final String selectContentTypeHeader = initSelectContentTypes() ;
public static String defaultSelectHeader() {
http://git-wip-us.apache.org/repos/asf/jena/blob/602e3c02/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestQuery.java
----------------------------------------------------------------------
diff --git a/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestQuery.java b/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestQuery.java
index e721d9d..5a57da3 100644
--- a/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestQuery.java
+++ b/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestQuery.java
@@ -31,18 +31,22 @@ import java.net.URL ;
import java.util.Iterator ;
import org.apache.jena.atlas.junit.BaseTest ;
+import org.apache.jena.atlas.logging.Log;
+import org.apache.jena.atlas.web.MediaType;
import org.apache.jena.graph.Node ;
import org.apache.jena.graph.Triple ;
import org.apache.jena.query.* ;
import org.apache.jena.sparql.core.Quad ;
import org.apache.jena.sparql.core.Var ;
import org.apache.jena.sparql.engine.binding.Binding ;
+import org.apache.jena.sparql.engine.http.QueryEngineHTTP ;
import org.apache.jena.sparql.resultset.ResultSetCompare ;
import org.apache.jena.sparql.sse.Item ;
import org.apache.jena.sparql.sse.SSE ;
import org.apache.jena.sparql.sse.builders.BuilderResultSet ;
import org.apache.jena.sparql.util.Convert ;
import org.apache.jena.rdf.model.*;
+import org.apache.jena.riot.WebContent;
import org.junit.AfterClass ;
import org.junit.Assert ;
import org.junit.BeforeClass ;
@@ -192,6 +196,36 @@ public class TestQuery extends BaseTest {
assertEquals(1, result.size());
}
}
+
+ @Test
+ public void query_construct_conneg()
+ {
+ String query = " CONSTRUCT {?s ?p ?o} WHERE {?s ?p ?o}" ;
+ for (MediaType type: DEF.rdfOffer.entries()){
+ String contentType = type.toHeaderString();
+ try ( QueryEngineHTTP qExec = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(serviceQuery, query) ) {
+ qExec.setModelContentType(initConstructContentTypes( contentType ) );
+ qExec.execConstruct();
+ assertEquals( contentType , qExec.getHttpResponseContentType());
+ }
+ }
+ }
+
+ @Test
+ public void query_construct_quad_conneg()
+ {
+ String queryString = " CONSTRUCT { GRAPH ?g {?s ?p ?o} } WHERE { GRAPH ?g {?s ?p ?o}}" ;
+ Query query = QueryFactory.create(queryString, Syntax.syntaxARQ);
+ for (MediaType type: DEF.quadsOffer.entries()){
+ String contentType = type.toHeaderString();
+ try ( QueryEngineHTTP qExec = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(serviceQuery, query) ) {
+ qExec.setDatasetContentType(initConstructContentTypes( contentType ) );
+ qExec.execConstructQuads();
+ assertEquals( contentType , qExec.getHttpResponseContentType());
+ }
+ }
+ }
+
private void execQuery(String queryString, int exceptedRowCount) {
QueryExecution qExec = QueryExecutionFactory.sparqlService(serviceQuery, queryString) ;
@@ -206,4 +240,22 @@ public class TestQuery extends BaseTest {
boolean b = ResultSetCompare.equalsByTerm(rs, expectedResultSet) ;
assertTrue("Result sets different", b) ;
}
+
+ private static String initConstructContentTypes(String... contentTypes) {
+ // Or use WebContent.defaultGraphAcceptHeader which is slightly
+ // narrower. Here, we have a tuned setting for SPARQL operations.
+ StringBuilder sBuff = new StringBuilder() ;
+ for (int i=0;i<contentTypes.length;i++ ){
+ accumulateContentTypeString(sBuff, contentTypes[i], 1- i*0.1);
+ }
+ return sBuff.toString();
+ }
+
+ private static void accumulateContentTypeString(StringBuilder sBuff, String str, double v) {
+ if ( sBuff.length() != 0 )
+ sBuff.append(", ") ;
+ sBuff.append(str) ;
+ if ( v < 1 )
+ sBuff.append(";q=").append(v) ;
+ }
}
[03/16] jena git commit: JENA-491 Fuseki Support: Add support of
exeConstructDataset() of QueryEngineHTTP
Posted by an...@apache.org.
JENA-491 Fuseki Support: Add support of exeConstructDataset() of
QueryEngineHTTP
Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/2bc9fe62
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/2bc9fe62
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/2bc9fe62
Branch: refs/heads/JENA-491-construct-quads
Commit: 2bc9fe621fbeede59885aada83ae361747513b8e
Parents: 5939a35
Author: confidencesun <co...@gmail.com>
Authored: Mon Aug 17 21:45:05 2015 +0800
Committer: confidencesun <co...@gmail.com>
Committed: Mon Aug 17 21:45:05 2015 +0800
----------------------------------------------------------------------
.../jena/sparql/engine/http/QueryEngineHTTP.java | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jena/blob/2bc9fe62/jena-arq/src/main/java/org/apache/jena/sparql/engine/http/QueryEngineHTTP.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/engine/http/QueryEngineHTTP.java b/jena-arq/src/main/java/org/apache/jena/sparql/engine/http/QueryEngineHTTP.java
index cab831f..84c2c10 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/engine/http/QueryEngineHTTP.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/engine/http/QueryEngineHTTP.java
@@ -36,6 +36,8 @@ import org.apache.jena.rdf.model.Model ;
import org.apache.jena.riot.* ;
import org.apache.jena.riot.web.HttpOp ;
import org.apache.jena.sparql.ARQException ;
+import org.apache.jena.sparql.core.DatasetGraph;
+import org.apache.jena.sparql.core.DatasetGraphFactory;
import org.apache.jena.sparql.core.Quad;
import org.apache.jena.sparql.engine.ResultSetCheckCondition ;
import org.apache.jena.sparql.graph.GraphFactory ;
@@ -399,7 +401,20 @@ public class QueryEngineHTTP implements QueryExecution {
@Override
public Dataset execConstructDataset(){
- return null;
+
+ DatasetGraph graph = DatasetGraphFactory.createMem();
+
+ checkNotClosed() ;
+ try
+ {
+ execConstructQuads().forEachRemaining(graph::add);
+ }
+ finally
+ {
+ this.close();
+ }
+ return DatasetFactory.create(graph);
+
}
@Override
[10/16] jena git commit: Use RDFDataMgr as core parser step.
Posted by an...@apache.org.
Use RDFDataMgr as core parser step.
Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/060248b7
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/060248b7
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/060248b7
Branch: refs/heads/JENA-491-construct-quads
Commit: 060248b790c6a78bcd0df5bab66f0fbf8b95b77e
Parents: 62bc52f
Author: Andy Seaborne <an...@apache.org>
Authored: Thu Aug 20 11:30:31 2015 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Thu Aug 20 11:30:31 2015 +0100
----------------------------------------------------------------------
jena-arq/src/main/java/org/apache/jena/riot/RiotReader.java | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jena/blob/060248b7/jena-arq/src/main/java/org/apache/jena/riot/RiotReader.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/riot/RiotReader.java b/jena-arq/src/main/java/org/apache/jena/riot/RiotReader.java
index 67b9384..05892bb 100644
--- a/jena-arq/src/main/java/org/apache/jena/riot/RiotReader.java
+++ b/jena-arq/src/main/java/org/apache/jena/riot/RiotReader.java
@@ -113,9 +113,8 @@ public class RiotReader
* @param dest Where to send the triples from the parser.
*/
public static void parse(InputStream in, Lang lang, String baseIRI, StreamRDF dest)
- {
- LangRIOT parser = RiotReader.createParser(in, lang, baseIRI, dest) ;
- parser.parse() ;
+ {
+ RDFDataMgr.parse(dest, in, baseIRI, lang);
}
// -------- Parsers
[14/16] jena git commit: Remove uncomments.
Posted by an...@apache.org.
Remove uncomments.
Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/4ddf9ec3
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/4ddf9ec3
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/4ddf9ec3
Branch: refs/heads/JENA-491-construct-quads
Commit: 4ddf9ec3247b8792a0024d72c76c3a1af45473f1
Parents: 1555126
Author: Andy Seaborne <an...@apache.org>
Authored: Thu Aug 20 11:32:36 2015 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Thu Aug 20 11:32:36 2015 +0100
----------------------------------------------------------------------
.../jena/fuseki/servlets/ResponseDataset.java | 22 +++++---------------
1 file changed, 5 insertions(+), 17 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jena/blob/4ddf9ec3/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/ResponseDataset.java
----------------------------------------------------------------------
diff --git a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/ResponseDataset.java b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/ResponseDataset.java
index 1464b99..f05331d 100644
--- a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/ResponseDataset.java
+++ b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/ResponseDataset.java
@@ -73,8 +73,7 @@ public class ResponseDataset
String mimeType = null ; // Header request type
- // TODO Use MediaType throughout.
- MediaType i = ConNeg.chooseContentType(request, DEF.quadsOffer, DEF.acceptNQuads) ;
+ MediaType i = ConNeg.chooseContentType(request, DEF.constructOffer, DEF.acceptTurtle) ;
if ( i != null )
mimeType = i.getContentType() ;
@@ -109,26 +108,15 @@ public class ResponseDataset
Lang lang = RDFLanguages.contentTypeToLang(contentType) ;
if ( lang == null )
ServletOps.errorBadRequest("Can't determine output content type: "+contentType) ;
-
-// if ( rdfw instanceof RDFXMLWriterI )
-// rdfw.setProperty("showXmlDeclaration", "true") ;
-
- // // Write locally to check it's possible.
- // // Time/space tradeoff.
- // try {
- // OutputStream out = new NullOutputStream() ;
- // RDFDataMgr.write(out, model, lang) ;
- // IO.flush(out) ;
- // } catch (JenaException ex)
- // {
- // SPARQL_ServletBase.errorOccurred(ex) ;
- // }
try {
ResponseResultSet.setHttpResponse(action, contentType, charset) ;
response.setStatus(HttpSC.OK_200) ;
ServletOutputStream out = response.getOutputStream() ;
- RDFDataMgr.write(out, dataset, lang) ;
+ if ( RDFLanguages.isQuads(lang) )
+ RDFDataMgr.write(out, dataset, lang) ;
+ else
+ RDFDataMgr.write(out, dataset.getDefaultModel(), lang) ;
out.flush() ;
}
catch (Exception ex) {
[16/16] jena git commit: Clean up tests.
Posted by an...@apache.org.
Clean up tests.
Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/444a6c9c
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/444a6c9c
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/444a6c9c
Branch: refs/heads/JENA-491-construct-quads
Commit: 444a6c9cbd5417e9830e4630d7b725874cda0334
Parents: f308d43
Author: Andy Seaborne <an...@apache.org>
Authored: Thu Aug 20 12:08:16 2015 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Thu Aug 20 12:08:16 2015 +0100
----------------------------------------------------------------------
.../java/org/apache/jena/fuseki/TestQuery.java | 49 +++++++-------------
1 file changed, 18 insertions(+), 31 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jena/blob/444a6c9c/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestQuery.java
----------------------------------------------------------------------
diff --git a/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestQuery.java b/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestQuery.java
index 7436e7a..dabe10d 100644
--- a/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestQuery.java
+++ b/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestQuery.java
@@ -26,6 +26,7 @@ import java.net.URL ;
import java.util.Iterator ;
import org.apache.jena.atlas.junit.BaseTest ;
+import org.apache.jena.atlas.web.AcceptList ;
import org.apache.jena.atlas.web.MediaType;
import org.apache.jena.graph.Node ;
import org.apache.jena.graph.Triple ;
@@ -118,7 +119,6 @@ public class TestQuery extends BaseTest {
}
}
{
-
String query = "SELECT * FROM <" + gn1 + "> { ?s ?p ?o }" ;
try (QueryExecution qExec = QueryExecutionFactory.sparqlService(serviceQuery + "?output=json", query)) {
ResultSet rs = qExec.execSelect() ;
@@ -190,31 +190,36 @@ public class TestQuery extends BaseTest {
}
}
+ private static final AcceptList rdfOfferTest = DEF.rdfOffer ;
+ private static final AcceptList quadsOfferTest = DEF.quadsOffer ;
+
@Test
- public void query_construct_conneg()
- {
+ public void query_construct_conneg() {
String query = " CONSTRUCT {?s ?p ?o} WHERE {?s ?p ?o}" ;
- for (MediaType type: DEF.rdfOffer.entries()){
+ for (MediaType type: rdfOfferTest.entries()){
String contentType = type.toHeaderString();
try ( QueryEngineHTTP qExec = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(serviceQuery, query) ) {
- qExec.setModelContentType(initConstructContentTypes( contentType ) );
- qExec.execConstruct();
- assertEquals( contentType , qExec.getHttpResponseContentType());
+ qExec.setModelContentType( contentType );
+ Iterator<Triple> iter = qExec.execConstructTriples();
+ assertTrue(iter.hasNext()) ;
+ String x = qExec.getHttpResponseContentType() ;
+ assertEquals( contentType , x ) ;
}
}
}
@Test
- public void query_construct_quad_conneg()
- {
+ public void query_construct_quad_conneg() {
String queryString = " CONSTRUCT { GRAPH ?g {?s ?p ?o} } WHERE { GRAPH ?g {?s ?p ?o}}" ;
Query query = QueryFactory.create(queryString, Syntax.syntaxARQ);
- for (MediaType type: DEF.quadsOffer.entries()){
+ for (MediaType type: quadsOfferTest.entries()){
String contentType = type.toHeaderString();
try ( QueryEngineHTTP qExec = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(serviceQuery, query) ) {
- qExec.setDatasetContentType(initConstructContentTypes( contentType ) );
- qExec.execConstructQuads();
- assertEquals( contentType , qExec.getHttpResponseContentType());
+ qExec.setDatasetContentType( contentType );
+ Iterator<Quad> iter = qExec.execConstructQuads();
+ assertTrue(iter.hasNext()) ;
+ String x = qExec.getHttpResponseContentType() ;
+ assertEquals( contentType , x ) ;
}
}
}
@@ -232,22 +237,4 @@ public class TestQuery extends BaseTest {
boolean b = ResultSetCompare.equalsByTerm(rs, expectedResultSet) ;
assertTrue("Result sets different", b) ;
}
-
- private static String initConstructContentTypes(String... contentTypes) {
- // Or use WebContent.defaultGraphAcceptHeader which is slightly
- // narrower. Here, we have a tuned setting for SPARQL operations.
- StringBuilder sBuff = new StringBuilder() ;
- for (int i=0;i<contentTypes.length;i++ ){
- accumulateContentTypeString(sBuff, contentTypes[i], 1- i*0.1);
- }
- return sBuff.toString();
- }
-
- private static void accumulateContentTypeString(StringBuilder sBuff, String str, double v) {
- if ( sBuff.length() != 0 )
- sBuff.append(", ") ;
- sBuff.append(str) ;
- if ( v < 1 )
- sBuff.append(";q=").append(v) ;
- }
}
[11/16] jena git commit: Add execConstructDataset(Dataset)
Posted by an...@apache.org.
Add execConstructDataset(Dataset)
Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/cfb7fda2
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/cfb7fda2
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/cfb7fda2
Branch: refs/heads/JENA-491-construct-quads
Commit: cfb7fda26273c129c2e5bf6650169a89c06c67ac
Parents: 060248b
Author: Andy Seaborne <an...@apache.org>
Authored: Thu Aug 20 11:30:47 2015 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Thu Aug 20 11:30:47 2015 +0100
----------------------------------------------------------------------
.../jena/sparql/engine/QueryExecutionBase.java | 24 ++++++++------------
1 file changed, 10 insertions(+), 14 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jena/blob/cfb7fda2/jena-arq/src/main/java/org/apache/jena/sparql/engine/QueryExecutionBase.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/engine/QueryExecutionBase.java b/jena-arq/src/main/java/org/apache/jena/sparql/engine/QueryExecutionBase.java
index 9a98b71..c04675b 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/engine/QueryExecutionBase.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/engine/QueryExecutionBase.java
@@ -47,7 +47,6 @@ import org.apache.jena.riot.system.IRIResolver;
import org.apache.jena.shared.PrefixMapping;
import org.apache.jena.sparql.ARQConstants;
import org.apache.jena.sparql.core.DatasetGraph;
-import org.apache.jena.sparql.core.DatasetGraphFactory;
import org.apache.jena.sparql.core.Quad;
import org.apache.jena.sparql.core.describe.DescribeHandler;
import org.apache.jena.sparql.core.describe.DescribeHandlerRegistry;
@@ -279,27 +278,24 @@ public class QueryExecutionBase implements QueryExecution
@Override
public Dataset execConstructDataset(){
-
- DatasetGraph graph = DatasetGraphFactory.createMem();
-
- checkNotClosed() ;
- try
- {
- execConstructQuads().forEachRemaining(graph::add);
- }
- finally
- {
+ return execConstructDataset(DatasetFactory.createMem()) ;
+ }
+
+ @Override
+ public Dataset execConstructDataset(Dataset dataset){
+ DatasetGraph dsg = dataset.asDatasetGraph() ;
+ try {
+ execConstructQuads().forEachRemaining(dsg::add);
+ } finally {
this.close();
}
- return DatasetFactory.create(graph);
-
+ return dataset ;
}
@Override
public Model execDescribe()
{ return execDescribe(GraphFactory.makeJenaDefaultModel()) ; }
-
@Override
public Model execDescribe(Model model)
{
[05/16] jena git commit: JENA-491 Fuseki Support: always use
exeConstructQuads() at the server side, and discards ResponseModel.
Posted by an...@apache.org.
JENA-491 Fuseki Support: always use exeConstructQuads() at the server
side, and discards ResponseModel.
Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/75a7a77c
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/75a7a77c
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/75a7a77c
Branch: refs/heads/JENA-491-construct-quads
Commit: 75a7a77c9a92662a88c62dca5d80f85c1c478b78
Parents: de1d1c3
Author: confidencesun <co...@gmail.com>
Authored: Tue Aug 18 23:23:09 2015 +0800
Committer: confidencesun <co...@gmail.com>
Committed: Tue Aug 18 23:23:09 2015 +0800
----------------------------------------------------------------------
.../main/java/org/apache/jena/fuseki/DEF.java | 17 ++-
.../jena/fuseki/servlets/ResponseDataset.java | 28 +++-
.../jena/fuseki/servlets/ResponseModel.java | 135 -------------------
.../jena/fuseki/servlets/SPARQL_Query.java | 25 +---
.../java/org/apache/jena/fuseki/TestQuery.java | 12 +-
5 files changed, 54 insertions(+), 163 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jena/blob/75a7a77c/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/DEF.java
----------------------------------------------------------------------
diff --git a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/DEF.java b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/DEF.java
index 953b724..46ef3be 100644
--- a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/DEF.java
+++ b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/DEF.java
@@ -31,11 +31,24 @@ public class DEF
public static final AcceptList jsonOffer = AcceptList.create(contentTypeJSON) ;
- public static final AcceptList pureRdfOffer = AcceptList.create(contentTypeTurtle,
+ public static final AcceptList constructOffer = AcceptList.create(contentTypeTurtle,
contentTypeTurtleAlt1,
contentTypeTurtleAlt2,
contentTypeNTriples,
- contentTypeRDFXML
+ contentTypeNTriplesAlt,
+ contentTypeRDFXML,
+ contentTypeTriX,
+ contentTypeTriXxml,
+ contentTypeJSONLD,
+ contentTypeRDFJSON,
+ contentTypeRDFThrift,
+
+ contentTypeTriG,
+ contentTypeTriGAlt1,
+ contentTypeTriGAlt2,
+ contentTypeNQuads,
+ contentTypeNQuadsAlt1,
+ contentTypeNQuadsAlt2
) ;
public static final AcceptList rdfOffer = AcceptList.create(contentTypeTurtle,
http://git-wip-us.apache.org/repos/asf/jena/blob/75a7a77c/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/ResponseDataset.java
----------------------------------------------------------------------
diff --git a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/ResponseDataset.java b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/ResponseDataset.java
index 91d615d..5242f4b 100644
--- a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/ResponseDataset.java
+++ b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/ResponseDataset.java
@@ -19,6 +19,8 @@
package org.apache.jena.fuseki.servlets;
import static org.apache.jena.riot.WebContent.charsetUTF8;
+import static org.apache.jena.riot.WebContent.contentTypeNQuads;
+import static org.apache.jena.riot.WebContent.contentTypeTriG;
import static org.apache.jena.riot.WebContent.contentTypeJSONLD;
import static org.apache.jena.riot.WebContent.contentTypeNTriples;
import static org.apache.jena.riot.WebContent.contentTypeRDFJSON;
@@ -41,7 +43,6 @@ import org.apache.jena.query.Dataset;
import org.apache.jena.riot.Lang;
import org.apache.jena.riot.RDFDataMgr;
import org.apache.jena.riot.RDFLanguages;
-import org.apache.jena.riot.WebContent;
import org.apache.jena.web.HttpSC;
public class ResponseDataset
@@ -49,6 +50,13 @@ public class ResponseDataset
// Short names for "output="
private static final String contentOutputTriG = "trig" ;
private static final String contentOutputNQuads = "n-quads" ;
+ private static final String contentOutputJSONLD = "json-ld" ;
+ private static final String contentOutputJSONRDF = "json-rdf" ;
+ private static final String contentOutputJSON = "json" ;
+ private static final String contentOutputXML = "xml" ;
+ private static final String contentOutputText = "text" ;
+ private static final String contentOutputTTL = "ttl" ;
+ private static final String contentOutputNT = "nt" ;
public static Map<String,String> shortNamesModel = new HashMap<String, String>() ;
@@ -56,8 +64,15 @@ public class ResponseDataset
// Some short names. keys are lowercase.
- ResponseOps.put(shortNamesModel, contentOutputNQuads, WebContent.contentTypeNQuads) ;
- ResponseOps.put(shortNamesModel, contentOutputTriG, WebContent.contentTypeTriG) ;
+ ResponseOps.put(shortNamesModel, contentOutputNQuads, contentTypeNQuads) ;
+ ResponseOps.put(shortNamesModel, contentOutputTriG, contentTypeTriG) ;
+ ResponseOps.put(shortNamesModel, contentOutputJSONLD, contentTypeJSONLD) ;
+ ResponseOps.put(shortNamesModel, contentOutputJSONRDF, contentTypeRDFJSON) ;
+ ResponseOps.put(shortNamesModel, contentOutputJSON, contentTypeJSONLD) ;
+ ResponseOps.put(shortNamesModel, contentOutputXML, contentTypeRDFXML) ;
+ ResponseOps.put(shortNamesModel, contentOutputText, contentTypeTurtle) ;
+ ResponseOps.put(shortNamesModel, contentOutputTTL, contentTypeTurtle) ;
+ ResponseOps.put(shortNamesModel, contentOutputNT, contentTypeNTriples) ;
}
public static void doResponseDataset(HttpAction action, Dataset dataset)
@@ -68,7 +83,7 @@ public class ResponseDataset
String mimeType = null ; // Header request type
// TODO Use MediaType throughout.
- MediaType i = ConNeg.chooseContentType(request, DEF.quadsOffer, DEF.acceptNQuads) ;
+ MediaType i = ConNeg.chooseContentType(request, DEF.constructOffer, DEF.acceptNQuads) ;
if ( i != null )
mimeType = i.getContentType() ;
@@ -122,7 +137,10 @@ public class ResponseDataset
ResponseResultSet.setHttpResponse(action, contentType, charset) ;
response.setStatus(HttpSC.OK_200) ;
ServletOutputStream out = response.getOutputStream() ;
- RDFDataMgr.write(out, dataset, lang) ;
+ if (RDFLanguages.isQuads(lang))
+ RDFDataMgr.write(out, dataset, lang) ;
+ else
+ RDFDataMgr.write(out, dataset.getDefaultModel(), lang) ;
out.flush() ;
}
catch (Exception ex) {
http://git-wip-us.apache.org/repos/asf/jena/blob/75a7a77c/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/ResponseModel.java
----------------------------------------------------------------------
diff --git a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/ResponseModel.java b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/ResponseModel.java
deleted file mode 100644
index 68cf016..0000000
--- a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/ResponseModel.java
+++ /dev/null
@@ -1,135 +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.jena.fuseki.servlets;
-
-import java.util.HashMap ;
-import java.util.Map ;
-
-import javax.servlet.ServletOutputStream ;
-import javax.servlet.http.HttpServletRequest ;
-import javax.servlet.http.HttpServletResponse ;
-
-import org.apache.jena.atlas.web.MediaType ;
-import org.apache.jena.fuseki.DEF ;
-import org.apache.jena.fuseki.Fuseki ;
-import org.apache.jena.fuseki.conneg.ConNeg ;
-import org.apache.jena.fuseki.conneg.WebLib ;
-import org.apache.jena.rdf.model.Model ;
-import org.apache.jena.riot.Lang ;
-import org.apache.jena.riot.RDFDataMgr ;
-import org.apache.jena.riot.RDFLanguages ;
-import static org.apache.jena.riot.WebContent.* ;
-import org.apache.jena.web.HttpSC ;
-
-public class ResponseModel
-{
- // Short names for "output="
- private static final String contentOutputJSONLD = "json-ld" ;
- private static final String contentOutputJSONRDF = "json-rdf" ;
- private static final String contentOutputJSON = "json" ;
- private static final String contentOutputXML = "xml" ;
- private static final String contentOutputText = "text" ;
- private static final String contentOutputTTL = "ttl" ;
- private static final String contentOutputNT = "nt" ;
-
- public static Map<String,String> shortNamesModel = new HashMap<String, String>() ;
- static {
-
- // Some short names. keys are lowercase.
- ResponseOps.put(shortNamesModel, contentOutputJSONLD, contentTypeJSONLD) ;
- ResponseOps.put(shortNamesModel, contentOutputJSONRDF, contentTypeRDFJSON) ;
- ResponseOps.put(shortNamesModel, contentOutputJSON, contentTypeJSONLD) ;
- ResponseOps.put(shortNamesModel, contentOutputXML, contentTypeRDFXML) ;
- ResponseOps.put(shortNamesModel, contentOutputText, contentTypeTurtle) ;
- ResponseOps.put(shortNamesModel, contentOutputTTL, contentTypeTurtle) ;
- ResponseOps.put(shortNamesModel, contentOutputNT, contentTypeNTriples) ;
- }
-
- public static void doResponseModel(HttpAction action, Model model)
- {
- HttpServletRequest request = action.request ;
- HttpServletResponse response = action.response ;
-
- String mimeType = null ; // Header request type
-
- // TODO Use MediaType throughout.
- MediaType i = ConNeg.chooseContentType(request, DEF.rdfOffer, DEF.acceptRDFXML) ;
- if ( i != null )
- mimeType = i.getContentType() ;
-
- String outputField = ResponseOps.paramOutput(request, shortNamesModel) ;
- if ( outputField != null )
- mimeType = outputField ;
-
- String writerMimeType = mimeType ;
-
- if ( mimeType == null )
- {
- Fuseki.actionLog.warn("Can't find MIME type for response") ;
- String x = WebLib.getAccept(request) ;
- String msg ;
- if ( x == null )
- msg = "No Accept: header" ;
- else
- msg = "Accept: "+x+" : Not understood" ;
- ServletOps.error(HttpSC.NOT_ACCEPTABLE_406, msg) ;
- }
-
- String contentType = mimeType ;
- String charset = charsetUTF8 ;
-
- String forceAccept = ResponseOps.paramForceAccept(request) ;
- if ( forceAccept != null )
- {
- contentType = forceAccept ;
- charset = charsetUTF8 ;
- }
-
- Lang lang = RDFLanguages.contentTypeToLang(contentType) ;
- if ( lang == null )
- ServletOps.errorBadRequest("Can't determine output content type: "+contentType) ;
-
-// if ( rdfw instanceof RDFXMLWriterI )
-// rdfw.setProperty("showXmlDeclaration", "true") ;
-
- // // Write locally to check it's possible.
- // // Time/space tradeoff.
- // try {
- // OutputStream out = new NullOutputStream() ;
- // RDFDataMgr.write(out, model, lang) ;
- // IO.flush(out) ;
- // } catch (JenaException ex)
- // {
- // SPARQL_ServletBase.errorOccurred(ex) ;
- // }
-
- try {
- ResponseResultSet.setHttpResponse(action, contentType, charset) ;
- response.setStatus(HttpSC.OK_200) ;
- ServletOutputStream out = response.getOutputStream() ;
- RDFDataMgr.write(out, model, lang) ;
- out.flush() ;
- }
- catch (Exception ex) {
- action.log.info("Exception while writing the response model: "+ex.getMessage(), ex) ;
- ServletOps.errorOccurred("Exception while writing the response model: "+ex.getMessage(), ex) ;
- }
- }
-}
-
http://git-wip-us.apache.org/repos/asf/jena/blob/75a7a77c/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Query.java
----------------------------------------------------------------------
diff --git a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Query.java b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Query.java
index cd0c410..8e81426 100644
--- a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Query.java
+++ b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Query.java
@@ -45,14 +45,10 @@ import javax.servlet.http.HttpServletResponse ;
import org.apache.jena.atlas.io.IO ;
import org.apache.jena.atlas.io.IndentedLineBuffer ;
-import org.apache.jena.atlas.web.AcceptList ;
import org.apache.jena.atlas.web.ContentType ;
-import org.apache.jena.atlas.web.MediaType ;
-import org.apache.jena.fuseki.DEF ;
import org.apache.jena.fuseki.Fuseki ;
import org.apache.jena.fuseki.FusekiException ;
import org.apache.jena.fuseki.FusekiLib ;
-import org.apache.jena.fuseki.conneg.WebLib ;
import org.apache.jena.query.* ;
import org.apache.jena.rdf.model.Model ;
import org.apache.jena.riot.web.HttpNames ;
@@ -319,18 +315,9 @@ public abstract class SPARQL_Query extends SPARQL_Protocol
}
if ( query.isConstructType() ) {
-
- MediaType rdfMediaType = AcceptList.match( DEF.pureRdfOffer, new AcceptList( WebLib.getAccept(action.getRequest())));
-
- if ( ! rdfMediaType.getType().equals("*") ) {
- Model model = queryExecution.execConstruct();
- action.log.info(format("[%d] exec/construct/model", action.id));
- return new SPARQLResult(model);
- } else {
- Dataset dataset = queryExecution.execConstructDataset();
- action.log.info(format("[%d] exec/construct/dataset", action.id));
- return new SPARQLResult(dataset);
- }
+ Dataset dataset = queryExecution.execConstructDataset();
+ action.log.info(format("[%d] exec/construct/dataset", action.id));
+ return new SPARQLResult(dataset);
}
if ( query.isDescribeType() ) {
@@ -391,12 +378,10 @@ public abstract class SPARQL_Query extends SPARQL_Protocol
protected void sendResults(HttpAction action, SPARQLResult result, Prologue qPrologue) {
if ( result.isResultSet() )
ResponseResultSet.doResponseResultSet(action, result.getResultSet(), qPrologue) ;
- else if ( result.isGraph() )
- ResponseModel.doResponseModel(action, result.getModel()) ;
- else if ( result.isBoolean() )
- ResponseResultSet.doResponseResultSet(action, result.getBooleanResult()) ;
else if ( result.isDataset() )
ResponseDataset.doResponseDataset(action, result.getDataset());
+ else if ( result.isBoolean() )
+ ResponseResultSet.doResponseResultSet(action, result.getBooleanResult()) ;
else
ServletOps.errorOccurred("Unknown or invalid result type") ;
}
http://git-wip-us.apache.org/repos/asf/jena/blob/75a7a77c/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestQuery.java
----------------------------------------------------------------------
diff --git a/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestQuery.java b/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestQuery.java
index 4cf5b1b..e721d9d 100644
--- a/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestQuery.java
+++ b/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestQuery.java
@@ -42,6 +42,7 @@ import org.apache.jena.sparql.sse.Item ;
import org.apache.jena.sparql.sse.SSE ;
import org.apache.jena.sparql.sse.builders.BuilderResultSet ;
import org.apache.jena.sparql.util.Convert ;
+import org.apache.jena.rdf.model.*;
import org.junit.AfterClass ;
import org.junit.Assert ;
import org.junit.BeforeClass ;
@@ -169,7 +170,6 @@ public class TestQuery extends BaseTest {
Dataset result = qExec.execConstructDataset();
Assert.assertTrue(result.asDatasetGraph().find().hasNext());
Assert.assertEquals( "http://eg/g", result.asDatasetGraph().find().next().getGraph().getURI());
-
}
}
@@ -182,6 +182,16 @@ public class TestQuery extends BaseTest {
Assert.assertTrue(result.hasNext());
}
}
+
+ @Test
+ public void query_construct_02()
+ {
+ String query = " CONSTRUCT {?s ?p ?o} WHERE {?s ?p ?o}" ;
+ try ( QueryExecution qExec = QueryExecutionFactory.sparqlService(serviceQuery, query) ) {
+ Model result = qExec.execConstruct();
+ assertEquals(1, result.size());
+ }
+ }
private void execQuery(String queryString, int exceptedRowCount) {
QueryExecution qExec = QueryExecutionFactory.sparqlService(serviceQuery, queryString) ;
[12/16] jena git commit: Add execConstructDataset(Dataset)
Posted by an...@apache.org.
Add execConstructDataset(Dataset)
Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/179a2048
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/179a2048
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/179a2048
Branch: refs/heads/JENA-491-construct-quads
Commit: 179a2048a2d6b4e4a44a5304d4ca87e9b8f14f4f
Parents: cfb7fda
Author: Andy Seaborne <an...@apache.org>
Authored: Thu Aug 20 11:30:53 2015 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Thu Aug 20 11:31:59 2015 +0100
----------------------------------------------------------------------
.../sparql/engine/http/QueryEngineHTTP.java | 164 ++++++++++---------
1 file changed, 90 insertions(+), 74 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jena/blob/179a2048/jena-arq/src/main/java/org/apache/jena/sparql/engine/http/QueryEngineHTTP.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/engine/http/QueryEngineHTTP.java b/jena-arq/src/main/java/org/apache/jena/sparql/engine/http/QueryEngineHTTP.java
index 2fa9602..933c8e7 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/engine/http/QueryEngineHTTP.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/engine/http/QueryEngineHTTP.java
@@ -28,6 +28,7 @@ import java.util.concurrent.TimeUnit ;
import org.apache.http.client.HttpClient ;
import org.apache.jena.atlas.io.IO ;
+import org.apache.jena.atlas.lib.Pair ;
import org.apache.jena.atlas.web.auth.HttpAuthenticator ;
import org.apache.jena.atlas.web.auth.SimpleAuthenticator ;
import org.apache.jena.graph.Triple ;
@@ -36,8 +37,6 @@ import org.apache.jena.rdf.model.Model ;
import org.apache.jena.riot.* ;
import org.apache.jena.riot.web.HttpOp ;
import org.apache.jena.sparql.ARQException ;
-import org.apache.jena.sparql.core.DatasetGraph;
-import org.apache.jena.sparql.core.DatasetGraphFactory;
import org.apache.jena.sparql.core.Quad;
import org.apache.jena.sparql.engine.ResultSetCheckCondition ;
import org.apache.jena.sparql.graph.GraphFactory ;
@@ -87,7 +86,9 @@ public class QueryEngineHTTP implements QueryExecution {
private String selectContentType = defaultSelectHeader();
private String askContentType = defaultAskHeader();
private String modelContentType = defaultConstructHeader();
- private String datasetContentType = WebContent.defaultDatasetAcceptHeader;
+
+ private String constructContentType = defaultConstructHeader() ;
+ private String datasetContentType = defaultConstructDatasetHeader() ;
// Received content type
private String httpResponseContentType = null ;
@@ -411,14 +412,12 @@ public class QueryEngineHTTP implements QueryExecution {
@Override
public Dataset execConstructDataset(){
- checkNotClosed() ;
- DatasetGraph dataset = DatasetGraphFactory.createMem();
- try {
- execConstructQuads().forEachRemaining(dataset::add);
- } finally {
- this.close();
- }
- return DatasetFactory.create(dataset);
+ return execConstructDataset(DatasetFactory.createMem());
+ }
+
+ @Override
+ public Dataset execConstructDataset(Dataset dataset){
+ return execDataset(dataset) ;
}
@Override
@@ -437,64 +436,43 @@ public class QueryEngineHTTP implements QueryExecution {
}
private Model execModel(Model model) {
- checkNotClosed() ;
- HttpQuery httpQuery = makeHttpQuery();
- httpQuery.setAccept(modelContentType);
- InputStream in = httpQuery.exec();
-
- // Don't assume the endpoint actually gives back the content type we
- // asked for
- String actualContentType = httpQuery.getContentType();
- httpResponseContentType = actualContentType;
-
- // If the server fails to return a Content-Type then we will assume
- // the server returned the type we asked for
- if (actualContentType == null || actualContentType.equals("")) {
- actualContentType = modelContentType;
- }
-
- // Try to select language appropriately here based on the model content
- // type
- Lang lang = RDFLanguages.contentTypeToLang(actualContentType);
- if (!RDFLanguages.isTriples(lang))
- throw new QueryException("Endpoint returned Content Type: " + actualContentType
- + " which is not a valid RDF Graph syntax");
- RDFDataMgr.read(model, in, lang);
- this.close();
+ Pair<InputStream, Lang> p = execConstructWorker(modelContentType) ;
+ InputStream in = p.getLeft() ;
+ Lang lang = p.getRight() ;
+ try { RDFDataMgr.read(model, in, lang); }
+ finally { this.close(); }
return model;
}
- private Iterator<Triple> execTriples() {
- checkNotClosed() ;
- HttpQuery httpQuery = makeHttpQuery();
- httpQuery.setAccept(modelContentType);
- InputStream in = httpQuery.exec();
-
- // Don't assume the endpoint actually gives back the content type we
- // asked for
- String actualContentType = httpQuery.getContentType();
- httpResponseContentType = actualContentType;
-
- // If the server fails to return a Content-Type then we will assume
- // the server returned the type we asked for
- if (actualContentType == null || actualContentType.equals("")) {
- actualContentType = modelContentType;
- }
-
- // Try to select language appropriately here based on the model content
- // type
- Lang lang = RDFLanguages.contentTypeToLang(actualContentType);
- if (!RDFLanguages.isTriples(lang))
- throw new QueryException("Endpoint returned Content Type: " + actualContentType
- + " which is not a valid RDF Graph syntax");
+ private Dataset execDataset(Dataset dataset) {
+ Pair<InputStream, Lang> p = execConstructWorker(datasetContentType);
+ InputStream in = p.getLeft() ;
+ Lang lang = p.getRight() ;
+ try { RDFDataMgr.read(dataset, in, lang); }
+ finally { this.close(); }
+ return dataset;
+ }
+ private Iterator<Triple> execTriples() {
+ Pair<InputStream, Lang> p = execConstructWorker(modelContentType) ;
+ InputStream in = p.getLeft() ;
+ Lang lang = p.getRight() ;
+ // Base URI?
return RiotReader.createIteratorTriples(in, lang, null);
}
private Iterator<Quad> execQuads() {
+ Pair<InputStream, Lang> p = execConstructWorker(datasetContentType) ;
+ InputStream in = p.getLeft() ;
+ Lang lang = p.getRight() ;
+ // Base URI?
+ return RiotReader.createIteratorQuads(in, lang, null);
+ }
+
+ private Pair<InputStream, Lang> execConstructWorker(String contentType) {
checkNotClosed() ;
HttpQuery httpQuery = makeHttpQuery();
- httpQuery.setAccept(datasetContentType);
+ httpQuery.setAccept(contentType);
InputStream in = httpQuery.exec();
// Don't assume the endpoint actually gives back the content type we
@@ -507,17 +485,14 @@ public class QueryEngineHTTP implements QueryExecution {
if (actualContentType == null || actualContentType.equals("")) {
actualContentType = WebContent.defaultDatasetAcceptHeader;
}
-
- // Try to select language appropriately here based on the model content
- // type
Lang lang = RDFLanguages.contentTypeToLang(actualContentType);
- if (!RDFLanguages.isQuads(lang))
- throw new QueryException("Endpoint returned Content Type: " + actualContentType
- + " which is not a valid RDF Dataset syntax");
-
- return RiotReader.createIteratorQuads(in, lang, null);
+ if ( ! RDFLanguages.isQuads(lang) && ! RDFLanguages.isTriples(lang) )
+ throw new QueryException("Endpoint returned Content Type: "
+ + actualContentType
+ + " which is not a valid RDF syntax");
+ return Pair.create(in, lang) ;
}
-
+
@Override
public boolean execAsk() {
checkNotClosed() ;
@@ -813,10 +788,10 @@ public class QueryEngineHTTP implements QueryExecution {
datasetContentType = contentType;
}
- private static final String selectContentTypeHeader = initSelectContentTypes() ;
+ private static final String dftSelectContentTypeHeader = initSelectContentTypes() ;
public static String defaultSelectHeader() {
- return selectContentTypeHeader ;
+ return dftSelectContentTypeHeader ;
}
private static String initSelectContentTypes() {
@@ -836,18 +811,18 @@ public class QueryEngineHTTP implements QueryExecution {
private static final String askContentTypeHeader = initAskContentTypes() ;
public static String defaultAskHeader() {
- return selectContentTypeHeader ;
+ return dftSelectContentTypeHeader ;
}
// These happen to be the same.
private static String initAskContentTypes() { return initSelectContentTypes(); }
- private static final String constructContentTypeHeader = initConstructContentTypes() ;
+ private static final String dftConstructContentTypeHeader = initConstructContentTypes() ;
public static String defaultConstructHeader() {
- return constructContentTypeHeader ;
+ return dftConstructContentTypeHeader ;
}
-
+
private static String initConstructContentTypes() {
// Or use WebContent.defaultGraphAcceptHeader which is slightly
// narrower. Here, we have a tuned setting for SPARQL operations.
@@ -869,6 +844,47 @@ public class QueryEngineHTTP implements QueryExecution {
return sBuff.toString();
}
+ private static final String dftConstructDatasetContentTypeHeader = initConstructDatasetContentTypes() ;
+
+ public static String defaultConstructDatasetHeader() {
+ return dftConstructDatasetContentTypeHeader ;
+ }
+
+ private static String initConstructDatasetContentTypes() {
+ // Or use WebContent.defaultDatasetAcceptHeader which is slightly
+ // narrower. Here, we have a tuned setting for SPARQL operations.
+ StringBuilder sBuff = new StringBuilder() ;
+
+ accumulateContentTypeString(sBuff, WebContent.contentTypeTriG, 1.0) ;
+ accumulateContentTypeString(sBuff, WebContent.contentTypeTriGAlt1, 1.0) ;
+ accumulateContentTypeString(sBuff, WebContent.contentTypeTriGAlt2, 1.0) ;
+
+ accumulateContentTypeString(sBuff, WebContent.contentTypeNQuads, 1.0) ;
+ accumulateContentTypeString(sBuff, WebContent.contentTypeNQuadsAlt1, 1.0) ;
+ accumulateContentTypeString(sBuff, WebContent.contentTypeNQuadsAlt2, 1.0) ;
+
+ accumulateContentTypeString(sBuff, WebContent.contentTypeJSONLD, 0.9) ;
+
+ // And triple formats (the case of execConstructDatasets but a regular triples CONSTRUCT).
+ accumulateContentTypeString(sBuff, WebContent.contentTypeTurtle, 0.8);
+ accumulateContentTypeString(sBuff, WebContent.contentTypeNTriples, 0.8);
+
+ accumulateContentTypeString(sBuff, WebContent.contentTypeRDFXML, 0.7);
+
+ accumulateContentTypeString(sBuff, WebContent.contentTypeTurtleAlt1, 0.6);
+ accumulateContentTypeString(sBuff, WebContent.contentTypeTurtleAlt2, 0.6);
+
+ accumulateContentTypeString(sBuff, WebContent.contentTypeN3, 0.5);
+ accumulateContentTypeString(sBuff, WebContent.contentTypeN3Alt1, 0.5);
+ accumulateContentTypeString(sBuff, WebContent.contentTypeN3Alt2, 0.5);
+
+ accumulateContentTypeString(sBuff, WebContent.contentTypeNTriplesAlt, 0.4);
+
+ accumulateContentTypeString(sBuff, "*/*", 0.1) ;
+
+ return sBuff.toString();
+ }
+
private static void accumulateContentTypeString(StringBuilder sBuff, String str, double v) {
if ( sBuff.length() != 0 )
sBuff.append(", ") ;
[02/16] jena git commit: JENA-491 Fuseki Support: minor formatting
for SPARQL_Query.java
Posted by an...@apache.org.
JENA-491 Fuseki Support: minor formatting for SPARQL_Query.java
Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/5939a351
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/5939a351
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/5939a351
Branch: refs/heads/JENA-491-construct-quads
Commit: 5939a351616d5e588835b9a265dd568f2087148b
Parents: c7dedb2
Author: confidencesun <co...@gmail.com>
Authored: Mon Aug 17 21:32:55 2015 +0800
Committer: confidencesun <co...@gmail.com>
Committed: Mon Aug 17 21:32:55 2015 +0800
----------------------------------------------------------------------
.../jena/fuseki/servlets/SPARQL_Query.java | 121 +++++++++----------
1 file changed, 54 insertions(+), 67 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jena/blob/5939a351/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Query.java
----------------------------------------------------------------------
diff --git a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Query.java b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Query.java
index 8a2195e..cd0c410 100644
--- a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Query.java
+++ b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Query.java
@@ -18,61 +18,48 @@
package org.apache.jena.fuseki.servlets ;
-import static java.lang.String.format;
-import static org.apache.jena.fuseki.server.CounterName.QueryTimeouts;
-import static org.apache.jena.riot.WebContent.ctHTMLForm;
-import static org.apache.jena.riot.WebContent.ctSPARQLQuery;
-import static org.apache.jena.riot.WebContent.isHtmlForm;
-import static org.apache.jena.riot.WebContent.matchContentType;
-import static org.apache.jena.riot.web.HttpNames.paramAccept;
-import static org.apache.jena.riot.web.HttpNames.paramCallback;
-import static org.apache.jena.riot.web.HttpNames.paramDefaultGraphURI;
-import static org.apache.jena.riot.web.HttpNames.paramForceAccept;
-import static org.apache.jena.riot.web.HttpNames.paramNamedGraphURI;
-import static org.apache.jena.riot.web.HttpNames.paramOutput1;
-import static org.apache.jena.riot.web.HttpNames.paramOutput2;
-import static org.apache.jena.riot.web.HttpNames.paramQuery;
-import static org.apache.jena.riot.web.HttpNames.paramQueryRef;
-import static org.apache.jena.riot.web.HttpNames.paramStyleSheet;
-import static org.apache.jena.riot.web.HttpNames.paramTimeout;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Enumeration;
-import java.util.List;
-import java.util.Locale;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.apache.jena.atlas.io.IO;
-import org.apache.jena.atlas.io.IndentedLineBuffer;
-import org.apache.jena.atlas.web.AcceptList;
-import org.apache.jena.atlas.web.ContentType;
-import org.apache.jena.atlas.web.MediaType;
-import org.apache.jena.fuseki.DEF;
-import org.apache.jena.fuseki.Fuseki;
-import org.apache.jena.fuseki.FusekiException;
-import org.apache.jena.fuseki.FusekiLib;
-import org.apache.jena.fuseki.conneg.WebLib;
-import org.apache.jena.query.Dataset;
-import org.apache.jena.query.Query;
-import org.apache.jena.query.QueryCancelledException;
-import org.apache.jena.query.QueryException;
-import org.apache.jena.query.QueryExecution;
-import org.apache.jena.query.QueryExecutionFactory;
-import org.apache.jena.query.QueryFactory;
-import org.apache.jena.query.QueryParseException;
-import org.apache.jena.query.ResultSet;
-import org.apache.jena.query.Syntax;
-import org.apache.jena.rdf.model.Model;
-import org.apache.jena.riot.web.HttpNames;
-import org.apache.jena.riot.web.HttpOp;
-import org.apache.jena.sparql.core.Prologue;
-import org.apache.jena.sparql.resultset.SPARQLResult;
-import org.apache.jena.web.HttpSC;
+import static java.lang.String.format ;
+import static org.apache.jena.fuseki.server.CounterName.QueryTimeouts ;
+import static org.apache.jena.riot.WebContent.ctHTMLForm ;
+import static org.apache.jena.riot.WebContent.ctSPARQLQuery ;
+import static org.apache.jena.riot.WebContent.isHtmlForm ;
+import static org.apache.jena.riot.WebContent.matchContentType ;
+import static org.apache.jena.riot.web.HttpNames.paramAccept ;
+import static org.apache.jena.riot.web.HttpNames.paramCallback ;
+import static org.apache.jena.riot.web.HttpNames.paramDefaultGraphURI ;
+import static org.apache.jena.riot.web.HttpNames.paramForceAccept ;
+import static org.apache.jena.riot.web.HttpNames.paramNamedGraphURI ;
+import static org.apache.jena.riot.web.HttpNames.paramOutput1 ;
+import static org.apache.jena.riot.web.HttpNames.paramOutput2 ;
+import static org.apache.jena.riot.web.HttpNames.paramQuery ;
+import static org.apache.jena.riot.web.HttpNames.paramQueryRef ;
+import static org.apache.jena.riot.web.HttpNames.paramStyleSheet ;
+import static org.apache.jena.riot.web.HttpNames.paramTimeout ;
+
+import java.io.IOException ;
+import java.io.InputStream ;
+import java.util.* ;
+
+import javax.servlet.http.HttpServletRequest ;
+import javax.servlet.http.HttpServletResponse ;
+
+import org.apache.jena.atlas.io.IO ;
+import org.apache.jena.atlas.io.IndentedLineBuffer ;
+import org.apache.jena.atlas.web.AcceptList ;
+import org.apache.jena.atlas.web.ContentType ;
+import org.apache.jena.atlas.web.MediaType ;
+import org.apache.jena.fuseki.DEF ;
+import org.apache.jena.fuseki.Fuseki ;
+import org.apache.jena.fuseki.FusekiException ;
+import org.apache.jena.fuseki.FusekiLib ;
+import org.apache.jena.fuseki.conneg.WebLib ;
+import org.apache.jena.query.* ;
+import org.apache.jena.rdf.model.Model ;
+import org.apache.jena.riot.web.HttpNames ;
+import org.apache.jena.riot.web.HttpOp ;
+import org.apache.jena.sparql.core.Prologue ;
+import org.apache.jena.sparql.resultset.SPARQLResult ;
+import org.apache.jena.web.HttpSC ;
/** Handle SPARQL Query requests overt eh SPARQL Protocol.
* Subclasses provide this algorithm with the actual dataset to query, whether
@@ -332,18 +319,18 @@ public abstract class SPARQL_Query extends SPARQL_Protocol
}
if ( query.isConstructType() ) {
-
+
MediaType rdfMediaType = AcceptList.match( DEF.pureRdfOffer, new AcceptList( WebLib.getAccept(action.getRequest())));
-
- if ( ! rdfMediaType.getType().equals("*") ) {
- Model model = queryExecution.execConstruct();
- action.log.info(format("[%d] exec/construct/model", action.id));
- return new SPARQLResult(model);
- } else {
- Dataset dataset = queryExecution.execConstructDataset();
- action.log.info(format("[%d] exec/construct/dataset", action.id));
- return new SPARQLResult(dataset);
- }
+
+ if ( ! rdfMediaType.getType().equals("*") ) {
+ Model model = queryExecution.execConstruct();
+ action.log.info(format("[%d] exec/construct/model", action.id));
+ return new SPARQLResult(model);
+ } else {
+ Dataset dataset = queryExecution.execConstructDataset();
+ action.log.info(format("[%d] exec/construct/dataset", action.id));
+ return new SPARQLResult(dataset);
+ }
}
if ( query.isDescribeType() ) {
@@ -409,7 +396,7 @@ public abstract class SPARQL_Query extends SPARQL_Protocol
else if ( result.isBoolean() )
ResponseResultSet.doResponseResultSet(action, result.getBooleanResult()) ;
else if ( result.isDataset() )
- ResponseDataset.doResponseDataset(action, result.getDataset());
+ ResponseDataset.doResponseDataset(action, result.getDataset());
else
ServletOps.errorOccurred("Unknown or invalid result type") ;
}
[04/16] jena git commit: JENA-491 Fuseki Support: Test
exeConstructDataset() of QueryEngineHTTP
Posted by an...@apache.org.
JENA-491 Fuseki Support: Test exeConstructDataset() of
QueryEngineHTTP
Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/de1d1c33
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/de1d1c33
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/de1d1c33
Branch: refs/heads/JENA-491-construct-quads
Commit: de1d1c33cd64b88d3a56127c4c434c2b39c1e196
Parents: 2bc9fe6
Author: confidencesun <co...@gmail.com>
Authored: Mon Aug 17 21:45:05 2015 +0800
Committer: confidencesun <co...@gmail.com>
Committed: Mon Aug 17 21:54:05 2015 +0800
----------------------------------------------------------------------
.../test/java/org/apache/jena/fuseki/TestQuery.java | 14 ++++++++++++++
1 file changed, 14 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jena/blob/de1d1c33/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestQuery.java
----------------------------------------------------------------------
diff --git a/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestQuery.java b/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestQuery.java
index 21f89fc..4cf5b1b 100644
--- a/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestQuery.java
+++ b/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestQuery.java
@@ -160,6 +160,20 @@ public class TestQuery extends BaseTest {
}
@Test
+ public void query_construct_quad_02()
+ {
+ String queryString = " CONSTRUCT { GRAPH <http://eg/g> {?s ?p ?oq} } WHERE {?s ?p ?oq}" ;
+ Query query = QueryFactory.create(queryString, Syntax.syntaxARQ);
+
+ try ( QueryExecution qExec = QueryExecutionFactory.sparqlService(serviceQuery, query) ) {
+ Dataset result = qExec.execConstructDataset();
+ Assert.assertTrue(result.asDatasetGraph().find().hasNext());
+ Assert.assertEquals( "http://eg/g", result.asDatasetGraph().find().next().getGraph().getURI());
+
+ }
+ }
+
+ @Test
public void query_construct_01()
{
String query = " CONSTRUCT {?s ?p ?o} WHERE {?s ?p ?o}" ;
[13/16] jena git commit: acceptTurtle
Posted by an...@apache.org.
acceptTurtle
Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/15551263
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/15551263
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/15551263
Branch: refs/heads/JENA-491-construct-quads
Commit: 155512631065c6f3e4f613b002ebfe6d356d616f
Parents: 179a204
Author: Andy Seaborne <an...@apache.org>
Authored: Thu Aug 20 11:32:20 2015 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Thu Aug 20 11:32:20 2015 +0100
----------------------------------------------------------------------
.../jena-fuseki-core/src/main/java/org/apache/jena/fuseki/DEF.java | 1 +
1 file changed, 1 insertion(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jena/blob/15551263/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/DEF.java
----------------------------------------------------------------------
diff --git a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/DEF.java b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/DEF.java
index 46ef3be..cd7962a 100644
--- a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/DEF.java
+++ b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/DEF.java
@@ -28,6 +28,7 @@ public class DEF
public static final MediaType acceptNQuads = MediaType.create(contentTypeNQuads) ;
public static final MediaType acceptRSXML = MediaType.create(contentTypeResultsXML) ;
public static final MediaType acceptJSON = MediaType.create(contentTypeJSON) ;
+ public static final MediaType acceptTurtle = MediaType.create(contentTypeTurtle) ;
public static final AcceptList jsonOffer = AcceptList.create(contentTypeJSON) ;
[08/16] jena git commit: Remove unused imports
Posted by an...@apache.org.
Remove unused imports
Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/fe19b4b1
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/fe19b4b1
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/fe19b4b1
Branch: refs/heads/JENA-491-construct-quads
Commit: fe19b4b1b5cfbfdf956a07370e0622071cebda26
Parents: 077a413
Author: Andy Seaborne <an...@apache.org>
Authored: Thu Aug 20 09:40:53 2015 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Thu Aug 20 09:40:53 2015 +0100
----------------------------------------------------------------------
.../src/test/java/org/apache/jena/fuseki/TestQuery.java | 11 ++---------
1 file changed, 2 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jena/blob/fe19b4b1/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestQuery.java
----------------------------------------------------------------------
diff --git a/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestQuery.java b/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestQuery.java
index 1c496f0..7436e7a 100644
--- a/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestQuery.java
+++ b/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestQuery.java
@@ -18,12 +18,7 @@
package org.apache.jena.fuseki ;
-import static org.apache.jena.fuseki.ServerTest.gn1 ;
-import static org.apache.jena.fuseki.ServerTest.gn2 ;
-import static org.apache.jena.fuseki.ServerTest.model1 ;
-import static org.apache.jena.fuseki.ServerTest.model2 ;
-import static org.apache.jena.fuseki.ServerTest.serviceQuery ;
-import static org.apache.jena.fuseki.ServerTest.serviceREST ;
+import static org.apache.jena.fuseki.ServerTest.* ;
import java.io.IOException ;
import java.net.HttpURLConnection ;
@@ -31,11 +26,11 @@ import java.net.URL ;
import java.util.Iterator ;
import org.apache.jena.atlas.junit.BaseTest ;
-import org.apache.jena.atlas.logging.Log;
import org.apache.jena.atlas.web.MediaType;
import org.apache.jena.graph.Node ;
import org.apache.jena.graph.Triple ;
import org.apache.jena.query.* ;
+import org.apache.jena.rdf.model.Model ;
import org.apache.jena.sparql.core.Quad ;
import org.apache.jena.sparql.core.Var ;
import org.apache.jena.sparql.engine.binding.Binding ;
@@ -45,8 +40,6 @@ import org.apache.jena.sparql.sse.Item ;
import org.apache.jena.sparql.sse.SSE ;
import org.apache.jena.sparql.sse.builders.BuilderResultSet ;
import org.apache.jena.sparql.util.Convert ;
-import org.apache.jena.rdf.model.*;
-import org.apache.jena.riot.WebContent;
import org.junit.AfterClass ;
import org.junit.Assert ;
import org.junit.BeforeClass ;