org.eclipse.rdf4j.repository.http

## Class HTTPRepository

- java.lang.Object
- - org.eclipse.rdf4j.repository.base.AbstractRepository
  - - org.eclipse.rdf4j.repository.http.HTTPRepository

- All Implemented Interfaces:
    HttpClientDependent, SesameClientDependent, 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:
    `UnauthorizedException`

- - ### Field Summary

    - ### Fields inherited from class org.eclipse.rdf4j.repository.base.AbstractRepository

      `logger`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `HTTPRepository(String repositoryURL)`
    `HTTPRepository(String serverURL, String repositoryID)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected RDF4JProtocolSession` | `createHTTPClient()` Creates a new `RDF4JProtocolSession` object.
    `Map<String,String>` | `getAdditionalHttpHeaders()` Get the additional HTTP headers which will be used
    `RepositoryConnection` | `getConnection()` Opens a connection to this repository that can be used for querying and updating the contents of the repository.
    `File` | `getDataDir()` Get the directory where data and logging for this repository is stored.
    `org.apache.http.client.HttpClient` | `getHttpClient()` `HttpClient` that has been assigned or has been used by this object.
    `HttpClientSessionManager` | `getHttpClientSessionManager()` `HttpClientSessionManager` that has been assigned or has been used by this object.
    `RDFFormat` | `getPreferredRDFFormat()` Indicates the current preferred `RDFFormat`.
    `TupleQueryResultFormat` | `getPreferredTupleQueryResultFormat()` Indicates the current preferred `TupleQueryResultFormat`.
    `String` | `getRepositoryURL()`
    `ValueFactory` | `getValueFactory()` Gets a ValueFactory for this Repository.
    `protected void` | `initializeInternal()`
    `boolean` | `isWritable()` Checks whether this repository is writable, i.e.
    `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` | `setDataDir(File dataDir)` Set the directory where data and logging for this repository is stored.
    `void` | `setHttpClient(org.apache.http.client.HttpClient httpClient)` Assign an `HttpClient` that this object should use.
    `void` | `setHttpClientSessionManager(HttpClientSessionManager client)` Assign an `HttpClientSessionManager` that this object should use.
    `void` | `setPreferredRDFFormat(RDFFormat format)` Sets the preferred serialization format for RDF to the supplied `RDFFormat`, overriding the `SPARQLProtocolSession`'s default preference.
    `void` | `setPreferredTupleQueryResultFormat(TupleQueryResultFormat format)` Sets the preferred serialization format for tuple query results to the supplied `TupleQueryResultFormat`, overriding the `SPARQLProtocolSession` 's default preference.
    `void` | `setUsernameAndPassword(String username, String password)` Set the username and password to use for authenticating with the remote repository.
    `protected void` | `shutDownInternal()`

    - ### Methods inherited from class org.eclipse.rdf4j.repository.base.AbstractRepository

      `init, initialize, isInitialized, shutDown`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface org.eclipse.rdf4j.http.client.SesameClientDependent

      `getSesameClient, setSesameClient`

- - ### Constructor Detail

    - #### HTTPRepository

          public HTTPRepository(String serverURL,
                                String repositoryID)

    - #### HTTPRepository

          public HTTPRepository(String repositoryURL)

  - ### Method Detail

    - #### setDataDir

          public void setDataDir(File dataDir)

      Description copied from interface: `Repository`
      Set the directory where data and logging for this repository is stored.
      Specified by:
        `setDataDir` in interface `Repository`
      Parameters:
        `dataDir` - the directory where data for this repository is stored

    - #### getDataDir

          public File getDataDir()

      Description copied from interface: `Repository`
      Get the directory where data and logging for this repository is stored.
      Specified by:
        `getDataDir` in interface `Repository`
      Returns:
        the directory where data for this repository is stored.

    - #### getHttpClientSessionManager

          public HttpClientSessionManager getHttpClientSessionManager()

      Description copied from interface: `SessionManagerDependent`
      `HttpClientSessionManager` 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 `HttpClientSessionManager` was passed to or created by this object respectively.
      Specified by:
        `getHttpClientSessionManager` in interface `SesameClientDependent`
      Specified by:
        `getHttpClientSessionManager` in interface `SessionManagerDependent`
      Returns:
        a `HttpClientSessionManager` instance or null

    - #### setHttpClientSessionManager

          public void setHttpClientSessionManager(HttpClientSessionManager client)

      Description copied from interface: `SessionManagerDependent`
      Assign an `HttpClientSessionManager` that this object should use. The life cycle of the given `HttpClientSessionManager` 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:
        `setHttpClientSessionManager` in interface `SesameClientDependent`
      Specified by:
        `setHttpClientSessionManager` in interface `SessionManagerDependent`

    - #### getAdditionalHttpHeaders

          public Map<String,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(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. This will only take effect on connections subsequently returned by `getConnection()`.
      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: `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.
      Specified by:
        `getHttpClient` in interface `HttpClientDependent`
      Returns:
        an `HttpClient` instance or null

    - #### setHttpClient

          public void setHttpClient(org.apache.http.client.HttpClient httpClient)

      Description copied from interface: `HttpClientDependent`
      Assign an `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.
      Specified by:
        `setHttpClient` in interface `HttpClientDependent`

    - #### getValueFactory

          public ValueFactory getValueFactory()

      Description copied from interface: `Repository`
      Gets a ValueFactory for this Repository.
      Specified by:
        `getValueFactory` in interface `Repository`
      Returns:
        A repository-specific ValueFactory.

    - #### getConnection

          public RepositoryConnection getConnection()
                                             throws RepositoryException

      Description copied from interface: `Repository`
      Opens 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 `RepositoryConnection` is 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 own `RepositoryConnection`s.
      Specified by:
        `getConnection` in interface `Repository`
      Returns:
        A connection that allows operations on this repository.
      Throws:
        `RepositoryException` - If something went wrong during the creation of the Connection.

    - #### isWritable

          public boolean isWritable()
                             throws RepositoryException

      Description copied from interface: `Repository`
      Checks 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:
        `isWritable` in interface `Repository`
      Throws:
        `RepositoryException`

    - #### setPreferredTupleQueryResultFormat

          public void setPreferredTupleQueryResultFormat(TupleQueryResultFormat format)

      Sets the preferred serialization format for tuple query results to the supplied `TupleQueryResultFormat`, overriding the `SPARQLProtocolSession` 's default preference. Setting this parameter is not necessary in most cases as the `SPARQLProtocolSession` by default indicates a preference for the most compact and efficient format available.
      Parameters:
        `format` - the preferred `TupleQueryResultFormat`. If set to 'null' no explicit preference will be stated.

    - #### getPreferredTupleQueryResultFormat

          public TupleQueryResultFormat getPreferredTupleQueryResultFormat()

      Indicates the current preferred `TupleQueryResultFormat`.
      Returns:
        The preferred format, of 'null' if no explicit preference is defined.

    - #### setPreferredRDFFormat

          public void setPreferredRDFFormat(RDFFormat format)

      Sets the preferred serialization format for RDF to the supplied `RDFFormat`, overriding the `SPARQLProtocolSession`'s default preference. Setting this parameter is not necessary in most cases as the `SPARQLProtocolSession` by 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 preferred `RDFFormat`. If set to 'null' no explicit preference will be stated.

    - #### getPreferredRDFFormat

          public RDFFormat getPreferredRDFFormat()

      Indicates the current preferred `RDFFormat`.
      Returns:
        The preferred format, of 'null' if no explicit preference is defined.

    - #### setUsernameAndPassword

          public void setUsernameAndPassword(String username,
                                             String password)

      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

          public String getRepositoryURL()

    - #### initializeInternal

          protected void initializeInternal()
                                     throws RepositoryException

      Specified by:
        `initializeInternal` in class `AbstractRepository`
      Throws:
        `RepositoryException`

    - #### shutDownInternal

          protected void shutDownInternal()
                                   throws RepositoryException

      Specified by:
        `shutDownInternal` in class `AbstractRepository`
      Throws:
        `RepositoryException`

    - #### createHTTPClient

          protected RDF4JProtocolSession createHTTPClient()

      Creates a new `RDF4JProtocolSession` object.
      Returns:
        a `RDF4JProtocolSession` object.

Copyright © 2015-2022 Eclipse Foundation. All Rights Reserved.