Package org.glassfish.jersey.server
Class ContainerResponse
- java.lang.Object
-
- org.glassfish.jersey.server.ContainerResponse
-
- All Implemented Interfaces:
jakarta.ws.rs.container.ContainerResponseContext
public class ContainerResponse extends Object implements jakarta.ws.rs.container.ContainerResponseContext
Jersey container response context.- Author:
- Marek Potociar
-
-
Constructor Summary
Constructors Constructor Description ContainerResponse(ContainerRequest requestContext, jakarta.ws.rs.core.Response 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(jakarta.ws.rs.core.Configuration configuration)Enable a buffering of serialized entity.Set<String>getAllowedMethods()Map<String,jakarta.ws.rs.core.NewCookie>getCookies()DategetDate()ObjectgetEntity()Annotation[]getEntityAnnotations()Class<?>getEntityClass()OutputStreamgetEntityStream()jakarta.ws.rs.core.EntityTaggetEntityTag()TypegetEntityType()jakarta.ws.rs.core.MultivaluedMap<String,Object>getHeaders()StringgetHeaderString(String name)LocalegetLanguage()DategetLastModified()intgetLength()jakarta.ws.rs.core.LinkgetLink(String relation)jakarta.ws.rs.core.Link.BuildergetLinkBuilder(String relation)Set<jakarta.ws.rs.core.Link>getLinks()URIgetLocation()jakarta.ws.rs.core.MediaTypegetMediaType()ContainerRequestgetRequestContext()Get the associated container request context paired with this response context.intgetStatus()jakarta.ws.rs.core.Response.StatusTypegetStatusInfo()jakarta.ws.rs.core.MultivaluedMap<String,String>getStringHeaders()OutboundMessageContextgetWrappedMessageContext()Get the wrapped response message context.booleanhasEntity()booleanhasLink(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(Object entity)Set a new message message entity.voidsetEntity(Object entity, Annotation[] annotations)Set a new message message entity.voidsetEntity(Object entity, Annotation[] annotations, jakarta.ws.rs.core.MediaType mediaType)voidsetEntity(Object entity, Type type, Annotation[] annotations)Set a new message message entity.voidsetEntityAnnotations(Annotation[] annotations)Set the annotations attached to the entity.voidsetEntityStream(OutputStream outputStream)voidsetEntityType(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(jakarta.ws.rs.core.MediaType mediaType)Set the message content media type.voidsetStatus(int code)voidsetStatusInfo(jakarta.ws.rs.core.Response.StatusType status)voidsetStreamProvider(OutboundMessageContext.StreamProvider streamProvider)Set the output stream provider callback.
-
-
-
Constructor Detail
-
ContainerResponse
public ContainerResponse(ContainerRequest requestContext, jakarta.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.
-
-
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 interfacejakarta.ws.rs.container.ContainerResponseContext
-
setStatus
public void setStatus(int code)
- Specified by:
setStatusin interfacejakarta.ws.rs.container.ContainerResponseContext
-
setStatusInfo
public void setStatusInfo(jakarta.ws.rs.core.Response.StatusType status)
- Specified by:
setStatusInfoin interfacejakarta.ws.rs.container.ContainerResponseContext
-
getStatusInfo
public jakarta.ws.rs.core.Response.StatusType getStatusInfo()
- Specified by:
getStatusInfoin interfacejakarta.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,jakarta.ws.rs.core.NewCookie> getCookies()
- Specified by:
getCookiesin interfacejakarta.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:
getHeaderStringin interfacejakarta.ws.rs.container.ContainerResponseContext
-
getHeaders
public jakarta.ws.rs.core.MultivaluedMap<String,Object> getHeaders()
- Specified by:
getHeadersin interfacejakarta.ws.rs.container.ContainerResponseContext
-
getStringHeaders
public jakarta.ws.rs.core.MultivaluedMap<String,String> getStringHeaders()
- Specified by:
getStringHeadersin interfacejakarta.ws.rs.container.ContainerResponseContext
-
getDate
public Date getDate()
- Specified by:
getDatein interfacejakarta.ws.rs.container.ContainerResponseContext
-
getLanguage
public Locale getLanguage()
- Specified by:
getLanguagein interfacejakarta.ws.rs.container.ContainerResponseContext
-
getMediaType
public jakarta.ws.rs.core.MediaType getMediaType()
- Specified by:
getMediaTypein interfacejakarta.ws.rs.container.ContainerResponseContext
-
getAllowedMethods
public Set<String> getAllowedMethods()
- Specified by:
getAllowedMethodsin interfacejakarta.ws.rs.container.ContainerResponseContext
-
getLength
public int getLength()
- Specified by:
getLengthin interfacejakarta.ws.rs.container.ContainerResponseContext
-
getEntityTag
public jakarta.ws.rs.core.EntityTag getEntityTag()
- Specified by:
getEntityTagin interfacejakarta.ws.rs.container.ContainerResponseContext
-
getLastModified
public Date getLastModified()
- Specified by:
getLastModifiedin interfacejakarta.ws.rs.container.ContainerResponseContext
-
getLocation
public URI getLocation()
- Specified by:
getLocationin interfacejakarta.ws.rs.container.ContainerResponseContext
-
getLinks
public Set<jakarta.ws.rs.core.Link> getLinks()
- Specified by:
getLinksin interfacejakarta.ws.rs.container.ContainerResponseContext
-
hasLink
public boolean hasLink(String relation)
- Specified by:
hasLinkin interfacejakarta.ws.rs.container.ContainerResponseContext
-
getLink
public jakarta.ws.rs.core.Link getLink(String relation)
- Specified by:
getLinkin interfacejakarta.ws.rs.container.ContainerResponseContext
-
getLinkBuilder
public jakarta.ws.rs.core.Link.Builder getLinkBuilder(String relation)
- Specified by:
getLinkBuilderin interfacejakarta.ws.rs.container.ContainerResponseContext
-
hasEntity
public boolean hasEntity()
- Specified by:
hasEntityin interfacejakarta.ws.rs.container.ContainerResponseContext
-
getEntity
public Object getEntity()
- Specified by:
getEntityin interfacejakarta.ws.rs.container.ContainerResponseContext
-
setEntity
public void setEntity(Object entity)
Set a new message message entity.- Specified by:
setEntityin interfacejakarta.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, jakarta.ws.rs.core.MediaType mediaType)
- Specified by:
setEntityin interfacejakarta.ws.rs.container.ContainerResponseContext
-
setMediaType
public void setMediaType(jakarta.ws.rs.core.MediaType mediaType)
Set the message content media type.- Parameters:
mediaType- message content media type.
-
getEntityClass
public Class<?> getEntityClass()
- Specified by:
getEntityClassin interfacejakarta.ws.rs.container.ContainerResponseContext
-
getEntityType
public Type getEntityType()
- Specified by:
getEntityTypein interfacejakarta.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:
getEntityAnnotationsin interfacejakarta.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:
getEntityStreamin interfacejakarta.ws.rs.container.ContainerResponseContext
-
setEntityStream
public void setEntityStream(OutputStream outputStream)
- Specified by:
setEntityStreamin interfacejakarta.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(jakarta.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 IOExceptionCommit theentity streamunless already committed.- Throws:
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.
-
-