Package org.eclipse.rdf4j.http.client
Class SPARQLProtocolSession
- java.lang.Object
-
- org.eclipse.rdf4j.http.client.SPARQLProtocolSession
-
- All Implemented Interfaces:
java.lang.AutoCloseable
,HttpClientDependent
- Direct Known Subclasses:
RDF4JProtocolSession
public class SPARQLProtocolSession extends java.lang.Object implements HttpClientDependent, java.lang.AutoCloseable
The SPARQLProtocolSession provides low level HTTP methods for communication with SPARQL endpoints. All methods are compliant to the SPARQL 1.1 Protocol W3C Recommendation. For both Tuple and Graph queries there is a variant which parses the result in the background, seeBackgroundTupleResult
andBackgroundGraphResult
. For boolean queries the result is parsed in the current thread. All methods in this class guarantee that HTTP connections are closed properly and returned to the connection pool. The methods in this class are not guaranteed to be thread-safe. Functionality specific to the RDF4J HTTP protocol can be found inRDF4JProtocolSession
(which is used by HTTPRepository).
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<java.lang.String,java.lang.String>
additionalHttpHeaders
private BackgroundResultExecutor
background
static int
DEFAULT_MAXIMUM_URL_LENGTH
The default value of the threshold for URL length, beyond which we use the POST method for SPARQL query requests.private org.apache.http.client.HttpClient
httpClient
private org.apache.http.client.protocol.HttpClientContext
httpContext
(package private) static org.slf4j.Logger
logger
static int
MAXIMUM_URL_LENGTH
Deprecated.useDEFAULT_MAXIMUM_URL_LENGTH
instead.static java.lang.String
MAXIMUM_URL_LENGTH_PARAM
System property for configuration of URL length threshold:rdf4j.sparql.url.maxlength
.private int
maximumUrlLength
The threshold for URL length, beyond which we use the POST method.private org.apache.http.params.HttpParams
params
private ParserConfig
parserConfig
private boolean
passThroughEnabled
private BooleanQueryResultFormat
preferredBQRFormat
private RDFFormat
preferredRDFFormat
private TupleQueryResultFormat
preferredTQRFormat
private java.lang.String
queryURL
private java.lang.String
updateURL
protected static java.nio.charset.Charset
UTF8
private ValueFactory
valueFactory
-
Constructor Summary
Constructors Constructor Description SPARQLProtocolSession(org.apache.http.client.HttpClient client, java.util.concurrent.ExecutorService executor)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
close()
private static boolean
contentTypeIs(org.apache.http.HttpResponse response, java.lang.String contentType)
protected org.apache.http.HttpResponse
execute(org.apache.http.client.methods.HttpUriRequest method)
protected void
executeNoContent(org.apache.http.client.methods.HttpUriRequest method)
protected org.apache.http.HttpResponse
executeOK(org.apache.http.client.methods.HttpUriRequest method)
Convenience method to deal with HTTP level errors of tuple, graph and boolean queries in the same way.java.util.Map<java.lang.String,java.lang.String>
getAdditionalHttpHeaders()
Get the additional HTTP headers which will be usedprotected TupleQueryResult
getBackgroundTupleQueryResult(org.apache.http.client.methods.HttpUriRequest method, java.lang.ref.WeakReference<?> callerRef)
Deprecated.WeakReference> callerRef argument will be removedprotected boolean
getBoolean(org.apache.http.client.methods.HttpUriRequest method)
Parse the response in this thread using a suitableBooleanQueryResultParser
.long
getConnectionTimeout()
Gets the http connection read timeout in milliseconds.(package private) static RDFFormat
getContentTypeSerialisation(org.apache.http.HttpResponse response)
protected ErrorInfo
getErrorInfo(org.apache.http.HttpResponse response)
org.apache.http.client.HttpClient
getHttpClient()
HttpClient
that has been assigned or has been used by this object.protected org.apache.http.protocol.HttpContext
getHttpContext()
Get theHttpContext
used for sending HTTP requests.ParserConfig
getParserConfig()
BooleanQueryResultFormat
getPreferredBooleanQueryResultFormat()
Gets the preferredBooleanQueryResultFormat
for encoding boolean query results.RDFFormat
getPreferredRDFFormat()
Gets the preferredRDFFormat
for encoding RDF documents.TupleQueryResultFormat
getPreferredTupleQueryResultFormat()
Gets the preferredTupleQueryResultFormat
for encoding tuple query results.protected org.apache.http.client.methods.HttpUriRequest
getQueryMethod(QueryLanguage ql, java.lang.String query, java.lang.String baseURI, Dataset dataset, boolean includeInferred, int maxQueryTime, Binding... bindings)
protected java.util.List<org.apache.http.NameValuePair>
getQueryMethodParameters(QueryLanguage ql, java.lang.String query, java.lang.String baseURI, Dataset dataset, boolean includeInferred, int maxQueryTime, Binding... bindings)
java.lang.String
getQueryURL()
protected void
getRDF(org.apache.http.client.methods.HttpUriRequest method, RDFHandler handler, boolean requireContext)
Parse the response in this thread using the providedRDFHandler
.protected GraphQueryResult
getRDFBackground(org.apache.http.client.methods.HttpUriRequest method, boolean requireContext, java.lang.ref.WeakReference<?> callerRef)
Deprecated.WeakReference> callerRef argument will be removed(package private) java.util.Optional<java.nio.charset.Charset>
getResponseCharset(org.apache.http.HttpResponse response)
Gets the character encoding specified in the HTTP headers of the supplied response, if any.protected java.lang.String
getResponseMIMEType(org.apache.http.HttpResponse method)
Gets the MIME type specified in the response headers of the supplied method, if any.protected void
getTupleQueryResult(org.apache.http.client.methods.HttpUriRequest method, TupleQueryResultHandler handler)
Parse the response in this thread using the providedTupleQueryResultHandler
.protected org.apache.http.client.methods.HttpUriRequest
getUpdateMethod(QueryLanguage ql, java.lang.String update, java.lang.String baseURI, Dataset dataset, boolean includeInferred, int maxQueryTime, Binding... bindings)
protected org.apache.http.client.methods.HttpUriRequest
getUpdateMethod(QueryLanguage ql, java.lang.String update, java.lang.String baseURI, Dataset dataset, boolean includeInferred, Binding... bindings)
protected java.util.List<org.apache.http.NameValuePair>
getUpdateMethodParameters(QueryLanguage ql, java.lang.String update, java.lang.String baseURI, Dataset dataset, boolean includeInferred, int maxQueryTime, Binding... bindings)
protected java.util.List<org.apache.http.NameValuePair>
getUpdateMethodParameters(QueryLanguage ql, java.lang.String update, java.lang.String baseURI, Dataset dataset, boolean includeInferred, Binding... bindings)
java.lang.String
getUpdateURL()
ValueFactory
getValueFactory()
boolean
isPassThroughEnabled()
Indicates if direct pass-through of the endpoint result to the suppliedSink
is enabled.private boolean
passThrough(org.apache.http.HttpResponse response, FileFormat responseFormat, Sink sink)
Pass through response content directly to the supplied sink if possible.boolean
sendBooleanQuery(QueryLanguage ql, java.lang.String query, java.lang.String baseURI, Dataset dataset, boolean includeInferred, int maxQueryTime, Binding... bindings)
boolean
sendBooleanQuery(QueryLanguage ql, java.lang.String query, Dataset dataset, boolean includeInferred, Binding... bindings)
private org.apache.http.HttpResponse
sendBooleanQueryViaHttp(org.apache.http.client.methods.HttpUriRequest method, java.util.Set<QueryResultFormat> booleanFormats)
GraphQueryResult
sendGraphQuery(QueryLanguage ql, java.lang.String query, java.lang.String baseURI, Dataset dataset, boolean includeInferred, int maxQueryTime, java.lang.ref.WeakReference<?> callerRef, Binding... bindings)
Deprecated.WeakReference> callerRef argument will be removedvoid
sendGraphQuery(QueryLanguage ql, java.lang.String query, java.lang.String baseURI, Dataset dataset, boolean includeInferred, int maxQueryTime, RDFHandler handler, Binding... bindings)
GraphQueryResult
sendGraphQuery(QueryLanguage ql, java.lang.String query, Dataset dataset, boolean includeInferred, java.lang.ref.WeakReference<?> callerRef, Binding... bindings)
Deprecated.WeakReference> callerRef argument will be removedvoid
sendGraphQuery(QueryLanguage ql, java.lang.String query, Dataset dataset, boolean includeInferred, RDFHandler handler, Binding... bindings)
private org.apache.http.HttpResponse
sendGraphQueryViaHttp(org.apache.http.client.methods.HttpUriRequest method, boolean requireContext, java.util.Set<RDFFormat> rdfFormats)
TupleQueryResult
sendTupleQuery(QueryLanguage ql, java.lang.String query, java.lang.String baseURI, Dataset dataset, boolean includeInferred, int maxQueryTime, java.lang.ref.WeakReference<?> callerRef, Binding... bindings)
Deprecated.WeakReference> callerRef argument will be removedvoid
sendTupleQuery(QueryLanguage ql, java.lang.String query, java.lang.String baseURI, Dataset dataset, boolean includeInferred, int maxQueryTime, TupleQueryResultHandler handler, Binding... bindings)
TupleQueryResult
sendTupleQuery(QueryLanguage ql, java.lang.String query, Dataset dataset, boolean includeInferred, java.lang.ref.WeakReference<?> callerRef, Binding... bindings)
Deprecated.WeakReference> callerRef argument will be removedprivate org.apache.http.HttpResponse
sendTupleQueryViaHttp(org.apache.http.client.methods.HttpUriRequest method, java.util.Set<QueryResultFormat> tqrFormats)
Send the tuple query via HTTP and throws an exception in case anything goes wrong, i.e.void
sendUpdate(QueryLanguage ql, java.lang.String update, java.lang.String baseURI, Dataset dataset, boolean includeInferred, int maxQueryTime, Binding... bindings)
void
sendUpdate(QueryLanguage ql, java.lang.String update, java.lang.String baseURI, Dataset dataset, boolean includeInferred, Binding... bindings)
void
setAdditionalHttpHeaders(java.util.Map<java.lang.String,java.lang.String> additionalHttpHeaders)
Set additional HTTP headers to be included in every request to the server, which may be required for certain unusual server configurations.void
setConnectionTimeout(long timeout)
Sets the http connection read timeout.void
setHttpClient(org.apache.http.client.HttpClient httpClient)
Assign anHttpClient
that this object should use.void
setParserConfig(ParserConfig parserConfig)
Sets the parser configuration used to process HTTP response data.void
setPassThroughEnabled(boolean passThroughEnabled)
Configure direct pass-through of the endpoint result to the suppliedSink
.void
setPreferredBooleanQueryResultFormat(BooleanQueryResultFormat format)
Sets the preferred format for encoding boolean query results.void
setPreferredRDFFormat(RDFFormat format)
Sets the preferred format for encoding RDF documents.void
setPreferredTupleQueryResultFormat(TupleQueryResultFormat format)
Sets the preferred format for encoding tuple query results.protected void
setQueryURL(java.lang.String queryURL)
protected void
setUpdateURL(java.lang.String updateURL)
void
setUsernameAndPassword(java.lang.String username, java.lang.String password)
Set the username and password for authentication with the remote server.protected void
setUsernameAndPasswordForUrl(java.lang.String username, java.lang.String password, java.lang.String url)
void
setValueFactory(ValueFactory valueFactory)
protected boolean
shouldUsePost(java.lang.String fullQueryUrl)
Return whether the provided query should use POST (otherwise use GET)
-
-
-
Field Detail
-
UTF8
protected static final java.nio.charset.Charset UTF8
-
DEFAULT_MAXIMUM_URL_LENGTH
public static final int DEFAULT_MAXIMUM_URL_LENGTH
The default value of the threshold for URL length, beyond which we use the POST method for SPARQL query requests. The default is based on the lowest common denominator for various web servers.- See Also:
- Constant Field Values
-
MAXIMUM_URL_LENGTH
@Deprecated public static final int MAXIMUM_URL_LENGTH
Deprecated.useDEFAULT_MAXIMUM_URL_LENGTH
instead.- See Also:
- Constant Field Values
-
MAXIMUM_URL_LENGTH_PARAM
public static final java.lang.String MAXIMUM_URL_LENGTH_PARAM
System property for configuration of URL length threshold:rdf4j.sparql.url.maxlength
. A threshold of 0 (or a negative value) means that the POST method is used for every SPARQL query request.- See Also:
- Constant Field Values
-
maximumUrlLength
private final int maximumUrlLength
The threshold for URL length, beyond which we use the POST method. A threshold of 0 (or a negative value) means that the POST method is used for every SPARQL query request.
-
logger
static final org.slf4j.Logger logger
-
valueFactory
private ValueFactory valueFactory
-
queryURL
private java.lang.String queryURL
-
updateURL
private java.lang.String updateURL
-
httpClient
private org.apache.http.client.HttpClient httpClient
-
background
private final BackgroundResultExecutor background
-
httpContext
private final org.apache.http.client.protocol.HttpClientContext httpContext
-
params
private org.apache.http.params.HttpParams params
-
parserConfig
private ParserConfig parserConfig
-
preferredTQRFormat
private TupleQueryResultFormat preferredTQRFormat
-
preferredBQRFormat
private BooleanQueryResultFormat preferredBQRFormat
-
preferredRDFFormat
private RDFFormat preferredRDFFormat
-
additionalHttpHeaders
private java.util.Map<java.lang.String,java.lang.String> additionalHttpHeaders
-
passThroughEnabled
private boolean passThroughEnabled
-
-
Method Detail
-
getHttpClient
public final org.apache.http.client.HttpClient getHttpClient()
Description copied from interface:HttpClientDependent
HttpClient
that has been assigned or has been used by this object. The life cycle might not be or might be tied to this object, depending on whetherHttpClient
was passed to or created by this object respectively.- Specified by:
getHttpClient
in interfaceHttpClientDependent
- Returns:
- an
HttpClient
instance or null
-
setHttpClient
public void setHttpClient(org.apache.http.client.HttpClient httpClient)
Description copied from interface:HttpClientDependent
Assign anHttpClient
that this object should use. The life cycle of the givenHttpClient
is independent of this object. Closing or shutting down this object does not have any impact on the given client. Callers must ensure that the given client is properly closed elsewhere.- Specified by:
setHttpClient
in interfaceHttpClientDependent
-
setValueFactory
public void setValueFactory(ValueFactory valueFactory)
-
getValueFactory
public ValueFactory getValueFactory()
-
setQueryURL
protected void setQueryURL(java.lang.String queryURL)
-
setUpdateURL
protected void setUpdateURL(java.lang.String updateURL)
-
setPreferredTupleQueryResultFormat
public void setPreferredTupleQueryResultFormat(TupleQueryResultFormat format)
Sets the preferred format for encoding tuple query results.- Parameters:
format
- The preferredTupleQueryResultFormat
, or null to indicate no specific format is preferred.
-
getPreferredTupleQueryResultFormat
public TupleQueryResultFormat getPreferredTupleQueryResultFormat()
Gets the preferredTupleQueryResultFormat
for encoding tuple query results. TheSPARQL/XML
format is preferred by default.- Returns:
- The preferred format, of null if no specific format is preferred.
-
setPreferredRDFFormat
public void setPreferredRDFFormat(RDFFormat format)
Sets the preferred format for encoding RDF documents.- Parameters:
format
- The preferredRDFFormat
, or null to indicate no specific format is preferred.
-
getPreferredRDFFormat
public RDFFormat getPreferredRDFFormat()
- Returns:
- The preferred format, of null if no specific format is preferred.
-
setPreferredBooleanQueryResultFormat
public void setPreferredBooleanQueryResultFormat(BooleanQueryResultFormat format)
Sets the preferred format for encoding boolean query results.- Parameters:
format
- The preferredBooleanQueryResultFormat
, or null to indicate no specific format is preferred.
-
getPreferredBooleanQueryResultFormat
public BooleanQueryResultFormat getPreferredBooleanQueryResultFormat()
Gets the preferredBooleanQueryResultFormat
for encoding boolean query results. Thebinary
format is preferred by default.- Returns:
- The preferred format, of null if no specific format is preferred.
-
setUsernameAndPassword
public void setUsernameAndPassword(java.lang.String username, java.lang.String password)
Set the username and password for authentication with the remote server.- Parameters:
username
- the usernamepassword
- the password
-
setUsernameAndPasswordForUrl
protected void setUsernameAndPasswordForUrl(java.lang.String username, java.lang.String password, java.lang.String url)
-
getQueryURL
public java.lang.String getQueryURL()
-
getUpdateURL
public java.lang.String getUpdateURL()
-
close
public void close()
- Specified by:
close
in interfacejava.lang.AutoCloseable
-
sendTupleQuery
@Deprecated(since="4.1.2") public TupleQueryResult sendTupleQuery(QueryLanguage ql, java.lang.String query, Dataset dataset, boolean includeInferred, java.lang.ref.WeakReference<?> callerRef, Binding... bindings) throws java.io.IOException, RepositoryException, MalformedQueryException, UnauthorizedException, QueryInterruptedException
Deprecated.WeakReference> callerRef argument will be removed- Throws:
java.io.IOException
RepositoryException
MalformedQueryException
UnauthorizedException
QueryInterruptedException
-
sendTupleQuery
@Deprecated(since="4.1.2") public TupleQueryResult sendTupleQuery(QueryLanguage ql, java.lang.String query, java.lang.String baseURI, Dataset dataset, boolean includeInferred, int maxQueryTime, java.lang.ref.WeakReference<?> callerRef, Binding... bindings) throws java.io.IOException, RepositoryException, MalformedQueryException, UnauthorizedException, QueryInterruptedException
Deprecated.WeakReference> callerRef argument will be removed- Throws:
java.io.IOException
RepositoryException
MalformedQueryException
UnauthorizedException
QueryInterruptedException
-
sendTupleQuery
public void sendTupleQuery(QueryLanguage ql, java.lang.String query, java.lang.String baseURI, Dataset dataset, boolean includeInferred, int maxQueryTime, TupleQueryResultHandler handler, Binding... bindings) throws java.io.IOException, TupleQueryResultHandlerException, RepositoryException, MalformedQueryException, UnauthorizedException, QueryInterruptedException
- Throws:
java.io.IOException
TupleQueryResultHandlerException
RepositoryException
MalformedQueryException
UnauthorizedException
QueryInterruptedException
-
sendUpdate
public void sendUpdate(QueryLanguage ql, java.lang.String update, java.lang.String baseURI, Dataset dataset, boolean includeInferred, Binding... bindings) throws java.io.IOException, RepositoryException, MalformedQueryException, UnauthorizedException, QueryInterruptedException
- Throws:
java.io.IOException
RepositoryException
MalformedQueryException
UnauthorizedException
QueryInterruptedException
-
sendUpdate
public void sendUpdate(QueryLanguage ql, java.lang.String update, java.lang.String baseURI, Dataset dataset, boolean includeInferred, int maxQueryTime, Binding... bindings) throws java.io.IOException, RepositoryException, MalformedQueryException, UnauthorizedException, QueryInterruptedException
- Throws:
java.io.IOException
RepositoryException
MalformedQueryException
UnauthorizedException
QueryInterruptedException
-
sendGraphQuery
@Deprecated(since="4.1.2") public GraphQueryResult sendGraphQuery(QueryLanguage ql, java.lang.String query, Dataset dataset, boolean includeInferred, java.lang.ref.WeakReference<?> callerRef, Binding... bindings) throws java.io.IOException, RepositoryException, MalformedQueryException, UnauthorizedException, QueryInterruptedException
Deprecated.WeakReference> callerRef argument will be removed- Throws:
java.io.IOException
RepositoryException
MalformedQueryException
UnauthorizedException
QueryInterruptedException
-
sendGraphQuery
@Deprecated(since="4.1.2") public GraphQueryResult sendGraphQuery(QueryLanguage ql, java.lang.String query, java.lang.String baseURI, Dataset dataset, boolean includeInferred, int maxQueryTime, java.lang.ref.WeakReference<?> callerRef, Binding... bindings) throws java.io.IOException, RepositoryException, MalformedQueryException, UnauthorizedException, QueryInterruptedException
Deprecated.WeakReference> callerRef argument will be removed- Throws:
java.io.IOException
RepositoryException
MalformedQueryException
UnauthorizedException
QueryInterruptedException
-
sendGraphQuery
public void sendGraphQuery(QueryLanguage ql, java.lang.String query, Dataset dataset, boolean includeInferred, RDFHandler handler, Binding... bindings) throws java.io.IOException, RDFHandlerException, RepositoryException, MalformedQueryException, UnauthorizedException, QueryInterruptedException
- Throws:
java.io.IOException
RDFHandlerException
RepositoryException
MalformedQueryException
UnauthorizedException
QueryInterruptedException
-
sendGraphQuery
public void sendGraphQuery(QueryLanguage ql, java.lang.String query, java.lang.String baseURI, Dataset dataset, boolean includeInferred, int maxQueryTime, RDFHandler handler, Binding... bindings) throws java.io.IOException, RDFHandlerException, RepositoryException, MalformedQueryException, UnauthorizedException, QueryInterruptedException
- Throws:
java.io.IOException
RDFHandlerException
RepositoryException
MalformedQueryException
UnauthorizedException
QueryInterruptedException
-
sendBooleanQuery
public boolean sendBooleanQuery(QueryLanguage ql, java.lang.String query, Dataset dataset, boolean includeInferred, Binding... bindings) throws java.io.IOException, RepositoryException, MalformedQueryException, UnauthorizedException, QueryInterruptedException
- Throws:
java.io.IOException
RepositoryException
MalformedQueryException
UnauthorizedException
QueryInterruptedException
-
sendBooleanQuery
public boolean sendBooleanQuery(QueryLanguage ql, java.lang.String query, java.lang.String baseURI, Dataset dataset, boolean includeInferred, int maxQueryTime, Binding... bindings) throws java.io.IOException, RepositoryException, MalformedQueryException, UnauthorizedException, QueryInterruptedException
- Throws:
java.io.IOException
RepositoryException
MalformedQueryException
UnauthorizedException
QueryInterruptedException
-
getAdditionalHttpHeaders
public java.util.Map<java.lang.String,java.lang.String> getAdditionalHttpHeaders()
Get the additional HTTP headers which will be used- Returns:
- a read-only view of the additional HTTP headers which will be included in every request to the server.
-
setAdditionalHttpHeaders
public void setAdditionalHttpHeaders(java.util.Map<java.lang.String,java.lang.String> additionalHttpHeaders)
Set additional HTTP headers to be included in every request to the server, which may be required for certain unusual server configurations.- Parameters:
additionalHttpHeaders
- a map containing pairs of header names and values. May be null
-
getQueryMethod
protected org.apache.http.client.methods.HttpUriRequest getQueryMethod(QueryLanguage ql, java.lang.String query, java.lang.String baseURI, Dataset dataset, boolean includeInferred, int maxQueryTime, Binding... bindings)
-
shouldUsePost
protected boolean shouldUsePost(java.lang.String fullQueryUrl)
Return whether the provided query should use POST (otherwise use GET)- Parameters:
fullQueryUrl
- the complete URL, including hostname and all HTTP query parameters
-
getUpdateMethod
protected org.apache.http.client.methods.HttpUriRequest getUpdateMethod(QueryLanguage ql, java.lang.String update, java.lang.String baseURI, Dataset dataset, boolean includeInferred, Binding... bindings)
-
getUpdateMethod
protected org.apache.http.client.methods.HttpUriRequest getUpdateMethod(QueryLanguage ql, java.lang.String update, java.lang.String baseURI, Dataset dataset, boolean includeInferred, int maxQueryTime, Binding... bindings)
-
getQueryMethodParameters
protected java.util.List<org.apache.http.NameValuePair> getQueryMethodParameters(QueryLanguage ql, java.lang.String query, java.lang.String baseURI, Dataset dataset, boolean includeInferred, int maxQueryTime, Binding... bindings)
-
getUpdateMethodParameters
protected java.util.List<org.apache.http.NameValuePair> getUpdateMethodParameters(QueryLanguage ql, java.lang.String update, java.lang.String baseURI, Dataset dataset, boolean includeInferred, Binding... bindings)
-
getUpdateMethodParameters
protected java.util.List<org.apache.http.NameValuePair> getUpdateMethodParameters(QueryLanguage ql, java.lang.String update, java.lang.String baseURI, Dataset dataset, boolean includeInferred, int maxQueryTime, Binding... bindings)
-
getBackgroundTupleQueryResult
@Deprecated(since="4.1.2") protected TupleQueryResult getBackgroundTupleQueryResult(org.apache.http.client.methods.HttpUriRequest method, java.lang.ref.WeakReference<?> callerRef) throws RepositoryException, QueryInterruptedException, MalformedQueryException, java.io.IOException
Deprecated.WeakReference> callerRef argument will be removedParse the response in a background thread. HTTP connections are dealt with in theBackgroundTupleResult
or (in the error-case) in this method.- Throws:
RepositoryException
QueryInterruptedException
MalformedQueryException
java.io.IOException
-
getTupleQueryResult
protected void getTupleQueryResult(org.apache.http.client.methods.HttpUriRequest method, TupleQueryResultHandler handler) throws java.io.IOException, TupleQueryResultHandlerException, RepositoryException, MalformedQueryException, UnauthorizedException, QueryInterruptedException
Parse the response in this thread using the providedTupleQueryResultHandler
. All HTTP connections are closed and released in this method- Throws:
java.io.IOException
TupleQueryResultHandlerException
RepositoryException
MalformedQueryException
UnauthorizedException
QueryInterruptedException
-
sendTupleQueryViaHttp
private org.apache.http.HttpResponse sendTupleQueryViaHttp(org.apache.http.client.methods.HttpUriRequest method, java.util.Set<QueryResultFormat> tqrFormats) throws RepositoryException, java.io.IOException, QueryInterruptedException, MalformedQueryException
Send the tuple query via HTTP and throws an exception in case anything goes wrong, i.e. only for HTTP 200 the method returns without exception. If HTTP status code is not equal to 200, the request is aborted, however pooled connections are not released.- Parameters:
method
-- Throws:
RepositoryException
org.apache.http.HttpException
java.io.IOException
QueryInterruptedException
MalformedQueryException
-
getRDFBackground
@Deprecated(since="4.1.2") protected GraphQueryResult getRDFBackground(org.apache.http.client.methods.HttpUriRequest method, boolean requireContext, java.lang.ref.WeakReference<?> callerRef) throws java.io.IOException, RDFHandlerException, RepositoryException, MalformedQueryException, UnauthorizedException, QueryInterruptedException
Deprecated.WeakReference> callerRef argument will be removedParse the response in a background thread. HTTP connections are dealt with in theBackgroundGraphResult
or (in the error-case) in this method.- Throws:
java.io.IOException
RDFHandlerException
RepositoryException
MalformedQueryException
UnauthorizedException
QueryInterruptedException
-
getRDF
protected void getRDF(org.apache.http.client.methods.HttpUriRequest method, RDFHandler handler, boolean requireContext) throws java.io.IOException, RDFHandlerException, RepositoryException, MalformedQueryException, UnauthorizedException, QueryInterruptedException
Parse the response in this thread using the providedRDFHandler
. All HTTP connections are closed and released in this method- Throws:
java.io.IOException
RDFHandlerException
RepositoryException
MalformedQueryException
UnauthorizedException
QueryInterruptedException
-
passThrough
private boolean passThrough(org.apache.http.HttpResponse response, FileFormat responseFormat, Sink sink) throws java.io.IOException
Pass through response content directly to the supplied sink if possible.- Parameters:
response
- theHttpResponse
with the content.responseFormat
- the format of the response.sink
- theSink
to pass the content through to.- Returns:
true
if the content was passed through,false
otherwise.- Throws:
java.io.IOException
-
sendGraphQueryViaHttp
private org.apache.http.HttpResponse sendGraphQueryViaHttp(org.apache.http.client.methods.HttpUriRequest method, boolean requireContext, java.util.Set<RDFFormat> rdfFormats) throws RepositoryException, java.io.IOException, QueryInterruptedException, MalformedQueryException
- Throws:
RepositoryException
java.io.IOException
QueryInterruptedException
MalformedQueryException
-
getBoolean
protected boolean getBoolean(org.apache.http.client.methods.HttpUriRequest method) throws java.io.IOException, RDF4JException
Parse the response in this thread using a suitableBooleanQueryResultParser
. All HTTP connections are closed and released in this method- Throws:
RDF4JException
java.io.IOException
-
sendBooleanQueryViaHttp
private org.apache.http.HttpResponse sendBooleanQueryViaHttp(org.apache.http.client.methods.HttpUriRequest method, java.util.Set<QueryResultFormat> booleanFormats) throws java.io.IOException, RDF4JException
- Throws:
java.io.IOException
RDF4JException
-
executeOK
protected org.apache.http.HttpResponse executeOK(org.apache.http.client.methods.HttpUriRequest method) throws java.io.IOException, RDF4JException
Convenience method to deal with HTTP level errors of tuple, graph and boolean queries in the same way. This method aborts the HTTP connection.- Parameters:
method
-- Throws:
RDF4JException
java.io.IOException
-
executeNoContent
protected void executeNoContent(org.apache.http.client.methods.HttpUriRequest method) throws java.io.IOException, RDF4JException
- Throws:
java.io.IOException
RDF4JException
-
execute
protected org.apache.http.HttpResponse execute(org.apache.http.client.methods.HttpUriRequest method) throws java.io.IOException, RDF4JException
- Throws:
java.io.IOException
RDF4JException
-
getContentTypeSerialisation
static RDFFormat getContentTypeSerialisation(org.apache.http.HttpResponse response)
-
contentTypeIs
private static boolean contentTypeIs(org.apache.http.HttpResponse response, java.lang.String contentType)
-
getResponseMIMEType
protected java.lang.String getResponseMIMEType(org.apache.http.HttpResponse method) throws java.io.IOException
Gets the MIME type specified in the response headers of the supplied method, if any. For example, if the response headers contain Content-Type: application/xml;charset=UTF-8, this method will return application/xml as the MIME type.- Parameters:
method
- The method to get the reponse MIME type from.- Returns:
- The response MIME type, or null if not available.
- Throws:
java.io.IOException
-
getResponseCharset
java.util.Optional<java.nio.charset.Charset> getResponseCharset(org.apache.http.HttpResponse response)
Gets the character encoding specified in the HTTP headers of the supplied response, if any. For example, if the response headers contain Content-Type: application/xml;charset=UTF-8, this method will returnUTF-8
as the character encoding.- Parameters:
response
- the response to get the character encoding from.- Returns:
- the response character encoding,
Optional.empty()
if it can not be determined.
-
getErrorInfo
protected ErrorInfo getErrorInfo(org.apache.http.HttpResponse response) throws RepositoryException
- Throws:
RepositoryException
-
setParserConfig
public void setParserConfig(ParserConfig parserConfig)
Sets the parser configuration used to process HTTP response data.- Parameters:
parserConfig
- The parserConfig to set.
-
getParserConfig
public ParserConfig getParserConfig()
- Returns:
- Returns the parser configuration used to process HTTP response data.
-
getConnectionTimeout
public long getConnectionTimeout()
Gets the http connection read timeout in milliseconds.
-
setConnectionTimeout
public void setConnectionTimeout(long timeout)
Sets the http connection read timeout.- Parameters:
timeout
- timeout in milliseconds. Zero sets to infinity.
-
getHttpContext
protected org.apache.http.protocol.HttpContext getHttpContext()
Get theHttpContext
used for sending HTTP requests.- Returns:
- the
HttpContext
instance used for all protocol session requests.
-
isPassThroughEnabled
public boolean isPassThroughEnabled()
Indicates if direct pass-through of the endpoint result to the suppliedSink
is enabled.- Returns:
- the passThroughEnabled setting.
-
setPassThroughEnabled
public void setPassThroughEnabled(boolean passThroughEnabled)
Configure direct pass-through of the endpoint result to the suppliedSink
.If not explicitly configured, the setting defaults to
true
.- Parameters:
passThroughEnabled
- the passThroughEnabled to set.
-
-