Class ContainerResponse

java.lang.Object
org.glassfish.jersey.server.ContainerResponse
All Implemented Interfaces:
javax.ws.rs.container.ContainerResponseContext

public class ContainerResponse extends Object implements javax.ws.rs.container.ContainerResponseContext
Jersey container response context.
  • Field Details

    • status

      private javax.ws.rs.core.Response.StatusType status
    • requestContext

      private final ContainerRequest requestContext
    • messageContext

      private final OutboundMessageContext messageContext
    • mappedFromException

      private boolean mappedFromException
    • closed

      private boolean closed
  • Constructor Details

    • ContainerResponse

      public ContainerResponse(ContainerRequest requestContext, javax.ws.rs.core.Response response)
      Create a new Jersey container response context.
      Parameters:
      requestContext - associated container request context.
      response - response instance initializing the response context.
    • ContainerResponse

      ContainerResponse(ContainerRequest requestContext, OutboundJaxrsResponse response)
      Create a new Jersey container response context.
      Parameters:
      requestContext - associated container request context.
      response - response instance initializing the response context.
  • Method Details

    • isMappedFromException

      public boolean isMappedFromException()
      Returns true if the response is result of the exception (for example created during exception mapping).
      Returns:
      True if this response was created based on the exception, false otherwise.
    • setMappedFromException

      public void setMappedFromException(boolean mappedFromException)
      Sets the flag indicating whether the response was created based on the exception.
      Parameters:
      mappedFromException - True if this exception if result of the exception (for example result of exception mapping).
    • getStatus

      public int getStatus()
      Specified by:
      getStatus in interface javax.ws.rs.container.ContainerResponseContext
    • setStatus

      public void setStatus(int code)
      Specified by:
      setStatus in interface javax.ws.rs.container.ContainerResponseContext
    • setStatusInfo

      public void setStatusInfo(javax.ws.rs.core.Response.StatusType status)
      Specified by:
      setStatusInfo in interface javax.ws.rs.container.ContainerResponseContext
    • getStatusInfo

      public javax.ws.rs.core.Response.StatusType getStatusInfo()
      Specified by:
      getStatusInfo in interface javax.ws.rs.container.ContainerResponseContext
    • getRequestContext

      public ContainerRequest getRequestContext()
      Get the associated container request context paired with this response context.
      Returns:
      associated container request context.
    • getCookies

      public Map<String,javax.ws.rs.core.NewCookie> getCookies()
      Specified by:
      getCookies in interface javax.ws.rs.container.ContainerResponseContext
    • getWrappedMessageContext

      public OutboundMessageContext getWrappedMessageContext()
      Get the wrapped response message context.
      Returns:
      wrapped response message context.
    • getHeaderString

      public String getHeaderString(String name)
      Specified by:
      getHeaderString in interface javax.ws.rs.container.ContainerResponseContext
    • getHeaders

      public javax.ws.rs.core.MultivaluedMap<String,Object> getHeaders()
      Specified by:
      getHeaders in interface javax.ws.rs.container.ContainerResponseContext
    • getStringHeaders

      public javax.ws.rs.core.MultivaluedMap<String,String> getStringHeaders()
      Specified by:
      getStringHeaders in interface javax.ws.rs.container.ContainerResponseContext
    • getDate

      public Date getDate()
      Specified by:
      getDate in interface javax.ws.rs.container.ContainerResponseContext
    • getLanguage

      public Locale getLanguage()
      Specified by:
      getLanguage in interface javax.ws.rs.container.ContainerResponseContext
    • getMediaType

      public javax.ws.rs.core.MediaType getMediaType()
      Specified by:
      getMediaType in interface javax.ws.rs.container.ContainerResponseContext
    • getAllowedMethods

      public Set<String> getAllowedMethods()
      Specified by:
      getAllowedMethods in interface javax.ws.rs.container.ContainerResponseContext
    • getLength

      public int getLength()
      Specified by:
      getLength in interface javax.ws.rs.container.ContainerResponseContext
    • getEntityTag

      public javax.ws.rs.core.EntityTag getEntityTag()
      Specified by:
      getEntityTag in interface javax.ws.rs.container.ContainerResponseContext
    • getLastModified

      public Date getLastModified()
      Specified by:
      getLastModified in interface javax.ws.rs.container.ContainerResponseContext
    • getLocation

      public URI getLocation()
      Specified by:
      getLocation in interface javax.ws.rs.container.ContainerResponseContext
    • getLinks

      public Set<javax.ws.rs.core.Link> getLinks()
      Specified by:
      getLinks in interface javax.ws.rs.container.ContainerResponseContext
    • hasLink

      public boolean hasLink(String relation)
      Specified by:
      hasLink in interface javax.ws.rs.container.ContainerResponseContext
    • getLink

      public javax.ws.rs.core.Link getLink(String relation)
      Specified by:
      getLink in interface javax.ws.rs.container.ContainerResponseContext
    • getLinkBuilder

      public javax.ws.rs.core.Link.Builder getLinkBuilder(String relation)
      Specified by:
      getLinkBuilder in interface javax.ws.rs.container.ContainerResponseContext
    • hasEntity

      public boolean hasEntity()
      Specified by:
      hasEntity in interface javax.ws.rs.container.ContainerResponseContext
    • getEntity

      public Object getEntity()
      Specified by:
      getEntity in interface javax.ws.rs.container.ContainerResponseContext
    • setEntity

      public void setEntity(Object entity)
      Set a new message message entity.
      Specified by:
      setEntity in interface javax.ws.rs.container.ContainerResponseContext
      Parameters:
      entity - entity object.
      See Also:
      • MessageBodyWriter
    • setEntity

      public void setEntity(Object entity, Annotation[] annotations)
      Set a new message message entity.
      Parameters:
      entity - entity object.
      annotations - annotations attached to the entity.
      See Also:
      • MessageBodyWriter
    • setEntity

      public void setEntity(Object entity, Type type, Annotation[] annotations)
      Set a new message message entity.
      Parameters:
      entity - entity object.
      type - declared entity class.
      annotations - annotations attached to the entity.
      See Also:
      • MessageBodyWriter
    • setEntity

      public void setEntity(Object entity, Annotation[] annotations, javax.ws.rs.core.MediaType mediaType)
      Specified by:
      setEntity in interface javax.ws.rs.container.ContainerResponseContext
    • setMediaType

      public void setMediaType(javax.ws.rs.core.MediaType mediaType)
      Set the message content media type.
      Parameters:
      mediaType - message content media type.
    • getEntityClass

      public Class<?> getEntityClass()
      Specified by:
      getEntityClass in interface javax.ws.rs.container.ContainerResponseContext
    • getEntityType

      public Type getEntityType()
      Specified by:
      getEntityType in interface javax.ws.rs.container.ContainerResponseContext
    • setEntityType

      public void setEntityType(Type type)
      Set the message entity type information. This method overrides any computed or previously set entity type information.
      Parameters:
      type - overriding message entity type.
    • getEntityAnnotations

      public Annotation[] getEntityAnnotations()
      Specified by:
      getEntityAnnotations in interface javax.ws.rs.container.ContainerResponseContext
    • setEntityAnnotations

      public void setEntityAnnotations(Annotation[] annotations)
      Set the annotations attached to the entity.
      Parameters:
      annotations - entity annotations.
    • getEntityStream

      public OutputStream getEntityStream()
      Specified by:
      getEntityStream in interface javax.ws.rs.container.ContainerResponseContext
    • setEntityStream

      public void setEntityStream(OutputStream outputStream)
      Specified by:
      setEntityStream in interface javax.ws.rs.container.ContainerResponseContext
    • setStreamProvider

      public void setStreamProvider(OutboundMessageContext.StreamProvider streamProvider)
      Set the output stream provider callback.

      This method must be called before first bytes are written to the entity stream.

      Parameters:
      streamProvider - non-null output stream provider.
    • enableBuffering

      public void enableBuffering(javax.ws.rs.core.Configuration configuration)
      Enable a buffering of serialized entity. The buffering will be configured from configuration. The property determining the size of the buffer is CommonProperties.OUTBOUND_CONTENT_LENGTH_BUFFER.

      The buffering functionality is by default disabled and could be enabled by calling this method. In this case this method must be called before first bytes are written to the entity stream.

      Parameters:
      configuration - runtime configuration.
    • commitStream

      public void commitStream() throws IOException
      Commit the entity stream unless already committed.
      Throws:
      IOException - in case of the IO error.
    • isCommitted

      public boolean isCommitted()
      Returns true if the entity stream has been committed.
      Returns:
      true if the entity stream has been committed. Otherwise returns false.
    • close

      public void close()
      Closes the response. Flushes and closes the entity stream, frees up container resources associated with the corresponding request.
    • isChunked

      public boolean isChunked()
      Returns true if the response entity is a ChunkedOutput instance.
      Returns:
      true if the entity is a ChunkedOutput instance, false otherwise.