Package org.glassfish.jersey.server
Class ContainerResponse
- java.lang.Object
-
- org.glassfish.jersey.server.ContainerResponse
-
- All Implemented Interfaces:
ContainerResponseContext
public class ContainerResponse extends Object implements ContainerResponseContext
Jersey container response context.- Author:
- Marek Potociar
-
-
Constructor Summary
Constructors Constructor Description ContainerResponse(ContainerRequest requestContext, Response response)
Create a new Jersey container response context.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Closes the response.void
commitStream()
Commit theentity stream
unless already committed.void
enableBuffering(Configuration configuration)
Enable a buffering of serialized entity.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)
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()
Returnstrue
if the response entity is aChunkedOutput
instance.boolean
isCommitted()
Returnstrue
if the entity stream has been committed.boolean
isMappedFromException()
Returns true if the response is result of the exception (for example created duringexception mapping
).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
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
setMappedFromException(boolean mappedFromException)
Sets the flag indicating whether the response was created based on the exception.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 callback.
-
-
-
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 duringexception 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 ofexception mapping
).
-
getStatus
public int getStatus()
- Specified by:
getStatus
in interfaceContainerResponseContext
-
setStatus
public void setStatus(int code)
- Specified by:
setStatus
in interfaceContainerResponseContext
-
setStatusInfo
public void setStatusInfo(Response.StatusType status)
- Specified by:
setStatusInfo
in interfaceContainerResponseContext
-
getStatusInfo
public Response.StatusType getStatusInfo()
- Specified by:
getStatusInfo
in interfaceContainerResponseContext
-
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 interfaceContainerResponseContext
-
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 interfaceContainerResponseContext
-
getHeaders
public MultivaluedMap<String,Object> getHeaders()
- Specified by:
getHeaders
in interfaceContainerResponseContext
-
getStringHeaders
public MultivaluedMap<String,String> getStringHeaders()
- Specified by:
getStringHeaders
in interfaceContainerResponseContext
-
getDate
public Date getDate()
- Specified by:
getDate
in interfaceContainerResponseContext
-
getLanguage
public Locale getLanguage()
- Specified by:
getLanguage
in interfaceContainerResponseContext
-
getMediaType
public MediaType getMediaType()
- Specified by:
getMediaType
in interfaceContainerResponseContext
-
getAllowedMethods
public Set<String> getAllowedMethods()
- Specified by:
getAllowedMethods
in interfaceContainerResponseContext
-
getLength
public int getLength()
- Specified by:
getLength
in interfaceContainerResponseContext
-
getEntityTag
public EntityTag getEntityTag()
- Specified by:
getEntityTag
in interfaceContainerResponseContext
-
getLastModified
public Date getLastModified()
- Specified by:
getLastModified
in interfaceContainerResponseContext
-
getLocation
public URI getLocation()
- Specified by:
getLocation
in interfaceContainerResponseContext
-
getLinks
public Set<Link> getLinks()
- Specified by:
getLinks
in interfaceContainerResponseContext
-
hasLink
public boolean hasLink(String relation)
- Specified by:
hasLink
in interfaceContainerResponseContext
-
getLink
public Link getLink(String relation)
- Specified by:
getLink
in interfaceContainerResponseContext
-
getLinkBuilder
public Link.Builder getLinkBuilder(String relation)
- Specified by:
getLinkBuilder
in interfaceContainerResponseContext
-
hasEntity
public boolean hasEntity()
- Specified by:
hasEntity
in interfaceContainerResponseContext
-
getEntity
public Object getEntity()
- Specified by:
getEntity
in interfaceContainerResponseContext
-
setEntity
public void setEntity(Object entity)
Set a new message message entity.- Specified by:
setEntity
in interfaceContainerResponseContext
- 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 interfaceContainerResponseContext
-
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 interfaceContainerResponseContext
-
getEntityType
public Type getEntityType()
- Specified by:
getEntityType
in interfaceContainerResponseContext
-
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 interfaceContainerResponseContext
-
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 interfaceContainerResponseContext
-
setEntityStream
public void setEntityStream(OutputStream outputStream)
- Specified by:
setEntityStream
in interfaceContainerResponseContext
-
setStreamProvider
public void setStreamProvider(OutboundMessageContext.StreamProvider streamProvider)
Set the output stream provider callback. This method must be called before first bytes are written to theentity 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 isCommonProperties.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 theentity stream
.- Parameters:
configuration
- runtime configuration.
-
commitStream
public void commitStream() throws IOException
Commit theentity stream
unless already committed.- Throws:
IOException
- in case of the IO error.
-
isCommitted
public boolean isCommitted()
Returnstrue
if the entity stream has been committed.- Returns:
true
if the entity stream has been committed. Otherwise returnsfalse
.
-
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()
Returnstrue
if the response entity is aChunkedOutput
instance.- Returns:
true
if the entity is aChunkedOutput
instance,false
otherwise.
-
-