Class FcrepoResponse

  • All Implemented Interfaces:
    Closeable, AutoCloseable

    public class FcrepoResponse
    extends Object
    implements Closeable
    Represents a response from a fedora repository using a FcrepoClient.

    This class implements Closeable. Suggested usage is to create the FcrepoResponse within 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 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 URL
        statusCode - the HTTP status code
        headers - a map of all response header names and values
        body - the response body stream
    • Method Detail

      • close

        public void close()
                   throws IOException

        Implementation note: Invoking this method will close the underlying InputStream containing the entity body of the HTTP response.

        Specified by:
        close in interface AutoCloseable
        Specified by:
        close in interface Closeable
        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 the entity body.
        Returns:
        true if resources have been freed, otherwise false
      • getUrl

        public URI getUrl()
        url getter
        Returns:
        the requested URL
      • setUrl

        public void setUrl​(URI url)
        url setter
        Parameters:
        url - the requested URL
      • 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
      • getHeaderValues

        public List<StringgetHeaderValues​(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
      • getLinkHeaders

        public List<URIgetLinkHeaders​(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,​StringgetContentDisposition()
        Get a map of parameters from the Content-Disposition header if present
        Returns:
        map of Content-Disposition parameters or null