Package org.fcrepo.client
Class FcrepoResponse
- java.lang.Object
-
- org.fcrepo.client.FcrepoResponse
-
- All Implemented Interfaces:
Closeable,AutoCloseable
public class FcrepoResponse extends Object implements Closeable
Represents a response from a fedora repository using aFcrepoClient.This class implements
Closeable. Suggested usage is to create theFcrepoResponsewithin a try-with-resources block, insuring that any resources held by the response are freed automatically.FcrepoClient client = ...; try (FcrepoResponse res = client.get(...)) { // do something with the response } catch (FcrepoOperationFailedException|IOException e) { // handle any exceptions }Closed responses have no obligation to provide access to released resources.- Since:
- October 20, 2014
- Author:
- Aaron Coburn
-
-
Constructor Summary
Constructors Constructor Description FcrepoResponse(URI url, int statusCode, Map<String,List<String>> headers, InputStream body)Create a FcrepoResponse object from the http response
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()InputStreamgetBody()body getterMap<String,String>getContentDisposition()Get a map of parameters from the Content-Disposition header if presentStringgetContentType()contentType getterMap<String,List<String>>getHeaders()headers getterStringgetHeaderValue(String name)Get the first value for the specified headerList<String>getHeaderValues(String name)Get all values for the specified headerList<URI>getLinkHeaders(String relationship)Retrieve link header values matching the given relationshipURIgetLocation()location getterintgetStatusCode()statusCode getterURIgetTransactionUri()Get the transaction location.URIgetUrl()url getterbooleanhasType(String typeString)Return true if the response represents a resource with the given typebooleanhasType(URI typeUri)Return true if the response represents a resource with the given typebooleanisClosed()Whether or not the resources have been freed from this response.voidsetBody(InputStream body)body settervoidsetContentType(String contentType)contentType settervoidsetHeaders(Map<String,List<String>> headers)headers settervoidsetLocation(URI location)location settervoidsetStatusCode(int statusCode)statusCode settervoidsetUrl(URI url)url setter
-
-
-
Constructor Detail
-
FcrepoResponse
public FcrepoResponse(URI url, int statusCode, Map<String,List<String>> headers, InputStream body)
Create a FcrepoResponse object from the http response- Parameters:
url- the requested URLstatusCode- the HTTP status codeheaders- a map of all response header names and valuesbody- the response body stream
-
-
Method Detail
-
close
public void close() throws IOException
Implementation note: Invoking this method will close the underlying
InputStreamcontaining the entity body of the HTTP response.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException- if there is an error closing the underlying HTTP response stream.
-
isClosed
public boolean isClosed()
Whether or not the resources have been freed from this response. There should be no expectation that a closed response provides access to theentity body.- Returns:
trueif resources have been freed, otherwisefalse
-
getStatusCode
public int getStatusCode()
statusCode getter- Returns:
- the HTTP status code
-
setStatusCode
public void setStatusCode(int statusCode)
statusCode setter- Parameters:
statusCode- the HTTP status code
-
getBody
public InputStream getBody()
body getter- Returns:
- the response body as a stream
-
setBody
public void setBody(InputStream body)
body setter- Parameters:
body- the contents of the response body
-
getHeaders
public Map<String,List<String>> getHeaders()
headers getter- Returns:
- headers from the response
-
getHeaderValues
public List<String> getHeaderValues(String name)
Get all values for the specified header- Parameters:
name- name of the header to retrieve- Returns:
- All values of the specified header
-
getHeaderValue
public String getHeaderValue(String name)
Get the first value for the specified header- Parameters:
name- name of the header to retrieve- Returns:
- First value of the header, or null if not present
-
setHeaders
public void setHeaders(Map<String,List<String>> headers)
headers setter- Parameters:
headers- headers from the response
-
getLinkHeaders
public List<URI> getLinkHeaders(String relationship)
Retrieve link header values matching the given relationship- Parameters:
relationship- the relationship of links to return- Returns:
- list of link header URIs matching the given relationship
-
hasType
public boolean hasType(String typeString)
Return true if the response represents a resource with the given type- Parameters:
typeString- String containing the URI of the type- Returns:
- true if the type is present.
-
hasType
public boolean hasType(URI typeUri)
Return true if the response represents a resource with the given type- Parameters:
typeUri- URI of the type- Returns:
- true if the type is present.
-
getLocation
public URI getLocation()
location getter- Returns:
- the location of a related resource
-
setLocation
public void setLocation(URI location)
location setter- Parameters:
location- the value of a related resource
-
getContentType
public String getContentType()
contentType getter- Returns:
- the mime-type of response
-
setContentType
public void setContentType(String contentType)
contentType setter- Parameters:
contentType- the mime-type of the response
-
getContentDisposition
public Map<String,String> getContentDisposition()
Get a map of parameters from the Content-Disposition header if present- Returns:
- map of Content-Disposition parameters or null
-
getTransactionUri
public URI getTransactionUri()
Get the transaction location. If the location is not for a transaction, check for the Atomic-ID, otherwise return null.- Returns:
- the transaction location or null
-
-