Class ClientResponse

  • All Implemented Interfaces:
    ClientResponseContext, org.glassfish.jersey.internal.inject.InjectionManagerSupplier

    public class ClientResponse
    extends InboundMessageContext
    implements ClientResponseContext, org.glassfish.jersey.internal.inject.InjectionManagerSupplier
    Jersey client response context.
    Author:
    Marek Potociar
    • Constructor Detail

      • ClientResponse

        public ClientResponse​(ClientRequest requestContext,
                              Response response)
        Create new Jersey client response context initialized from a JAX-RS response.
        Parameters:
        requestContext - associated request context.
        response - JAX-RS response to be used to initialize the response context.
      • ClientResponse

        public ClientResponse​(Response.StatusType status,
                              ClientRequest requestContext)
        Create a new Jersey client response context.
        Parameters:
        status - response status.
        requestContext - associated client request context.
      • ClientResponse

        public ClientResponse​(Response.StatusType status,
                              ClientRequest requestContext,
                              URI resolvedRequestUri)
        Create a new Jersey client response context.
        Parameters:
        status - response status.
        requestContext - associated client request context.
        resolvedRequestUri - resolved request URI (see getResolvedRequestUri()).
    • Method Detail

      • getResolvedRequestUri

        public URI getResolvedRequestUri()
        Get the absolute URI of the ultimate request made to receive this response.

        The returned URI points to the ultimate location of the requested resource that provided the data represented by this response instance. Because Jersey client connectors may be configured to automatically follow redirect responses, the value of the URI returned by this method may be different from the value of the original request URI that can be retrieved using response.getRequestContext().getUri() chain of method calls.

        Returns:
        absolute URI of the ultimate request made to receive this response.
        Since:
        2.6
        See Also:
        ClientProperties.FOLLOW_REDIRECTS, setResolvedRequestUri(java.net.URI)
      • setResolvedRequestUri

        public void setResolvedRequestUri​(URI uri)
        Set the absolute URI of the ultimate request that was made to receive this response.

        If the original request URI has been modified (e.g. due to redirections), the absolute URI of the ultimate request being made to receive the response should be set by the caller on the response instance using this method.

        Parameters:
        uri - absolute URI of the ultimate request made to receive this response. Must not be null.
        Throws:
        NullPointerException - in case the passed uri parameter is null.
        IllegalArgumentException - in case the passed uri parameter does not represent an absolute URI.
        Since:
        2.6
        See Also:
        ClientProperties.FOLLOW_REDIRECTS, getResolvedRequestUri()
      • getRequestContext

        public ClientRequest getRequestContext()
        Get the associated client request context paired with this response context.
        Returns:
        associated client request context.
      • readEntity

        public <T> T readEntity​(Class<T> entityType)
                         throws ProcessingException,
                                IllegalStateException
        Read the message entity input stream as an instance of specified Java type using a MessageBodyReader that supports mapping the message entity stream onto the requested type.

        Method throws an ProcessingException if the content of the message cannot be mapped to an entity of the requested type and IllegalStateException in case the entity is not backed by an input stream or if the original entity input stream has already been consumed without buffering the entity data prior consuming.

        A message instance returned from this method will be cached for subsequent retrievals via getEntity(). Unless the supplied entity type is an input stream, this method automatically closes the an unconsumed original response entity data stream if open. In case the entity data has been buffered, the buffer will be reset prior consuming the buffered data to enable subsequent invocations of readEntity(...) methods on this response.

        Type Parameters:
        T - entity instance Java type.
        Parameters:
        entityType - the type of entity.
        Returns:
        the message entity; for a zero-length response entities returns a corresponding Java object that represents zero-length data. In case no zero-length representation is defined for the Java type, a ProcessingException wrapping the underlying NoContentException is thrown.
        Throws:
        ProcessingException - if the content of the message cannot be mapped to an entity of the requested type.
        IllegalStateException - if the entity is not backed by an input stream, the response has been closed already, or if the entity input stream has been fully consumed already and has not been buffered prior consuming.
        Since:
        2.5
        See Also:
        MessageBodyReader, Response.readEntity(Class)
      • readEntity

        public <T> T readEntity​(GenericType<T> entityType)
                         throws ProcessingException,
                                IllegalStateException
        Read the message entity input stream as an instance of specified Java type using a MessageBodyReader that supports mapping the message entity stream onto the requested type.

        Method throws an ProcessingException if the content of the message cannot be mapped to an entity of the requested type and IllegalStateException in case the entity is not backed by an input stream or if the original entity input stream has already been consumed without buffering the entity data prior consuming.

        A message instance returned from this method will be cached for subsequent retrievals via getEntity(). Unless the supplied entity type is an input stream, this method automatically closes the an unconsumed original response entity data stream if open. In case the entity data has been buffered, the buffer will be reset prior consuming the buffered data to enable subsequent invocations of readEntity(...) methods on this response.

        Type Parameters:
        T - entity instance Java type.
        Parameters:
        entityType - the type of entity; may be generic.
        Returns:
        the message entity; for a zero-length response entities returns a corresponding Java object that represents zero-length data. In case no zero-length representation is defined for the Java type, a ProcessingException wrapping the underlying NoContentException is thrown.
        Throws:
        ProcessingException - if the content of the message cannot be mapped to an entity of the requested type.
        IllegalStateException - if the entity is not backed by an input stream, the response has been closed already, or if the entity input stream has been fully consumed already and has not been buffered prior consuming.
        Since:
        2.5
        See Also:
        MessageBodyReader, Response.readEntity(jakarta.ws.rs.core.GenericType)
      • readEntity

        public <T> T readEntity​(Class<T> entityType,
                                Annotation[] annotations)
                         throws ProcessingException,
                                IllegalStateException
        Read the message entity input stream as an instance of specified Java type using a MessageBodyReader that supports mapping the message entity stream onto the requested type.

        Method throws an ProcessingException if the content of the message cannot be mapped to an entity of the requested type and IllegalStateException in case the entity is not backed by an input stream or if the original entity input stream has already been consumed without buffering the entity data prior consuming.

        A message instance returned from this method will be cached for subsequent retrievals via getEntity(). Unless the supplied entity type is an input stream, this method automatically closes the an unconsumed original response entity data stream if open. In case the entity data has been buffered, the buffer will be reset prior consuming the buffered data to enable subsequent invocations of readEntity(...) methods on this response.

        Type Parameters:
        T - entity instance Java type.
        Parameters:
        entityType - the type of entity.
        annotations - annotations that will be passed to the MessageBodyReader.
        Returns:
        the message entity; for a zero-length response entities returns a corresponding Java object that represents zero-length data. In case no zero-length representation is defined for the Java type, a ProcessingException wrapping the underlying NoContentException is thrown.
        Throws:
        ProcessingException - if the content of the message cannot be mapped to an entity of the requested type.
        IllegalStateException - if the entity is not backed by an input stream, the response has been closed already, or if the entity input stream has been fully consumed already and has not been buffered prior consuming.
        Since:
        2.5
        See Also:
        MessageBodyReader, Response.readEntity(Class, java.lang.annotation.Annotation[])
      • readEntity

        public <T> T readEntity​(GenericType<T> entityType,
                                Annotation[] annotations)
                         throws ProcessingException,
                                IllegalStateException
        Read the message entity input stream as an instance of specified Java type using a MessageBodyReader that supports mapping the message entity stream onto the requested type.

        Method throws an ProcessingException if the content of the message cannot be mapped to an entity of the requested type and IllegalStateException in case the entity is not backed by an input stream or if the original entity input stream has already been consumed without buffering the entity data prior consuming.

        A message instance returned from this method will be cached for subsequent retrievals via getEntity(). Unless the supplied entity type is an input stream, this method automatically closes the an unconsumed original response entity data stream if open. In case the entity data has been buffered, the buffer will be reset prior consuming the buffered data to enable subsequent invocations of readEntity(...) methods on this response.

        Type Parameters:
        T - entity instance Java type.
        Parameters:
        entityType - the type of entity; may be generic.
        annotations - annotations that will be passed to the MessageBodyReader.
        Returns:
        the message entity; for a zero-length response entities returns a corresponding Java object that represents zero-length data. In case no zero-length representation is defined for the Java type, a ProcessingException wrapping the underlying NoContentException is thrown.
        Throws:
        ProcessingException - if the content of the message cannot be mapped to an entity of the requested type.
        IllegalStateException - if the entity is not backed by an input stream, the response has been closed already, or if the entity input stream has been fully consumed already and has not been buffered prior consuming.
        Since:
        2.5
        See Also:
        MessageBodyReader, Response.readEntity(jakarta.ws.rs.core.GenericType, java.lang.annotation.Annotation[])
      • getInjectionManager

        public org.glassfish.jersey.internal.inject.InjectionManager getInjectionManager()
        Specified by:
        getInjectionManager in interface org.glassfish.jersey.internal.inject.InjectionManagerSupplier