Class ClientResponse

All Implemented Interfaces:
AutoCloseable
Direct Known Subclasses:
FinalizedClientResponse

public abstract class ClientResponse extends BuiltResponse
Version:
$Revision: 1 $
Author:
Bill Burke
  • Field Details

  • Constructor Details

  • Method Details

    • setHeaders

      public void setHeaders(MultivaluedMap<String,String> headers)
    • setProperties

      public void setProperties(Map<String,Object> properties)
    • getProperties

      public Map<String,Object> getProperties()
    • setClientConfiguration

      public void setClientConfiguration(ClientConfiguration configuration)
    • getEntity

      public Object getEntity()
      Description copied from class: Response
      Get the message entity Java instance. Returns null if the message does not contain an entity body.

      If the entity is represented by an un-consumed input stream the method will return the input stream.

      Overrides:
      getEntity in class AbstractBuiltResponse
      Returns:
      the message entity or null if message does not contain an entity body (i.e. when Response.hasEntity() returns false).
    • getEntityClass

      public Class<?> getEntityClass()
      Overrides:
      getEntityClass in class AbstractBuiltResponse
    • hasEntity

      public boolean hasEntity()
      Description copied from class: Response
      Check if there is an entity available in the response. The method returns true if the entity is present, returns false otherwise.

      Note that the method may return true also for response messages with a zero-length content, in case the "Content-Length" and "Content-Type" headers are specified in the message. In such case, an attempt to read the entity using one of the readEntity(...) methods will return a corresponding instance representing a zero-length entity for a given Java type or produce a ProcessingException in case no such instance is available for the Java type.

      Overrides:
      hasEntity in class AbstractBuiltResponse
      Returns:
      true if there is an entity present in the message, false otherwise.
    • noReleaseConnection

      public void noReleaseConnection()
      In case of an InputStream or Reader and a invocation that returns no Response object, we need to make sure the GC does not close the returned InputStream or Reader
    • close

      public void close()
      Description copied from class: Response
      Close the underlying message entity input stream (if available and open) as well as releases any other resources associated with the response (e.g. buffered message entity data).

      This operation is idempotent, i.e. it can be invoked multiple times with the same effect which also means that calling the close() method on an already closed message instance is legal and has no further effect.

      The close() method should be invoked on all instances that contain an un-consumed entity input stream to ensure the resources associated with the instance are properly cleaned-up and prevent potential memory leaks. This is typical for client-side scenarios where application layer code processes only the response headers and ignores the response entity.

      Any attempts to manipulate (read, get, buffer) a message entity on a closed response will result in an IllegalStateException being thrown.

      Specified by:
      close in interface AutoCloseable
      Overrides:
      close in class AbstractBuiltResponse
    • getHeaderValueProcessor

      protected HeaderValueProcessor getHeaderValueProcessor()
      Overrides:
      getHeaderValueProcessor in class AbstractBuiltResponse
    • getEntityStream

      protected InputStream getEntityStream()
      Overrides:
      getEntityStream in class BuiltResponse
    • setInputStream

      protected abstract void setInputStream(InputStream is)
      Overrides:
      setInputStream in class BuiltResponse
    • readFrom

      protected <T> Object readFrom(Class<T> type, Type genericType, MediaType media, Annotation[] annotations)
      Overrides:
      readFrom in class BuiltResponse
    • bufferEntity

      public boolean bufferEntity()
      Description copied from class: Response
      Buffer the message entity data.

      In case the message entity is backed by an unconsumed entity input stream, all the bytes of the original entity input stream are read and stored in a local buffer. The original entity input stream is consumed and automatically closed as part of the operation and the method returns true.

      In case the response entity instance is not backed by an unconsumed input stream an invocation of bufferEntity method is ignored and the method returns false.

      This operation is idempotent, i.e. it can be invoked multiple times with the same effect which also means that calling the bufferEntity() method on an already buffered (and thus closed) message instance is legal and has no further effect. Also, the result returned by the bufferEntity() method is consistent across all invocations of the method on the same Response instance.

      Buffering the message entity data allows for multiple invocations of readEntity(...) methods on the response instance. Note however, that once the response instance itself is closed, the implementations are expected to release the buffered message entity data too. Therefore any subsequent attempts to read a message entity stream on such closed response will result in an IllegalStateException being thrown.

      Overrides:
      bufferEntity in class BuiltResponse
      Returns:
      true if the message entity input stream was available and was buffered successfully, returns false if the entity stream was not available.
    • abortIfClosed

      public void abortIfClosed()
      Overrides:
      abortIfClosed in class AbstractBuiltResponse