Class HTTPRepository
java.lang.Object
org.eclipse.rdf4j.repository.base.AbstractRepository
org.eclipse.rdf4j.repository.http.HTTPRepository
- All Implemented Interfaces:
HttpClientDependent,SessionManagerDependent,Repository
public class HTTPRepository
extends AbstractRepository
implements HttpClientDependent, SessionManagerDependent
A repository that serves as a client for a remote repository on an RDF4J Server. Methods in this class may throw the
specific
RepositoryException subclass UnauthorizedException, the semantics of which is defined by the
HTTP protocol.
This repository client uses a RDF4J-specific extension
of the SPARQL 1.1 Protocol to communicate with the server. For communicating with a SPARQL endpoint that is not
based on RDF4J, it is recommended to use SPARQLRepository instead.
- Author:
- Arjohn Kampman, Jeen Broekstra, Herko ter Horst
- See Also:
-
Field Summary
Fields inherited from class org.eclipse.rdf4j.repository.base.AbstractRepository
logger -
Constructor Summary
ConstructorsConstructorDescriptionHTTPRepository(String repositoryURL) HTTPRepository(String serverURL, String repositoryID) -
Method Summary
Modifier and TypeMethodDescriptionprotected RDF4JProtocolSessionCreates a newRDF4JProtocolSessionobject.Get the additional HTTP headers which will be usedOpens a connection to this repository that can be used for querying and updating the contents of the repository.Get the directory where data and logging for this repository is stored.final org.apache.http.client.HttpClientHttpClientthat has been assigned or has been used by this object.HttpClientSessionManagerthat has been assigned or has been used by this object.Indicates the current preferredRDFFormat.Indicates the current preferredTupleQueryResultFormat.Gets a ValueFactory for this Repository.protected voidbooleanChecks whether this repository is writable, i.e.voidsetAdditionalHttpHeaders(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.voidsetDataDir(File dataDir) Set the directory where data and logging for this repository is stored.voidsetHttpClient(org.apache.http.client.HttpClient httpClient) Assign anHttpClientthat this object should use.voidAssign anHttpClientSessionManagerthat this object should use.voidsetPreferredRDFFormat(RDFFormat format) Sets the preferred serialization format for RDF to the suppliedRDFFormat, overriding theSPARQLProtocolSession's default preference.voidSets the preferred serialization format for tuple query results to the suppliedTupleQueryResultFormat, overriding theSPARQLProtocolSession's default preference.voidsetUsernameAndPassword(String username, String password) Set the username and password to use for authenticating with the remote repository.protected voidMethods inherited from class org.eclipse.rdf4j.repository.base.AbstractRepository
init, isInitialized, shutDown
-
Constructor Details
-
HTTPRepository
-
HTTPRepository
-
-
Method Details
-
setDataDir
Description copied from interface:RepositorySet the directory where data and logging for this repository is stored.- Specified by:
setDataDirin interfaceRepository- Parameters:
dataDir- the directory where data for this repository is stored
-
getDataDir
Description copied from interface:RepositoryGet the directory where data and logging for this repository is stored.- Specified by:
getDataDirin interfaceRepository- Returns:
- the directory where data for this repository is stored.
-
getHttpClientSessionManager
Description copied from interface:SessionManagerDependentHttpClientSessionManagerthat 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 whetherHttpClientSessionManagerwas passed to or created by this object respectively.- Specified by:
getHttpClientSessionManagerin interfaceSessionManagerDependent- Returns:
- a
HttpClientSessionManagerinstance or null
-
setHttpClientSessionManager
Description copied from interface:SessionManagerDependentAssign anHttpClientSessionManagerthat this object should use. The life cycle of the givenHttpClientSessionManageris 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:
setHttpClientSessionManagerin interfaceSessionManagerDependent
-
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
Set additional HTTP headers to be included in every request to the server, which may be required for certain unusual server configurations. This will only take effect on connections subsequently returned bygetConnection().- Parameters:
additionalHttpHeaders- a map containing pairs of header names and values. May be null
-
getHttpClient
public final org.apache.http.client.HttpClient getHttpClient()Description copied from interface:HttpClientDependentHttpClientthat 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 whetherHttpClientwas passed to or created by this object respectively.- Specified by:
getHttpClientin interfaceHttpClientDependent- Returns:
- an
HttpClientinstance or null
-
setHttpClient
public void setHttpClient(org.apache.http.client.HttpClient httpClient) Description copied from interface:HttpClientDependentAssign anHttpClientthat this object should use. The life cycle of the givenHttpClientis 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:
setHttpClientin interfaceHttpClientDependent
-
getValueFactory
Description copied from interface:RepositoryGets a ValueFactory for this Repository.- Specified by:
getValueFactoryin interfaceRepository- Returns:
- A repository-specific ValueFactory.
-
getConnection
Description copied from interface:RepositoryOpens a connection to this repository that can be used for querying and updating the contents of the repository. Created connections need to be closed to make sure that any resources they keep hold of are released. The best way to do this is to use a try-with-resources block, as follows:try (RepositoryConnection conn = repository.getConnection()) { // perform operations on the connection }Note that
RepositoryConnectionis not guaranteed to be thread-safe! The recommended pattern for repository access in a multi-threaded application is to share the Repository object between threads, but have each thread create and use its ownRepositoryConnections.- Specified by:
getConnectionin interfaceRepository- Returns:
- A connection that allows operations on this repository.
- Throws:
RepositoryException- If something went wrong during the creation of the Connection.
-
isWritable
Description copied from interface:RepositoryChecks whether this repository is writable, i.e. if the data contained in this repository can be changed. The writability of the repository is determined by the writability of the Sail that this repository operates on.- Specified by:
isWritablein interfaceRepository- Throws:
RepositoryException
-
setPreferredTupleQueryResultFormat
Sets the preferred serialization format for tuple query results to the suppliedTupleQueryResultFormat, overriding theSPARQLProtocolSession's default preference. Setting this parameter is not necessary in most cases as theSPARQLProtocolSessionby default indicates a preference for the most compact and efficient format available.- Parameters:
format- the preferredTupleQueryResultFormat. If set to 'null' no explicit preference will be stated.
-
getPreferredTupleQueryResultFormat
Indicates the current preferredTupleQueryResultFormat.- Returns:
- The preferred format, of 'null' if no explicit preference is defined.
-
setPreferredRDFFormat
Sets the preferred serialization format for RDF to the suppliedRDFFormat, overriding theSPARQLProtocolSession's default preference. Setting this parameter is not necessary in most cases as theSPARQLProtocolSessionby default indicates a preference for the most compact and efficient format available.Use with caution: if set to a format that does not support context serialization any context info contained in the query result will be lost.
- Parameters:
format- the preferredRDFFormat. If set to 'null' no explicit preference will be stated.
-
getPreferredRDFFormat
Indicates the current preferredRDFFormat.- Returns:
- The preferred format, of 'null' if no explicit preference is defined.
-
setUsernameAndPassword
Set the username and password to use for authenticating with the remote repository.- Parameters:
username- the username. Setting this to null will disable authentication.password- the password. Setting this to null will disable authentication.
-
getRepositoryURL
-
initializeInternal
- Specified by:
initializeInternalin classAbstractRepository- Throws:
RepositoryException
-
shutDownInternal
- Specified by:
shutDownInternalin classAbstractRepository- Throws:
RepositoryException
-
createHTTPClient
Creates a newRDF4JProtocolSessionobject.- Returns:
- a
RDF4JProtocolSessionobject.
-