org.glassfish.jersey.server
Class ContainerResponse

java.lang.Object
  extended by org.glassfish.jersey.server.ContainerResponse
All Implemented Interfaces:
ContainerResponseContext

public class ContainerResponse
extends Object
implements ContainerResponseContext

Jersey container response context.

Author:
Marek Potociar (marek.potociar at oracle.com)

Constructor Summary
ContainerResponse(ContainerRequest requestContext, Response response)
          Create a new Jersey container response context.
 
Method Summary
 void close()
          Closes the response.
 void commitStream()
          Commits the entity stream if it wasn't already committed.
 Set<String> getAllowedMethods()
           
 Map<String,NewCookie> getCookies()
           
 Date getDate()
           
 Object getEntity()
           
 Annotation[] getEntityAnnotations()
           
 Class<?> getEntityClass()
           
 OutputStream getEntityStream()
           
 EntityTag getEntityTag()
           
 Type getEntityType()
           
 MultivaluedMap<String,Object> getHeaders()
           
 String getHeaderString(String name)
          Get a message header as a single string value.
 Locale getLanguage()
           
 Date getLastModified()
           
 int getLength()
           
 Link getLink(String relation)
           
 Link.Builder getLinkBuilder(String relation)
           
 Set<Link> getLinks()
           
 URI getLocation()
           
 MediaType getMediaType()
           
 ContainerRequest getRequestContext()
          Get the associated container request context paired with this response context.
 int getStatus()
           
 Response.StatusType getStatusInfo()
           
 MultivaluedMap<String,String> getStringHeaders()
           
 OutboundMessageContext getWrappedMessageContext()
          Get the wrapped response message context.
 boolean hasEntity()
           
 boolean hasLink(String relation)
           
 boolean isChunked()
          Returns true if the response entity is a ChunkedResponse instance.
 boolean isCommitted()
          Returns true if the entity stream has been committed.
 void setEntity(Object entity)
          Set a new message message entity.
 void setEntity(Object entity, Annotation[] annotations)
          Set a new message message entity.
 void setEntity(Object entity, Annotation[] annotations, MediaType mediaType)
           
 void setEntity(Object entity, Type type, Annotation[] annotations)
          Set a new message message entity.
 void setEntity(Object entity, Type type, Annotation[] annotations, MediaType mediaType)
           
 void setEntityAnnotations(Annotation[] annotations)
          Set the annotations attached to the entity.
 void setEntityStream(OutputStream outputStream)
           
 void setEntityType(Type type)
          Set the message entity type information.
 void setMediaType(MediaType mediaType)
          Set the message content media type.
 void setStatus(int code)
           
 void setStatusInfo(Response.StatusType status)
           
 void setStreamProvider(OutboundMessageContext.StreamProvider streamProvider)
          Set the output stream provider.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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

getStatus

public int getStatus()
Specified by:
getStatus in interface ContainerResponseContext

setStatus

public void setStatus(int code)
Specified by:
setStatus in interface ContainerResponseContext

setStatusInfo

public void setStatusInfo(Response.StatusType status)
Specified by:
setStatusInfo in interface ContainerResponseContext

getStatusInfo

public Response.StatusType getStatusInfo()
Specified by:
getStatusInfo in interface 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,NewCookie> getCookies()
Specified by:
getCookies in interface ContainerResponseContext

getWrappedMessageContext

public OutboundMessageContext getWrappedMessageContext()
Get the wrapped response message context.

Returns:
wrapped response message context.

getHeaderString

public String getHeaderString(String name)
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.

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.

getHeaders

public MultivaluedMap<String,Object> getHeaders()
Specified by:
getHeaders in interface ContainerResponseContext

getStringHeaders

public MultivaluedMap<String,String> getStringHeaders()

getDate

public Date getDate()
Specified by:
getDate in interface ContainerResponseContext

getLanguage

public Locale getLanguage()
Specified by:
getLanguage in interface ContainerResponseContext

getMediaType

public MediaType getMediaType()
Specified by:
getMediaType in interface ContainerResponseContext

getAllowedMethods

public Set<String> getAllowedMethods()
Specified by:
getAllowedMethods in interface ContainerResponseContext

getLength

public int getLength()
Specified by:
getLength in interface ContainerResponseContext

getEntityTag

public EntityTag getEntityTag()
Specified by:
getEntityTag in interface ContainerResponseContext

getLastModified

public Date getLastModified()
Specified by:
getLastModified in interface ContainerResponseContext

getLocation

public URI getLocation()
Specified by:
getLocation in interface ContainerResponseContext

getLinks

public Set<Link> getLinks()
Specified by:
getLinks in interface ContainerResponseContext

hasLink

public boolean hasLink(String relation)
Specified by:
hasLink in interface ContainerResponseContext

getLink

public Link getLink(String relation)
Specified by:
getLink in interface ContainerResponseContext

getLinkBuilder

public Link.Builder getLinkBuilder(String relation)
Specified by:
getLinkBuilder in interface ContainerResponseContext

hasEntity

public boolean hasEntity()
Specified by:
hasEntity in interface ContainerResponseContext

getEntity

public Object getEntity()
Specified by:
getEntity in interface ContainerResponseContext

setEntity

public void setEntity(Object entity)
Set a new message message entity.

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,
                      MediaType mediaType)
Specified by:
setEntity in interface ContainerResponseContext

setEntity

public void setEntity(Object entity,
                      Type type,
                      Annotation[] annotations,
                      MediaType mediaType)
Specified by:
setEntity in interface ContainerResponseContext

setMediaType

public void setMediaType(MediaType mediaType)
Set the message content media type.

Parameters:
mediaType - message content media type.

getEntityClass

public Class<?> getEntityClass()
Specified by:
getEntityClass in interface ContainerResponseContext

getEntityType

public Type getEntityType()
Specified by:
getEntityType in interface 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 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 ContainerResponseContext

setEntityStream

public void setEntityStream(OutputStream outputStream)
Specified by:
setEntityStream in interface ContainerResponseContext

setStreamProvider

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

Parameters:
streamProvider - output stream provider.

commitStream

public void commitStream()
Commits the entity stream if it wasn't already committed.


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 ChunkedResponse instance.

Returns:
true if the entity is a ChunkedResponse instance, false otherwise.


Copyright © 2007-2012 Oracle Corporation. All Rights Reserved. Use is subject to license terms.