From fc246cc6f09adceafaffbdfa36d70d414233b586 Mon Sep 17 00:00:00 2001 From: Dietmar Glachs Date: Tue, 7 Apr 2015 10:10:10 +0200 Subject: [PATCH 1/3] #marmotta-606 in sparqlwebservice, only the first "Accept" header of the HttpServletRequest was checked. Added method in MarmottaHttpUtils#parseAcceptHeader(Enumeration) to return the ordered list of content types. Changed SparqlWebService to check the list --- .../commons/http/MarmottaHttpUtils.java | 34 +++++++++++++++++++ .../sparql/webservices/SparqlWebService.java | 19 +++++++---- 2 files changed, 47 insertions(+), 6 deletions(-) diff --git a/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/http/MarmottaHttpUtils.java b/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/http/MarmottaHttpUtils.java index 199dde96c..102c99111 100644 --- a/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/http/MarmottaHttpUtils.java +++ b/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/http/MarmottaHttpUtils.java @@ -18,20 +18,54 @@ package org.apache.marmotta.commons.http; import org.apache.commons.lang3.StringUtils; + import org.openrdf.query.resultio.QueryResultFormat; import java.nio.charset.Charset; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.Enumeration; import java.util.List; +import javax.servlet.http.HttpServletRequest; + /** * Add file description here! *

* Author: Sebastian Schaffert */ public class MarmottaHttpUtils { + public static final String ACCEPT = "Accept"; + /** + * A utility method for parsing Content-Type and Accept header + * @param request the {@link HttpServletRequest} provided + * @return An ordered list of {@link ContentType} elements + */ + public static List parseAcceptHeader(HttpServletRequest request) { + Enumeration acceptHeaderStrings = request.getHeaders(ACCEPT); + return parseAcceptHeader(acceptHeaderStrings); + } + /** + * A utility method for parsing Content-Type out of the provided Accept headers. + * + * @param request the {@link HttpServletRequest} provided + * @return An ordered list of {@link ContentType} elements. + * @see HttpServletRequest#getHeaders(String) + */ + public static List parseAcceptHeader(Enumeration acceptHeaderStrings) { + List contentTypes = new ArrayList<>(); + while ( acceptHeaderStrings.hasMoreElements() ) { + ContentType contentType = parseContentType(acceptHeaderStrings.nextElement()); + if ( contentType != null ) { + contentTypes.add(contentType); + } + } + // + Collections.sort(contentTypes); + + return contentTypes; + } /** * A utility method for parsing HTTP Content-Type and Accept header, taking into account different parameters that diff --git a/platform/marmotta-sparql/src/main/java/org/apache/marmotta/platform/sparql/webservices/SparqlWebService.java b/platform/marmotta-sparql/src/main/java/org/apache/marmotta/platform/sparql/webservices/SparqlWebService.java index 3fde761c8..6db847615 100644 --- a/platform/marmotta-sparql/src/main/java/org/apache/marmotta/platform/sparql/webservices/SparqlWebService.java +++ b/platform/marmotta-sparql/src/main/java/org/apache/marmotta/platform/sparql/webservices/SparqlWebService.java @@ -232,8 +232,12 @@ public Response selectPost(@QueryParam("output") String resultType, @Context Htt */ private Response select(String query, String resultType, HttpServletRequest request) { try { + // MARMOTTA-606 - check all "Accept" Headers, not only the first one + List acceptedTypes = MarmottaHttpUtils.parseAcceptHeader(request.getHeaders(ACCEPT)); String acceptHeader = StringUtils.defaultString(request.getHeader(ACCEPT), ""); if (StringUtils.isBlank(query)) { //empty query + // combine the list of accepted types to search for HTML header + acceptHeader = StringUtils.join(acceptedTypes, ","); if (acceptHeader.contains("html")) { return Response.seeOther(new URI(configurationService.getServerUri() + "sparql/admin/squebi.html")).build(); } else { @@ -242,13 +246,14 @@ private Response select(String query, String resultType, HttpServletRequest requ } else { //query duck typing QueryType queryType = sparqlService.getQueryType(QueryLanguage.SPARQL, query); - List acceptedTypes; + // List acceptedTypes; List offeredTypes; if (resultType != null) { acceptedTypes = MarmottaHttpUtils.parseAcceptHeader(resultType); - } else { - acceptedTypes = MarmottaHttpUtils.parseAcceptHeader(acceptHeader); - } + } +// else { +// acceptedTypes = MarmottaHttpUtils.parseAcceptHeader(acceptHeader); +// } if (QueryType.TUPLE.equals(queryType)) { offeredTypes = MarmottaHttpUtils.parseQueryResultFormatList(TupleQueryResultWriterRegistry.getInstance().getKeys()); } else if (QueryType.BOOL.equals(queryType)) { @@ -389,7 +394,8 @@ private Response update(String update, String resultType, HttpServletRequest req return Response.ok().build(); } else { if (resultType == null) { - List acceptedTypes = MarmottaHttpUtils.parseAcceptHeader(request.getHeader(ACCEPT)); + // MARMOTTA-606: Check all provdes accept headers, not only the first one + List acceptedTypes = MarmottaHttpUtils.parseAcceptHeader(request.getHeaders(ACCEPT)); List offeredTypes = MarmottaHttpUtils.parseStringList(Lists.newArrayList("*/*", "text/html")); ContentType bestType = MarmottaHttpUtils.bestContentType(offeredTypes, acceptedTypes); if (bestType != null) { @@ -464,7 +470,8 @@ private Response createServiceDescriptionResponse(final HttpServletRequest reque if (StringUtils.isBlank(request.getHeader(ACCEPT))) { acceptedTypes = Collections.singletonList(MarmottaHttpUtils.parseContentType(RDFXML.getDefaultMIMEType())); } else { - acceptedTypes = MarmottaHttpUtils.parseAcceptHeader(request.getHeader(ACCEPT)); + // MARMOTTA-606 - retrieve all headers instead of the first one + acceptedTypes = MarmottaHttpUtils.parseAcceptHeader(request.getHeaders(ACCEPT)); } ContentType _bestType = null; From 6a10c48c1349a517e1f1d35669c99747af2ee4b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Fern=C3=A1ndez?= Date: Tue, 7 Apr 2015 10:37:12 +0200 Subject: [PATCH 2/3] Revert "#marmotta-606" This reverts commit fc246cc6f09adceafaffbdfa36d70d414233b586. --- .../commons/http/MarmottaHttpUtils.java | 34 ------------------- .../sparql/webservices/SparqlWebService.java | 19 ++++------- 2 files changed, 6 insertions(+), 47 deletions(-) diff --git a/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/http/MarmottaHttpUtils.java b/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/http/MarmottaHttpUtils.java index 102c99111..199dde96c 100644 --- a/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/http/MarmottaHttpUtils.java +++ b/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/http/MarmottaHttpUtils.java @@ -18,54 +18,20 @@ package org.apache.marmotta.commons.http; import org.apache.commons.lang3.StringUtils; - import org.openrdf.query.resultio.QueryResultFormat; import java.nio.charset.Charset; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; -import java.util.Enumeration; import java.util.List; -import javax.servlet.http.HttpServletRequest; - /** * Add file description here! *

* Author: Sebastian Schaffert */ public class MarmottaHttpUtils { - public static final String ACCEPT = "Accept"; - /** - * A utility method for parsing Content-Type and Accept header - * @param request the {@link HttpServletRequest} provided - * @return An ordered list of {@link ContentType} elements - */ - public static List parseAcceptHeader(HttpServletRequest request) { - Enumeration acceptHeaderStrings = request.getHeaders(ACCEPT); - return parseAcceptHeader(acceptHeaderStrings); - } - /** - * A utility method for parsing Content-Type out of the provided Accept headers. - * - * @param request the {@link HttpServletRequest} provided - * @return An ordered list of {@link ContentType} elements. - * @see HttpServletRequest#getHeaders(String) - */ - public static List parseAcceptHeader(Enumeration acceptHeaderStrings) { - List contentTypes = new ArrayList<>(); - while ( acceptHeaderStrings.hasMoreElements() ) { - ContentType contentType = parseContentType(acceptHeaderStrings.nextElement()); - if ( contentType != null ) { - contentTypes.add(contentType); - } - } - // - Collections.sort(contentTypes); - - return contentTypes; - } /** * A utility method for parsing HTTP Content-Type and Accept header, taking into account different parameters that diff --git a/platform/marmotta-sparql/src/main/java/org/apache/marmotta/platform/sparql/webservices/SparqlWebService.java b/platform/marmotta-sparql/src/main/java/org/apache/marmotta/platform/sparql/webservices/SparqlWebService.java index 6db847615..3fde761c8 100644 --- a/platform/marmotta-sparql/src/main/java/org/apache/marmotta/platform/sparql/webservices/SparqlWebService.java +++ b/platform/marmotta-sparql/src/main/java/org/apache/marmotta/platform/sparql/webservices/SparqlWebService.java @@ -232,12 +232,8 @@ public Response selectPost(@QueryParam("output") String resultType, @Context Htt */ private Response select(String query, String resultType, HttpServletRequest request) { try { - // MARMOTTA-606 - check all "Accept" Headers, not only the first one - List acceptedTypes = MarmottaHttpUtils.parseAcceptHeader(request.getHeaders(ACCEPT)); String acceptHeader = StringUtils.defaultString(request.getHeader(ACCEPT), ""); if (StringUtils.isBlank(query)) { //empty query - // combine the list of accepted types to search for HTML header - acceptHeader = StringUtils.join(acceptedTypes, ","); if (acceptHeader.contains("html")) { return Response.seeOther(new URI(configurationService.getServerUri() + "sparql/admin/squebi.html")).build(); } else { @@ -246,14 +242,13 @@ private Response select(String query, String resultType, HttpServletRequest requ } else { //query duck typing QueryType queryType = sparqlService.getQueryType(QueryLanguage.SPARQL, query); - // List acceptedTypes; + List acceptedTypes; List offeredTypes; if (resultType != null) { acceptedTypes = MarmottaHttpUtils.parseAcceptHeader(resultType); - } -// else { -// acceptedTypes = MarmottaHttpUtils.parseAcceptHeader(acceptHeader); -// } + } else { + acceptedTypes = MarmottaHttpUtils.parseAcceptHeader(acceptHeader); + } if (QueryType.TUPLE.equals(queryType)) { offeredTypes = MarmottaHttpUtils.parseQueryResultFormatList(TupleQueryResultWriterRegistry.getInstance().getKeys()); } else if (QueryType.BOOL.equals(queryType)) { @@ -394,8 +389,7 @@ private Response update(String update, String resultType, HttpServletRequest req return Response.ok().build(); } else { if (resultType == null) { - // MARMOTTA-606: Check all provdes accept headers, not only the first one - List acceptedTypes = MarmottaHttpUtils.parseAcceptHeader(request.getHeaders(ACCEPT)); + List acceptedTypes = MarmottaHttpUtils.parseAcceptHeader(request.getHeader(ACCEPT)); List offeredTypes = MarmottaHttpUtils.parseStringList(Lists.newArrayList("*/*", "text/html")); ContentType bestType = MarmottaHttpUtils.bestContentType(offeredTypes, acceptedTypes); if (bestType != null) { @@ -470,8 +464,7 @@ private Response createServiceDescriptionResponse(final HttpServletRequest reque if (StringUtils.isBlank(request.getHeader(ACCEPT))) { acceptedTypes = Collections.singletonList(MarmottaHttpUtils.parseContentType(RDFXML.getDefaultMIMEType())); } else { - // MARMOTTA-606 - retrieve all headers instead of the first one - acceptedTypes = MarmottaHttpUtils.parseAcceptHeader(request.getHeaders(ACCEPT)); + acceptedTypes = MarmottaHttpUtils.parseAcceptHeader(request.getHeader(ACCEPT)); } ContentType _bestType = null; From 8ddcb7c5767b685905ba40d916720d413f4870a9 Mon Sep 17 00:00:00 2001 From: cuent Date: Thu, 3 May 2018 14:45:01 -0500 Subject: [PATCH 3/3] Fix inverse selector when provided a path. Signed-of-by: Xavier Sumba --- .../ldpath/model/selectors/ReversePropertySelector.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/ldpath/ldpath-core/src/main/java/org/apache/marmotta/ldpath/model/selectors/ReversePropertySelector.java b/libraries/ldpath/ldpath-core/src/main/java/org/apache/marmotta/ldpath/model/selectors/ReversePropertySelector.java index 4411ec57e..28d3a8c1d 100644 --- a/libraries/ldpath/ldpath-core/src/main/java/org/apache/marmotta/ldpath/model/selectors/ReversePropertySelector.java +++ b/libraries/ldpath/ldpath-core/src/main/java/org/apache/marmotta/ldpath/model/selectors/ReversePropertySelector.java @@ -56,7 +56,7 @@ public ReversePropertySelector(Node property) { public Collection select(RDFBackend rdfBackend, Node context, List path, Map> resultPaths) { if(rdfBackend.isURI(context) || rdfBackend.isBlank(context)) { if(path != null && resultPaths != null) { - Collection results = rdfBackend.listSubjects(context, property); + Collection results = rdfBackend.listSubjects(property, context); for(Node n :results) { resultPaths.put(n, new ImmutableList.Builder().addAll(path).add(context).add(n).build()); }