Class AbstractBuiltResponse

java.lang.Object
jakarta.ws.rs.core.Response
org.jboss.resteasy.specimpl.AbstractBuiltResponse
All Implemented Interfaces:
AutoCloseable
Direct Known Subclasses:
BuiltResponse

public abstract class AbstractBuiltResponse extends Response
A response object not attached to a client or server invocation.
Version:
$Revision: 1 $
Author:
Bill Burke
  • Field Details

    • entity

      protected Object entity
    • status

      protected int status
    • reason

      protected String reason
    • metadata

      protected Headers<Object> metadata
    • annotations

      protected Annotation[] annotations
    • entityClass

      protected Class entityClass
    • genericType

      protected Type genericType
    • processor

      protected HeaderValueProcessor processor
    • isClosed

      protected volatile boolean isClosed
    • is

      protected InputStream is
    • bufferedEntity

      protected byte[] bufferedEntity
    • streamRead

      protected volatile boolean streamRead
    • streamFullyRead

      protected volatile boolean streamFullyRead
  • Constructor Details

    • AbstractBuiltResponse

      public AbstractBuiltResponse()
    • AbstractBuiltResponse

      public AbstractBuiltResponse(int status, String reason, Headers<Object> metadata, Object entity, Annotation[] entityAnnotations)
  • Method Details

    • getInputStream

      protected abstract InputStream getInputStream()
    • setInputStream

      protected abstract void setInputStream(InputStream is)
    • getEntityStream

      protected abstract InputStream getEntityStream()
    • releaseConnection

      public abstract void releaseConnection() throws IOException
      Release underlying connection but do not close.
      Throws:
      IOException - if I/O error occurred
    • releaseConnection

      public abstract void releaseConnection(boolean consumeInputStream) throws IOException
      Release underlying connection but do not close.
      Parameters:
      consumeInputStream - boolean to indicate either the underlying input stream must be fully read before releasing the connection or not.

      For most HTTP connection implementations, consuming the underlying input stream before releasing the connection will help to ensure connection reusability with respect of Keep-Alive policy.

      Throws:
      IOException - if I/O error occured
    • getEntityClass

      public Class getEntityClass()
    • setEntityClass

      public void setEntityClass(Class entityClass)
    • getHeaderValueProcessor

      protected HeaderValueProcessor getHeaderValueProcessor()
    • 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.

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

      public int getStatus()
      Description copied from class: Response
      Get the status code associated with the response.
      Specified by:
      getStatus in class Response
      Returns:
      the response status code.
    • getReasonPhrase

      public String getReasonPhrase()
    • getStatusInfo

      public Response.StatusType getStatusInfo()
      Description copied from class: Response
      Get the complete status information associated with the response.
      Specified by:
      getStatusInfo in class Response
      Returns:
      the response status information. The returned value is never null.
    • getMetadata

      public MultivaluedMap<String,Object> getMetadata()
      Description copied from class: Response
      See Response.getHeaders(). This method is considered deprecated. Users are encouraged to switch their code to use the getHeaders() method instead. The method may be annotated as @Deprecated in a future release of JAX-RS API.
      Specified by:
      getMetadata in class Response
      Returns:
      response headers as a multivalued map.
    • setEntity

      public void setEntity(Object entity)
    • setStatus

      public void setStatus(int status)
    • setReasonPhrase

      public void setReasonPhrase(String reason)
    • setMetadata

      public void setMetadata(MultivaluedMap<String,Object> metadata)
    • getAnnotations

      public Annotation[] getAnnotations()
    • addMethodAnnotations

      public void addMethodAnnotations(Annotation[] methodAnnotations)
    • setAnnotations

      public void setAnnotations(Annotation[] annotations)
    • getGenericType

      public Type getGenericType()
    • setGenericType

      public void setGenericType(Type genericType)
    • readEntity

      public <T> T readEntity(Class<T> type, Annotation[] annotations)
      Description copied from class: Response
      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 Response.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.

      Specified by:
      readEntity in class Response
      Type Parameters:
      T - entity instance Java type.
      Parameters:
      type - 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.
      See Also:
    • readEntity

      public <T> T readEntity(GenericType<T> entityType, Annotation[] annotations)
      Description copied from class: Response
      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 Response.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.

      Specified by:
      readEntity in class 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.
      See Also:
    • readEntity

      public <T> T readEntity(Class<T> type)
      Description copied from class: Response
      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 Response.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.

      Specified by:
      readEntity in class Response
      Type Parameters:
      T - entity instance Java type.
      Parameters:
      type - 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.
      See Also:
    • readEntity

      public <T> T readEntity(GenericType<T> entityType)
      Description copied from class: Response
      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 Response.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.

      Specified by:
      readEntity in class 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.
      See Also:
    • readEntity

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

      protected void resetEntity()
    • setStreamRead

      public void setStreamRead(Boolean b)
    • setStreamFullyRead

      public void setStreamFullyRead(Boolean b)
    • 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.

      Specified by:
      hasEntity in class Response
      Returns:
      true if there is an entity present in the message, false otherwise.
    • isClosed

      public boolean isClosed()
      Description copied from class: Response
      Check if the response is closed. The method returns true if the response is closed, returns false otherwise.
      Overrides:
      isClosed in class Response
      Returns:
      true if the response has been closed, false otherwise.
    • abortIfClosed

      public void abortIfClosed()
    • 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
      Specified by:
      close in class Response
    • getLanguage

      public Locale getLanguage()
      Description copied from class: Response
      Get the language of the message entity.
      Specified by:
      getLanguage in class Response
      Returns:
      the language of the entity or null if not specified.
    • getLength

      public int getLength()
      Description copied from class: Response
      Get Content-Length value.
      Specified by:
      getLength in class Response
      Returns:
      Content-Length as integer if present and valid number. In other cases returns -1.
    • getMediaType

      public MediaType getMediaType()
      Description copied from class: Response
      Get the media type of the message entity.
      Specified by:
      getMediaType in class Response
      Returns:
      the media type or null if there is no response entity.
    • getCookies

      public Map<String,NewCookie> getCookies()
      Description copied from class: Response
      Get any new cookies set on the response message.
      Specified by:
      getCookies in class Response
      Returns:
      a read-only map of cookie name (String) to Cookie.
    • getEntityTag

      public EntityTag getEntityTag()
      Description copied from class: Response
      Get the entity tag.
      Specified by:
      getEntityTag in class Response
      Returns:
      the entity tag, otherwise null if not present.
    • getDate

      public Date getDate()
      Description copied from class: Response
      Get message date.
      Specified by:
      getDate in class Response
      Returns:
      the message date, otherwise null if not present.
    • getLastModified

      public Date getLastModified()
      Description copied from class: Response
      Get the last modified date.
      Specified by:
      getLastModified in class Response
      Returns:
      the last modified date, otherwise null if not present.
    • getAllowedMethods

      public Set<String> getAllowedMethods()
      Description copied from class: Response
      Get the allowed HTTP methods from the Allow HTTP header.
      Specified by:
      getAllowedMethods in class Response
      Returns:
      the allowed HTTP methods, all methods will returned as upper case strings.
    • toHeaderString

      protected String toHeaderString(Object header)
    • getStringHeaders

      public MultivaluedMap<String,String> getStringHeaders()
      Description copied from class: Response
      Get view of the response headers and their string values. The underlying header data may be subsequently modified by the JAX-RS runtime on the server side. Changes in the underlying header data are reflected in this view.
      Specified by:
      getStringHeaders in class Response
      Returns:
      response headers as a string view of header values.
      See Also:
    • getHeaderString

      public String getHeaderString(String name)
      Description copied from class: Response
      Get a message header as a single string value. Each single header value is converted to String using a RuntimeDelegate.HeaderDelegate if one is available via RuntimeDelegate.createHeaderDelegate(java.lang.Class) for the header value class or using its toString method if a header delegate is not available.
      Specified by:
      getHeaderString in class Response
      Parameters:
      name - the message header.
      Returns:
      the message header value. If the message header is not present then null is returned. If the message header is present but has no value then the empty string is returned. If the message header is present more than once then the values of joined together and separated by a ',' character.
      See Also:
    • getLocation

      public URI getLocation()
      Description copied from class: Response
      Get the location.
      Specified by:
      getLocation in class Response
      Returns:
      the location URI, otherwise null if not present.
    • getLinks

      public Set<Link> getLinks()
      Description copied from class: Response
      Get the links attached to the message as headers. Any links in the message that are relative must be resolved with respect to the actual request URI that produced this response. Note that request URIs may be updated by filters, so the actual request URI may differ from that in the original invocation.
      Specified by:
      getLinks in class Response
      Returns:
      links, may return empty Set if no links are present. Does not return null.
    • hasLink

      public boolean hasLink(String relation)
      Description copied from class: Response
      Check if link for relation exists.
      Specified by:
      hasLink in class Response
      Parameters:
      relation - link relation.
      Returns:
      true if the link for the relation is present in the message headers, false otherwise.
    • getLink

      public Link getLink(String relation)
      Description copied from class: Response
      Get the link for the relation. A relative link is resolved with respect to the actual request URI that produced this response. Note that request URIs may be updated by filters, so the actual request URI may differ from that in the original invocation.
      Specified by:
      getLink in class Response
      Parameters:
      relation - link relation.
      Returns:
      the link for the relation, otherwise null if not present.
    • getLinkBuilder

      public Link.Builder getLinkBuilder(String relation)
      Description copied from class: Response
      Convenience method that returns a Link.Builder for the relation. See Response.getLink(java.lang.String) for more information.
      Specified by:
      getLinkBuilder in class Response
      Parameters:
      relation - link relation.
      Returns:
      the link builder for the relation, otherwise null if not present.