Package org.fcrepo.client
Class FcrepoClient
- java.lang.Object
-
- org.fcrepo.client.FcrepoClient
-
- All Implemented Interfaces:
Closeable,AutoCloseable
public class FcrepoClient extends Object implements Closeable
Represents a client to interact with Fedora's HTTP API.Users of the
FcrepoClientare responsible for managing connection resources. Specifically, the underlying HTTP connections of this client must be freed. Suggested usage is to create theFcrepoResponsewithin atry-with-resourcesblock, insuring that any resources held by the response are freed automatically.FcrepoClient client = ...; try (FcrepoResponse res = client.get(...).perform()) { // do something with the response } catch (FcrepoOperationFailedException|IOException e) { // handle any exceptions }- Since:
- October 20, 2014
- Author:
- Aaron Coburn
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classFcrepoClient.FcrepoClientBuilderBuilds an FcrepoClient
-
Constructor Summary
Constructors Modifier Constructor Description protectedFcrepoClient(String username, String password, String host, Boolean throwExceptionOnFailure)Create a FcrepoClient with a set of authentication values.protectedFcrepoClient(org.apache.http.impl.client.CloseableHttpClient httpClient, Boolean throwExceptionOnFailure)Create a FcrepoClient which uses the givenCloseableHttpClient.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static FcrepoClient.FcrepoClientBuilderclient()Build a FcrepoClientvoidclose()OriginalMementoBuildercreateMemento(URI url)Make a POST request to create a new memento (LDPRm) within an LDPCv of the current version of a resource.HistoricMementoBuildercreateMemento(URI url, String mementoDatetime)Make a POST request to create a new memento (LDPRm) within an LDPCv using the given memento-datetime and the request body.HistoricMementoBuildercreateMemento(URI url, Instant mementoInstant)Make a POST request to create a new memento (LDPRm) within an LDPCv using the given memento-datetime and the request body.DeleteBuilderdelete(URI url)Make a DELETE request to delete a resourceFcrepoResponseexecuteRequest(URI url, org.apache.http.client.methods.HttpRequestBase request)Execute a HTTP requestGetBuilderget(URI url)Make a GET request to retrieve the content of a resourceHeadBuilderhead(URI url)Make a HEAD request to retrieve resource headers.OptionsBuilderoptions(URI url)Make a OPTIONS request to output information about the supported HTTP methods, etc.PatchBuilderpatch(URI url)Make a PATCH request to modify the triples associated with a resource with SPARQL-Update.PostBuilderpost(URI url)Make a POST request to create a new resource within an LDP container.PutBuilderput(URI url)Make a PUT request to create a resource with a specified path, or replace the triples associated with a resource with the triples provided in the request body.
-
-
-
Constructor Detail
-
FcrepoClient
protected FcrepoClient(String username, String password, String host, Boolean throwExceptionOnFailure)
Create a FcrepoClient with a set of authentication values.- Parameters:
username- the username for the repositorypassword- the password for the repositoryhost- the authentication hostname (realm) for the repositorythrowExceptionOnFailure- whether to throw an exception on any non-2xx or 3xx HTTP responses
-
FcrepoClient
protected FcrepoClient(org.apache.http.impl.client.CloseableHttpClient httpClient, Boolean throwExceptionOnFailure)
Create a FcrepoClient which uses the givenCloseableHttpClient. FcrepoClient will close the httpClient whenclose()is called.- Parameters:
httpClient- http client to use to connect to the repositorythrowExceptionOnFailure- whether to throw an exception on any non-2xx or 3xx HTTP responses
-
-
Method Detail
-
client
public static FcrepoClient.FcrepoClientBuilder client()
Build a FcrepoClient- Returns:
- a client builder
-
put
public PutBuilder put(URI url)
Make a PUT request to create a resource with a specified path, or replace the triples associated with a resource with the triples provided in the request body.- Parameters:
url- the URL of the resource to which to PUT- Returns:
- a put request builder object
-
patch
public PatchBuilder patch(URI url)
Make a PATCH request to modify the triples associated with a resource with SPARQL-Update.- Parameters:
url- the URL of the resource to which to PATCH- Returns:
- a patch request builder object
-
post
public PostBuilder post(URI url)
Make a POST request to create a new resource within an LDP container.- Parameters:
url- the URL of the resource to which to POST- Returns:
- a post request builder object
-
createMemento
public OriginalMementoBuilder createMemento(URI url)
Make a POST request to create a new memento (LDPRm) within an LDPCv of the current version of a resource.- Parameters:
url- the URL of the LDPCv in which to create the LDPRm.- Returns:
- a memento creation request builder object
-
createMemento
public HistoricMementoBuilder createMemento(URI url, Instant mementoInstant)
Make a POST request to create a new memento (LDPRm) within an LDPCv using the given memento-datetime and the request body.- Parameters:
url- the URL of the LDPCv in which to create the LDPRm.mementoInstant- the memento datetime as an Instant.- Returns:
- a memento creation request builder object
-
createMemento
public HistoricMementoBuilder createMemento(URI url, String mementoDatetime)
Make a POST request to create a new memento (LDPRm) within an LDPCv using the given memento-datetime and the request body.- Parameters:
url- the URL of the LDPCv in which to create the LDPRm.mementoDatetime- the RFC1123 formatted memento datetime.- Returns:
- a memento creation request builder object
-
delete
public DeleteBuilder delete(URI url)
Make a DELETE request to delete a resource- Parameters:
url- the URL of the resource to which to DELETE- Returns:
- a delete request builder object
-
get
public GetBuilder get(URI url)
Make a GET request to retrieve the content of a resource- Parameters:
url- the URL of the resource to which to GET- Returns:
- a get request builder object
-
head
public HeadBuilder head(URI url)
Make a HEAD request to retrieve resource headers.- Parameters:
url- the URL of the resource to make the HEAD request on.- Returns:
- a HEAD request builder object
-
options
public OptionsBuilder options(URI url)
Make a OPTIONS request to output information about the supported HTTP methods, etc.- Parameters:
url- the URL of the resource to make the OPTIONS request on.- Returns:
- a OPTIONS request builder object
-
close
public void close() throws IOException
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
executeRequest
public FcrepoResponse executeRequest(URI url, org.apache.http.client.methods.HttpRequestBase request) throws FcrepoOperationFailedException
Execute a HTTP request- Parameters:
url- URI the request is made torequest- the request- Returns:
- the repository response
- Throws:
FcrepoOperationFailedException- when the underlying HTTP request results in an error
-
-