public class SPARQLProtocolSession extends Object implements HttpClientDependent, AutoCloseable
BackgroundTupleResult
and BackgroundGraphResult
. 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 in RDF4JProtocolSession
(which is used by
HTTPRepository).RDF4JProtocolSession
,
SPARQL 1.1 Protocol (W3C Recommendation)Modifier and Type | Field and Description |
---|---|
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.
|
static int |
MAXIMUM_URL_LENGTH
Deprecated.
use
DEFAULT_MAXIMUM_URL_LENGTH instead. |
static String |
MAXIMUM_URL_LENGTH_PARAM
System property for configuration of URL length threshold:
rdf4j.sparql.url.maxlength . |
protected static Charset |
UTF8 |
Constructor and Description |
---|
SPARQLProtocolSession(org.apache.http.client.HttpClient client,
ExecutorService executor) |
Modifier and Type | Method and Description |
---|---|
void |
close() |
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.
|
Map<String,String> |
getAdditionalHttpHeaders()
Get the additional HTTP headers which will be used
|
protected TupleQueryResult |
getBackgroundTupleQueryResult(org.apache.http.client.methods.HttpUriRequest method)
Parse the response in a background thread.
|
protected boolean |
getBoolean(org.apache.http.client.methods.HttpUriRequest method)
Parse the response in this thread using a suitable
BooleanQueryResultParser . |
long |
getConnectionTimeout()
Gets the http connection read timeout in milliseconds.
|
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. |
ParserConfig |
getParserConfig() |
BooleanQueryResultFormat |
getPreferredBooleanQueryResultFormat()
Gets the preferred
BooleanQueryResultFormat for encoding boolean query results. |
RDFFormat |
getPreferredRDFFormat()
Gets the preferred
RDFFormat for encoding RDF documents. |
TupleQueryResultFormat |
getPreferredTupleQueryResultFormat()
Gets the preferred
TupleQueryResultFormat for encoding tuple query results. |
protected org.apache.http.client.methods.HttpUriRequest |
getQueryMethod(QueryLanguage ql,
String query,
String baseURI,
Dataset dataset,
boolean includeInferred,
int maxQueryTime,
Binding... bindings) |
protected List<org.apache.http.NameValuePair> |
getQueryMethodParameters(QueryLanguage ql,
String query,
String baseURI,
Dataset dataset,
boolean includeInferred,
int maxQueryTime,
Binding... bindings) |
String |
getQueryURL() |
protected void |
getRDF(org.apache.http.client.methods.HttpUriRequest method,
RDFHandler handler,
boolean requireContext)
Parse the response in this thread using the provided
RDFHandler . |
protected GraphQueryResult |
getRDFBackground(org.apache.http.client.methods.HttpUriRequest method,
boolean requireContext)
Parse the response in a background thread.
|
protected 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 provided
TupleQueryResultHandler . |
protected org.apache.http.client.methods.HttpUriRequest |
getUpdateMethod(QueryLanguage ql,
String update,
String baseURI,
Dataset dataset,
boolean includeInferred,
Binding... bindings) |
protected org.apache.http.client.methods.HttpUriRequest |
getUpdateMethod(QueryLanguage ql,
String update,
String baseURI,
Dataset dataset,
boolean includeInferred,
int maxQueryTime,
Binding... bindings) |
protected List<org.apache.http.NameValuePair> |
getUpdateMethodParameters(QueryLanguage ql,
String update,
String baseURI,
Dataset dataset,
boolean includeInferred,
Binding... bindings) |
protected List<org.apache.http.NameValuePair> |
getUpdateMethodParameters(QueryLanguage ql,
String update,
String baseURI,
Dataset dataset,
boolean includeInferred,
int maxQueryTime,
Binding... bindings) |
String |
getUpdateURL() |
ValueFactory |
getValueFactory() |
boolean |
sendBooleanQuery(QueryLanguage ql,
String query,
Dataset dataset,
boolean includeInferred,
Binding... bindings) |
boolean |
sendBooleanQuery(QueryLanguage ql,
String query,
String baseURI,
Dataset dataset,
boolean includeInferred,
int maxQueryTime,
Binding... bindings) |
GraphQueryResult |
sendGraphQuery(QueryLanguage ql,
String query,
Dataset dataset,
boolean includeInferred,
Binding... bindings) |
void |
sendGraphQuery(QueryLanguage ql,
String query,
Dataset dataset,
boolean includeInferred,
RDFHandler handler,
Binding... bindings) |
GraphQueryResult |
sendGraphQuery(QueryLanguage ql,
String query,
String baseURI,
Dataset dataset,
boolean includeInferred,
int maxQueryTime,
Binding... bindings) |
void |
sendGraphQuery(QueryLanguage ql,
String query,
String baseURI,
Dataset dataset,
boolean includeInferred,
int maxQueryTime,
RDFHandler handler,
Binding... bindings) |
TupleQueryResult |
sendTupleQuery(QueryLanguage ql,
String query,
Dataset dataset,
boolean includeInferred,
Binding... bindings) |
TupleQueryResult |
sendTupleQuery(QueryLanguage ql,
String query,
String baseURI,
Dataset dataset,
boolean includeInferred,
int maxQueryTime,
Binding... bindings) |
void |
sendTupleQuery(QueryLanguage ql,
String query,
String baseURI,
Dataset dataset,
boolean includeInferred,
int maxQueryTime,
TupleQueryResultHandler handler,
Binding... bindings) |
void |
sendUpdate(QueryLanguage ql,
String update,
String baseURI,
Dataset dataset,
boolean includeInferred,
Binding... bindings) |
void |
sendUpdate(QueryLanguage ql,
String update,
String baseURI,
Dataset dataset,
boolean includeInferred,
int maxQueryTime,
Binding... bindings) |
void |
setAdditionalHttpHeaders(Map<String,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 an
HttpClient that this object should use. |
void |
setParserConfig(ParserConfig parserConfig)
Sets the parser configuration used to process HTTP response data.
|
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(String queryURL) |
protected void |
setUpdateURL(String updateURL) |
void |
setUsernameAndPassword(String username,
String password)
Set the username and password for authentication with the remote server.
|
protected void |
setUsernameAndPasswordForUrl(String username,
String password,
String url) |
void |
setValueFactory(ValueFactory valueFactory) |
protected boolean |
shouldUsePost(String fullQueryUrl)
Return whether the provided query should use POST (otherwise use GET)
|
protected static final Charset UTF8
public static final int DEFAULT_MAXIMUM_URL_LENGTH
@Deprecated public static final int MAXIMUM_URL_LENGTH
DEFAULT_MAXIMUM_URL_LENGTH
instead.public static final String MAXIMUM_URL_LENGTH_PARAM
rdf4j.sparql.url.maxlength
. A threshold of 0
(or a negative value) means that the POST method is used for every SPARQL query request.public SPARQLProtocolSession(org.apache.http.client.HttpClient client, ExecutorService executor)
public final org.apache.http.client.HttpClient getHttpClient()
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 whether HttpClient
was passed to or created by this object
respectively.getHttpClient
in interface HttpClientDependent
HttpClient
instance or nullpublic void setHttpClient(org.apache.http.client.HttpClient httpClient)
HttpClientDependent
HttpClient
that this object should use. The life cycle of the given HttpClient
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.setHttpClient
in interface HttpClientDependent
public void setValueFactory(ValueFactory valueFactory)
public ValueFactory getValueFactory()
protected void setQueryURL(String queryURL)
protected void setUpdateURL(String updateURL)
public void setPreferredTupleQueryResultFormat(TupleQueryResultFormat format)
binary
format is preferred by default.format
- The preferred TupleQueryResultFormat
, or null to indicate no specific format is
preferred.public TupleQueryResultFormat getPreferredTupleQueryResultFormat()
TupleQueryResultFormat
for encoding tuple query results.public void setPreferredRDFFormat(RDFFormat format)
Turtle
format is preferred by
default.format
- The preferred RDFFormat
, or null to indicate no specific format is preferred.public RDFFormat getPreferredRDFFormat()
RDFFormat
for encoding RDF documents.public void setPreferredBooleanQueryResultFormat(BooleanQueryResultFormat format)
binary
format is preferred by default.format
- The preferred BooleanQueryResultFormat
, or null to indicate no specific format is
preferred.public BooleanQueryResultFormat getPreferredBooleanQueryResultFormat()
BooleanQueryResultFormat
for encoding boolean query results.public void setUsernameAndPassword(String username, String password)
username
- the usernamepassword
- the passwordprotected void setUsernameAndPasswordForUrl(String username, String password, String url)
public String getQueryURL()
public String getUpdateURL()
public void close()
close
in interface AutoCloseable
public TupleQueryResult sendTupleQuery(QueryLanguage ql, String query, Dataset dataset, boolean includeInferred, Binding... bindings) throws IOException, RepositoryException, MalformedQueryException, UnauthorizedException, QueryInterruptedException
public TupleQueryResult sendTupleQuery(QueryLanguage ql, String query, String baseURI, Dataset dataset, boolean includeInferred, int maxQueryTime, Binding... bindings) throws IOException, RepositoryException, MalformedQueryException, UnauthorizedException, QueryInterruptedException
public void sendTupleQuery(QueryLanguage ql, String query, String baseURI, Dataset dataset, boolean includeInferred, int maxQueryTime, TupleQueryResultHandler handler, Binding... bindings) throws IOException, TupleQueryResultHandlerException, RepositoryException, MalformedQueryException, UnauthorizedException, QueryInterruptedException
public void sendUpdate(QueryLanguage ql, String update, String baseURI, Dataset dataset, boolean includeInferred, Binding... bindings) throws IOException, RepositoryException, MalformedQueryException, UnauthorizedException, QueryInterruptedException
public void sendUpdate(QueryLanguage ql, String update, String baseURI, Dataset dataset, boolean includeInferred, int maxQueryTime, Binding... bindings) throws IOException, RepositoryException, MalformedQueryException, UnauthorizedException, QueryInterruptedException
public GraphQueryResult sendGraphQuery(QueryLanguage ql, String query, Dataset dataset, boolean includeInferred, Binding... bindings) throws IOException, RepositoryException, MalformedQueryException, UnauthorizedException, QueryInterruptedException
public GraphQueryResult sendGraphQuery(QueryLanguage ql, String query, String baseURI, Dataset dataset, boolean includeInferred, int maxQueryTime, Binding... bindings) throws IOException, RepositoryException, MalformedQueryException, UnauthorizedException, QueryInterruptedException
public void sendGraphQuery(QueryLanguage ql, String query, Dataset dataset, boolean includeInferred, RDFHandler handler, Binding... bindings) throws IOException, RDFHandlerException, RepositoryException, MalformedQueryException, UnauthorizedException, QueryInterruptedException
public void sendGraphQuery(QueryLanguage ql, String query, String baseURI, Dataset dataset, boolean includeInferred, int maxQueryTime, RDFHandler handler, Binding... bindings) throws IOException, RDFHandlerException, RepositoryException, MalformedQueryException, UnauthorizedException, QueryInterruptedException
public boolean sendBooleanQuery(QueryLanguage ql, String query, Dataset dataset, boolean includeInferred, Binding... bindings) throws IOException, RepositoryException, MalformedQueryException, UnauthorizedException, QueryInterruptedException
public boolean sendBooleanQuery(QueryLanguage ql, String query, String baseURI, Dataset dataset, boolean includeInferred, int maxQueryTime, Binding... bindings) throws IOException, RepositoryException, MalformedQueryException, UnauthorizedException, QueryInterruptedException
public Map<String,String> getAdditionalHttpHeaders()
public void setAdditionalHttpHeaders(Map<String,String> additionalHttpHeaders)
additionalHttpHeaders
- a map containing pairs of header names and values. May be nullprotected org.apache.http.client.methods.HttpUriRequest getQueryMethod(QueryLanguage ql, String query, String baseURI, Dataset dataset, boolean includeInferred, int maxQueryTime, Binding... bindings)
protected boolean shouldUsePost(String fullQueryUrl)
fullQueryUrl
- the complete URL, including hostname and all HTTP query parametersprotected org.apache.http.client.methods.HttpUriRequest getUpdateMethod(QueryLanguage ql, String update, String baseURI, Dataset dataset, boolean includeInferred, Binding... bindings)
protected org.apache.http.client.methods.HttpUriRequest getUpdateMethod(QueryLanguage ql, String update, String baseURI, Dataset dataset, boolean includeInferred, int maxQueryTime, Binding... bindings)
protected List<org.apache.http.NameValuePair> getQueryMethodParameters(QueryLanguage ql, String query, String baseURI, Dataset dataset, boolean includeInferred, int maxQueryTime, Binding... bindings)
protected List<org.apache.http.NameValuePair> getUpdateMethodParameters(QueryLanguage ql, String update, String baseURI, Dataset dataset, boolean includeInferred, Binding... bindings)
protected List<org.apache.http.NameValuePair> getUpdateMethodParameters(QueryLanguage ql, String update, String baseURI, Dataset dataset, boolean includeInferred, int maxQueryTime, Binding... bindings)
protected TupleQueryResult getBackgroundTupleQueryResult(org.apache.http.client.methods.HttpUriRequest method) throws RepositoryException, QueryInterruptedException, MalformedQueryException, IOException
BackgroundTupleResult
or (in the error-case) in this method.protected void getTupleQueryResult(org.apache.http.client.methods.HttpUriRequest method, TupleQueryResultHandler handler) throws IOException, TupleQueryResultHandlerException, RepositoryException, MalformedQueryException, UnauthorizedException, QueryInterruptedException
TupleQueryResultHandler
. All HTTP connections are
closed and released in this methodprotected GraphQueryResult getRDFBackground(org.apache.http.client.methods.HttpUriRequest method, boolean requireContext) throws IOException, RDFHandlerException, RepositoryException, MalformedQueryException, UnauthorizedException, QueryInterruptedException
BackgroundGraphResult
or (in the error-case) in this method.protected void getRDF(org.apache.http.client.methods.HttpUriRequest method, RDFHandler handler, boolean requireContext) throws IOException, RDFHandlerException, RepositoryException, MalformedQueryException, UnauthorizedException, QueryInterruptedException
RDFHandler
. All HTTP connections are closed and
released in this methodprotected boolean getBoolean(org.apache.http.client.methods.HttpUriRequest method) throws IOException, RDF4JException
BooleanQueryResultParser
. All HTTP connections are
closed and released in this methodRDF4JException
IOException
protected org.apache.http.HttpResponse executeOK(org.apache.http.client.methods.HttpUriRequest method) throws IOException, RDF4JException
method
- RDF4JException
IOException
protected void executeNoContent(org.apache.http.client.methods.HttpUriRequest method) throws IOException, RDF4JException
IOException
RDF4JException
protected org.apache.http.HttpResponse execute(org.apache.http.client.methods.HttpUriRequest method) throws IOException, RDF4JException
IOException
RDF4JException
protected String getResponseMIMEType(org.apache.http.HttpResponse method) throws IOException
method
- The method to get the reponse MIME type from.IOException
protected ErrorInfo getErrorInfo(org.apache.http.HttpResponse response) throws RepositoryException
RepositoryException
public void setParserConfig(ParserConfig parserConfig)
parserConfig
- The parserConfig to set.public ParserConfig getParserConfig()
public long getConnectionTimeout()
public void setConnectionTimeout(long timeout)
timeout
- timeout in milliseconds. Zero sets to infinity.Copyright © 2015-2019 Eclipse Foundation. All Rights Reserved.