Package org.glassfish.jersey.server
Class ContainerResponse
- java.lang.Object
-
- org.glassfish.jersey.server.ContainerResponse
-
- All Implemented Interfaces:
javax.ws.rs.container.ContainerResponseContext
public class ContainerResponse extends java.lang.Object implements javax.ws.rs.container.ContainerResponseContextJersey container response context.
-
-
Field Summary
Fields Modifier and Type Field Description private booleanclosedprivate booleanmappedFromExceptionprivate OutboundMessageContextmessageContextprivate ContainerRequestrequestContextprivate javax.ws.rs.core.Response.StatusTypestatus
-
Constructor Summary
Constructors Constructor Description ContainerResponse(ContainerRequest requestContext, javax.ws.rs.core.Response response)Create a new Jersey container response context.ContainerResponse(ContainerRequest requestContext, OutboundJaxrsResponse response)Create a new Jersey container response context.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Closes the response.voidcommitStream()Commit theentity streamunless already committed.voidenableBuffering(javax.ws.rs.core.Configuration configuration)Enable a buffering of serialized entity.java.util.Set<java.lang.String>getAllowedMethods()java.util.Map<java.lang.String,javax.ws.rs.core.NewCookie>getCookies()java.util.DategetDate()java.lang.ObjectgetEntity()java.lang.annotation.Annotation[]getEntityAnnotations()java.lang.Class<?>getEntityClass()java.io.OutputStreamgetEntityStream()javax.ws.rs.core.EntityTaggetEntityTag()java.lang.reflect.TypegetEntityType()javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.Object>getHeaders()java.lang.StringgetHeaderString(java.lang.String name)java.util.LocalegetLanguage()java.util.DategetLastModified()intgetLength()javax.ws.rs.core.LinkgetLink(java.lang.String relation)javax.ws.rs.core.Link.BuildergetLinkBuilder(java.lang.String relation)java.util.Set<javax.ws.rs.core.Link>getLinks()java.net.URIgetLocation()javax.ws.rs.core.MediaTypegetMediaType()ContainerRequestgetRequestContext()Get the associated container request context paired with this response context.intgetStatus()javax.ws.rs.core.Response.StatusTypegetStatusInfo()javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.String>getStringHeaders()OutboundMessageContextgetWrappedMessageContext()Get the wrapped response message context.booleanhasEntity()booleanhasLink(java.lang.String relation)booleanisChunked()Returnstrueif the response entity is aChunkedOutputinstance.booleanisCommitted()Returnstrueif the entity stream has been committed.booleanisMappedFromException()Returns true if the response is result of the exception (for example created duringexception mapping).voidsetEntity(java.lang.Object entity)Set a new message message entity.voidsetEntity(java.lang.Object entity, java.lang.annotation.Annotation[] annotations)Set a new message message entity.voidsetEntity(java.lang.Object entity, java.lang.annotation.Annotation[] annotations, javax.ws.rs.core.MediaType mediaType)voidsetEntity(java.lang.Object entity, java.lang.reflect.Type type, java.lang.annotation.Annotation[] annotations)Set a new message message entity.voidsetEntityAnnotations(java.lang.annotation.Annotation[] annotations)Set the annotations attached to the entity.voidsetEntityStream(java.io.OutputStream outputStream)voidsetEntityType(java.lang.reflect.Type type)Set the message entity type information.voidsetMappedFromException(boolean mappedFromException)Sets the flag indicating whether the response was created based on the exception.voidsetMediaType(javax.ws.rs.core.MediaType mediaType)Set the message content media type.voidsetStatus(int code)voidsetStatusInfo(javax.ws.rs.core.Response.StatusType status)voidsetStreamProvider(OutboundMessageContext.StreamProvider streamProvider)Set the output stream provider callback.
-
-
-
Field Detail
-
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 Detail
-
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 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:
getStatusin interfacejavax.ws.rs.container.ContainerResponseContext
-
setStatus
public void setStatus(int code)
- Specified by:
setStatusin interfacejavax.ws.rs.container.ContainerResponseContext
-
setStatusInfo
public void setStatusInfo(javax.ws.rs.core.Response.StatusType status)
- Specified by:
setStatusInfoin interfacejavax.ws.rs.container.ContainerResponseContext
-
getStatusInfo
public javax.ws.rs.core.Response.StatusType getStatusInfo()
- Specified by:
getStatusInfoin interfacejavax.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 java.util.Map<java.lang.String,javax.ws.rs.core.NewCookie> getCookies()
- Specified by:
getCookiesin interfacejavax.ws.rs.container.ContainerResponseContext
-
getWrappedMessageContext
public OutboundMessageContext getWrappedMessageContext()
Get the wrapped response message context.- Returns:
- wrapped response message context.
-
getHeaderString
public java.lang.String getHeaderString(java.lang.String name)
- Specified by:
getHeaderStringin interfacejavax.ws.rs.container.ContainerResponseContext
-
getHeaders
public javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.Object> getHeaders()
- Specified by:
getHeadersin interfacejavax.ws.rs.container.ContainerResponseContext
-
getStringHeaders
public javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.String> getStringHeaders()
- Specified by:
getStringHeadersin interfacejavax.ws.rs.container.ContainerResponseContext
-
getDate
public java.util.Date getDate()
- Specified by:
getDatein interfacejavax.ws.rs.container.ContainerResponseContext
-
getLanguage
public java.util.Locale getLanguage()
- Specified by:
getLanguagein interfacejavax.ws.rs.container.ContainerResponseContext
-
getMediaType
public javax.ws.rs.core.MediaType getMediaType()
- Specified by:
getMediaTypein interfacejavax.ws.rs.container.ContainerResponseContext
-
getAllowedMethods
public java.util.Set<java.lang.String> getAllowedMethods()
- Specified by:
getAllowedMethodsin interfacejavax.ws.rs.container.ContainerResponseContext
-
getLength
public int getLength()
- Specified by:
getLengthin interfacejavax.ws.rs.container.ContainerResponseContext
-
getEntityTag
public javax.ws.rs.core.EntityTag getEntityTag()
- Specified by:
getEntityTagin interfacejavax.ws.rs.container.ContainerResponseContext
-
getLastModified
public java.util.Date getLastModified()
- Specified by:
getLastModifiedin interfacejavax.ws.rs.container.ContainerResponseContext
-
getLocation
public java.net.URI getLocation()
- Specified by:
getLocationin interfacejavax.ws.rs.container.ContainerResponseContext
-
getLinks
public java.util.Set<javax.ws.rs.core.Link> getLinks()
- Specified by:
getLinksin interfacejavax.ws.rs.container.ContainerResponseContext
-
hasLink
public boolean hasLink(java.lang.String relation)
- Specified by:
hasLinkin interfacejavax.ws.rs.container.ContainerResponseContext
-
getLink
public javax.ws.rs.core.Link getLink(java.lang.String relation)
- Specified by:
getLinkin interfacejavax.ws.rs.container.ContainerResponseContext
-
getLinkBuilder
public javax.ws.rs.core.Link.Builder getLinkBuilder(java.lang.String relation)
- Specified by:
getLinkBuilderin interfacejavax.ws.rs.container.ContainerResponseContext
-
hasEntity
public boolean hasEntity()
- Specified by:
hasEntityin interfacejavax.ws.rs.container.ContainerResponseContext
-
getEntity
public java.lang.Object getEntity()
- Specified by:
getEntityin interfacejavax.ws.rs.container.ContainerResponseContext
-
setEntity
public void setEntity(java.lang.Object entity)
Set a new message message entity.- Specified by:
setEntityin interfacejavax.ws.rs.container.ContainerResponseContext- Parameters:
entity- entity object.- See Also:
MessageBodyWriter
-
setEntity
public void setEntity(java.lang.Object entity, java.lang.annotation.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(java.lang.Object entity, java.lang.reflect.Type type, java.lang.annotation.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(java.lang.Object entity, java.lang.annotation.Annotation[] annotations, javax.ws.rs.core.MediaType mediaType)- Specified by:
setEntityin interfacejavax.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 java.lang.Class<?> getEntityClass()
- Specified by:
getEntityClassin interfacejavax.ws.rs.container.ContainerResponseContext
-
getEntityType
public java.lang.reflect.Type getEntityType()
- Specified by:
getEntityTypein interfacejavax.ws.rs.container.ContainerResponseContext
-
setEntityType
public void setEntityType(java.lang.reflect.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 java.lang.annotation.Annotation[] getEntityAnnotations()
- Specified by:
getEntityAnnotationsin interfacejavax.ws.rs.container.ContainerResponseContext
-
setEntityAnnotations
public void setEntityAnnotations(java.lang.annotation.Annotation[] annotations)
Set the annotations attached to the entity.- Parameters:
annotations- entity annotations.
-
getEntityStream
public java.io.OutputStream getEntityStream()
- Specified by:
getEntityStreamin interfacejavax.ws.rs.container.ContainerResponseContext
-
setEntityStream
public void setEntityStream(java.io.OutputStream outputStream)
- Specified by:
setEntityStreamin interfacejavax.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 theentity stream.- Parameters:
streamProvider- non-nulloutput 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 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 java.io.IOExceptionCommit theentity streamunless already committed.- Throws:
java.io.IOException- in case of the IO error.
-
isCommitted
public boolean isCommitted()
Returnstrueif the entity stream has been committed.- Returns:
trueif 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()
Returnstrueif the response entity is aChunkedOutputinstance.- Returns:
trueif the entity is aChunkedOutputinstance,falseotherwise.
-
-