org.jboss.resteasy.client.jaxrs.internal

## Class ClientResponse

- java.lang.Object
- - javax.ws.rs.core.Response
  - - org.jboss.resteasy.specimpl.BuiltResponse
    - - org.jboss.resteasy.client.jaxrs.internal.ClientResponse

- Direct Known Subclasses:
    AbortedResponse

      public abstract class ClientResponse
      extends BuiltResponse

  Version:
    $Revision: 1 $
  Author:
    Bill Burke

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from class javax.ws.rs.core.Response

      `Response.ResponseBuilder, Response.Status, Response.StatusType`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected byte[]` | `bufferedEntity`
    `protected ClientConfiguration` | `configuration`
    `protected Map<String,Object>` | `properties`

    - ### Fields inherited from class org.jboss.resteasy.specimpl.BuiltResponse

      `annotations, entity, entityClass, genericType, isClosed, metadata, processor, status`

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `ClientResponse(ClientConfiguration configuration)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `abortIfClosed()`
    `boolean` | `bufferEntity()` Buffer the message entity data.
    `void` | `close()` Close the underlying message entity input stream (if available and open) as well as releases any other resources associated with the response (e.g.
    `protected void` | `finalize()`
    `Object` | `getEntity()` Get the message entity Java instance.
    `protected InputStream` | `getEntityStream()`
    `protected HeaderValueProcessor` | `getHeaderValueProcessor()`
    `protected abstract InputStream` | `getInputStream()`
    `Map<String,Object>` | `getProperties()`
    `boolean` | `hasEntity()` Check if there is an entity available in the response.
    `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
    `<T> T` | `readEntity(Class<T> type, Type genericType, Annotation[] anns)`
    `protected <T> Object` | `readFrom(Class<T> type, Type genericType, MediaType media, Annotation[] annotations)`
    `protected abstract void` | `releaseConnection()` release underlying connection but do not close
    `void` | `setClientConfiguration(ClientConfiguration configuration)`
    `void` | `setHeaders(MultivaluedMap<String,String> headers)`
    `protected abstract void` | `setInputStream(InputStream is)`
    `void` | `setProperties(Map<String,Object> properties)`

    - ### Methods inherited from class org.jboss.resteasy.specimpl.BuiltResponse

      `addMethodAnnotations, getAllowedMethods, getAnnotations, getCookies, getDate, getEntityClass, getEntityTag, getGenericType, getHeaderString, getLanguage, getLastModified, getLength, getLink, getLinkBuilder, getLinkHeaders, getLinks, getLocation, getMediaType, getMetadata, getStatus, getStatusInfo, getStringHeaders, hasLink, isClosed, readEntity, readEntity, readEntity, readEntity, setAnnotations, setEntity, setEntityClass, setGenericType, setMetadata, setStatus, toHeaderString`

    - ### Methods inherited from class javax.ws.rs.core.Response

      `accepted, accepted, created, fromResponse, getHeaders, noContent, notAcceptable, notModified, notModified, notModified, ok, ok, ok, ok, ok, seeOther, serverError, status, status, status, temporaryRedirect`

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

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

- - ### Field Detail

    - #### properties

          protected Map<String,Object> properties

    - #### configuration

          protected ClientConfiguration configuration

    - #### bufferedEntity

          protected byte[] bufferedEntity

  - ### Constructor Detail

    - #### ClientResponse

          protected ClientResponse(ClientConfiguration configuration)

  - ### Method Detail

    - #### 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 `BuiltResponse`
      Returns:
        the message entity or `null` if message does not contain an entity body (i.e. when `Response.hasEntity()` returns `false`).

    - #### 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 `BuiltResponse`
      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.

      Overrides:
        `close` in class `BuiltResponse`

    - #### finalize

          protected void finalize()
                           throws Throwable

      Overrides:
        `finalize` in class `Object`
      Throws:
        `Throwable`

    - #### getHeaderValueProcessor

          protected HeaderValueProcessor getHeaderValueProcessor()

      Overrides:
        `getHeaderValueProcessor` in class `BuiltResponse`

    - #### getInputStream

          protected abstract InputStream getInputStream()

    - #### getEntityStream

          protected InputStream getEntityStream()

    - #### setInputStream

          protected abstract void setInputStream(InputStream is)

    - #### releaseConnection

          protected abstract void releaseConnection()
                                             throws IOException

      release underlying connection but do not close
      Throws:
        `IOException`

    - #### readEntity

          public <T> T readEntity(Class<T> type,
                         Type genericType,
                         Annotation[] anns)

      Overrides:
        `readEntity` in class `BuiltResponse`

    - #### readFrom

          protected <T> Object readFrom(Class<T> type,
                            Type genericType,
                            MediaType media,
                            Annotation[] annotations)

    - #### 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 `BuiltResponse`

Copyright © 2014. All Rights Reserved.