Class ContainerResponse

    • Constructor Detail

      • ContainerResponse

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

      • 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).
      • getRequestContext

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

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

        public boolean hasLink​(String relation)
        Description copied from interface: ContainerResponseContext
        Check if link for relation exists.
        Specified by:
        hasLink in interface ContainerResponseContext
        Parameters:
        relation - link relation.
        Returns:
        true if the for the relation link exists, false otherwise.
      • hasEntity

        public boolean hasEntity()
        Description copied from interface: ContainerResponseContext
        Check if there is an entity available in the response. The method returns true if the entity is present, returns false otherwise.
        Specified by:
        hasEntity in interface ContainerResponseContext
        Returns:
        true if there is an entity present in the message, false otherwise.
      • getEntity

        public Object getEntity()
        Description copied from interface: ContainerResponseContext
        Get the message entity Java instance. Returns null if the message does not contain an entity.
        Specified by:
        getEntity in interface ContainerResponseContext
        Returns:
        the message entity or null if message does not contain an entity body.
      • 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
      • setMediaType

        public void setMediaType​(MediaType mediaType)
        Set the message content media type.
        Parameters:
        mediaType - message content media type.
      • 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()
        Description copied from interface: ContainerResponseContext
        Get the annotations attached to the entity instance.

        Note that the returned annotations array contains only those annotations explicitly attached to entity instance (such as the ones attached using Response.ResponseBuilder.entity(Object, java.lang.annotation.Annotation[]) method as well as the ones attached to the resource method that has returned the response). The entity instance annotations array does not include annotations declared on the entity implementation class or its ancestors.

        Note that container response filters invoked earlier in the filter chain may modify the entity annotations value, in which case this getter method would return the last annotations value set by a container response filter invoked earlier in the filter chain.

        For example:

         @Path("my-resource")
         public class MyResource {
           private final Annotations[] extras = ... ;
        
           @GET
           @Custom
           public String getAnnotatedMe() {
             return Response.ok().entity("Annotated me", extras).build();
           }
           ...
         }
         

        The container response context for a response returned from the getMe() method above would contain all the annotations declared on the getAnnotatedMe() method (@GET, @Custom) as well as all the annotations from the extras field, provided this value has not been replaced by any container response filter invoked earlier.

        Similarly:

         @Custom
         public class AnnotatedMe { ... }
        
         @Path("my-resource")
         public class MyResource {
           private final Annotations[] extras = ... ;
        
           @GET
           public AnnotatedMe getMe() {
             return Response.ok().entity(new AnnotatedMe(), extras).build();
           }
           ...
         }
         

        Provided that the value has not been replaced by any container response filter invoked earlier, the container response context for a response returned from the getMe() method above would contain all the annotations on the getMe() method (@GET) as well as all the annotations from the extras field. It would however not contain any annotations declared on the AnnotatedMe class.

        Specified by:
        getEntityAnnotations in interface ContainerResponseContext
        Returns:
        annotations attached to the entity instance.
      • setEntityAnnotations

        public void setEntityAnnotations​(Annotation[] annotations)
        Set the annotations attached to the entity.
        Parameters:
        annotations - entity annotations.
      • 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​(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.
      • 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.