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 2018/02/27 23:10:29 UTC
[09/24] jena git commit: Direct setting of Accept header.
Direct setting of Accept header.
Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/63e3dbe7
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/63e3dbe7
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/63e3dbe7
Branch: refs/heads/master
Commit: 63e3dbe79f9f61b4ffb7e17e320570d562ce0a9d
Parents: bd955ee
Author: Andy Seaborne <an...@apache.org>
Authored: Tue Feb 20 19:12:19 2018 +0000
Committer: Andy Seaborne <an...@apache.org>
Committed: Tue Feb 20 19:12:19 2018 +0000
----------------------------------------------------------------------
.../sparql/engine/http/QueryEngineHTTP.java | 26 +++++++++++++++++---
1 file changed, 22 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jena/blob/63e3dbe7/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 d793143..543e3a6 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
@@ -89,6 +89,9 @@ public class QueryEngineHTTP implements QueryExecution {
private String constructContentType = defaultConstructHeader() ;
private String datasetContentType = defaultConstructDatasetHeader() ;
+ // If this is non-null, it overrides the ???ContentType choice.
+ private String acceptHeader = null;
+
// Received content type
private String httpResponseContentType = null ;
/**
@@ -341,7 +344,7 @@ public class QueryEngineHTTP implements QueryExecution {
private ResultSet execResultSetInner() {
HttpQuery httpQuery = makeHttpQuery();
- httpQuery.setAccept(selectContentType);
+ httpQuery.setAccept(chooseAcceptHeader(acceptHeader, selectContentType));
InputStream in = httpQuery.exec();
if (false) {
@@ -376,6 +379,13 @@ public class QueryEngineHTTP implements QueryExecution {
return result;
}
+ // XXX Move
+ private static String chooseAcceptHeader(String acceptHeader, String contentType) {
+ if ( acceptHeader != null )
+ return acceptHeader;
+ return contentType;
+ }
+
@Override
public Model execConstruct() {
return execConstruct(GraphFactory.makeJenaDefaultModel());
@@ -458,7 +468,7 @@ public class QueryEngineHTTP implements QueryExecution {
private Pair<InputStream, Lang> execConstructWorker(String contentType) {
checkNotClosed() ;
HttpQuery httpQuery = makeHttpQuery();
- httpQuery.setAccept(contentType);
+ httpQuery.setAccept(chooseAcceptHeader(acceptHeader, contentType));
InputStream in = httpQuery.exec();
// Don't assume the endpoint actually gives back the content type we
@@ -483,7 +493,7 @@ public class QueryEngineHTTP implements QueryExecution {
public boolean execAsk() {
checkNotClosed() ;
HttpQuery httpQuery = makeHttpQuery();
- httpQuery.setAccept(askContentType);
+ httpQuery.setAccept(chooseAcceptHeader(acceptHeader, askContentType));
try(InputStream in = httpQuery.exec()) {
// Don't assume the endpoint actually gives back the content type we
// asked for
@@ -883,5 +893,13 @@ public class QueryEngineHTTP implements QueryExecution {
sBuff.append(str) ;
if ( v < 1 )
sBuff.append(";q=").append(v) ;
- }
+ }
+
+ /** Set the HTTP Accept header for the request.
+ * Unlike the {@code set??ContentType} operations, this is not checked
+ * for validity.
+ */
+ public void setAcceptHeader(String acceptHeader) {
+ this.acceptHeader = acceptHeader;
+ }
}
\ No newline at end of file