Interface ContainerResponseContext
-
public interface ContainerResponseContextContainer response filter context. A mutable class that provides response-specific information for the filter, such as message headers, message entity or request-scoped properties. The exposed setters allow modification of the exposed response-specific information.- Since:
- 2.0
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description java.util.Set<java.lang.String>getAllowedMethods()Get the allowed HTTP methods from the Allow HTTP header.java.util.Map<java.lang.String,NewCookie>getCookies()Get any new cookies set on the response message.java.util.DategetDate()Get message date.java.lang.ObjectgetEntity()Get the message entity Java instance.java.lang.annotation.Annotation[]getEntityAnnotations()Get the annotations attached to the entity instance.java.lang.Class<?>getEntityClass()Get the raw entity type information.java.io.OutputStreamgetEntityStream()Get the entity output stream.EntityTaggetEntityTag()Get the entity tag.java.lang.reflect.TypegetEntityType()Get the generic entity type information.MultivaluedMap<java.lang.String,java.lang.Object>getHeaders()Get the mutable response headers multivalued map.java.lang.StringgetHeaderString(java.lang.String name)Get a message header as a single string value.java.util.LocalegetLanguage()Get the language of the entity.java.util.DategetLastModified()Get the last modified date.intgetLength()Get Content-Length value.LinkgetLink(java.lang.String relation)Get the link for the relation.Link.BuildergetLinkBuilder(java.lang.String relation)Convenience method that returns aLink.Builderfor the relation.java.util.Set<Link>getLinks()Get the links attached to the message as header.java.net.URIgetLocation()Get the location.MediaTypegetMediaType()Get the media type of the entity.intgetStatus()Get the status code associated with the response.Response.StatusTypegetStatusInfo()Get the complete status information associated with the response.MultivaluedMap<java.lang.String,java.lang.String>getStringHeaders()Get a string view of header values associated with the message.booleanhasEntity()Check if there is an entity available in the response.booleanhasLink(java.lang.String relation)Check if link for relation exists.voidsetEntity(java.lang.Object entity)Set a new message entity.voidsetEntity(java.lang.Object entity, java.lang.annotation.Annotation[] annotations, MediaType mediaType)Set a new message entity, including the attached annotations and the media type.voidsetEntityStream(java.io.OutputStream outputStream)Set a new entity output stream.voidsetStatus(int code)Set a new response status code.voidsetStatusInfo(Response.StatusType statusInfo)Set the complete status information (status code and reason phrase) associated with the response.
-
-
-
Method Detail
-
getStatus
int getStatus()
Get the status code associated with the response.- Returns:
- the response status code or -1 if the status was not set.
-
setStatus
void setStatus(int code)
Set a new response status code.- Parameters:
code- new status code.
-
getStatusInfo
Response.StatusType getStatusInfo()
Get the complete status information associated with the response.- Returns:
- the response status information or
nullif the status was not set.
-
setStatusInfo
void setStatusInfo(Response.StatusType statusInfo)
Set the complete status information (status code and reason phrase) associated with the response.- Parameters:
statusInfo- the response status information.
-
getHeaders
MultivaluedMap<java.lang.String,java.lang.Object> getHeaders()
Get the mutable response headers multivalued map.- Returns:
- mutable multivalued map of response headers.
- See Also:
getStringHeaders(),getHeaderString(String)
-
getStringHeaders
MultivaluedMap<java.lang.String,java.lang.String> getStringHeaders()
Get a string view of header values associated with the message. Changes in the underlyingheaders mapare reflected in this view.The method converts the non-string header values to strings using a
RuntimeDelegate.HeaderDelegateif one is available viaRuntimeDelegate.createHeaderDelegate(java.lang.Class)for the class of the value or using the valuestoStringmethod if a header delegate is not available.- Returns:
- response headers as a string view of header values.
- See Also:
getHeaders(),getHeaderString(String)
-
getHeaderString
java.lang.String getHeaderString(java.lang.String name)
Get a message header as a single string value. Each single header value is converted to String using aRuntimeDelegate.HeaderDelegateif one is available viaRuntimeDelegate.createHeaderDelegate(java.lang.Class)for the header value class or using itstoStringmethod 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
nullis 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. - See Also:
getHeaders(),getStringHeaders()
-
getAllowedMethods
java.util.Set<java.lang.String> getAllowedMethods()
Get the allowed HTTP methods from the Allow HTTP header.- Returns:
- the allowed HTTP methods, all methods will returned as upper case strings.
-
getDate
java.util.Date getDate()
Get message date.- Returns:
- the message date, otherwise
nullif not present.
-
getLanguage
java.util.Locale getLanguage()
Get the language of the entity.- Returns:
- the language of the entity or
nullif not specified
-
getLength
int getLength()
Get Content-Length value.- Returns:
- Content-Length as integer if present and valid number. In other cases returns -1.
-
getMediaType
MediaType getMediaType()
Get the media type of the entity.- Returns:
- the media type or
nullif not specified (e.g. there's no response entity).
-
getCookies
java.util.Map<java.lang.String,NewCookie> getCookies()
Get any new cookies set on the response message.- Returns:
- a read-only map of cookie name (String) to a
new cookie.
-
getEntityTag
EntityTag getEntityTag()
Get the entity tag.- Returns:
- the entity tag, otherwise
nullif not present.
-
getLastModified
java.util.Date getLastModified()
Get the last modified date.- Returns:
- the last modified date, otherwise
nullif not present.
-
getLocation
java.net.URI getLocation()
Get the location.- Returns:
- the location URI, otherwise
nullif not present.
-
getLinks
java.util.Set<Link> getLinks()
Get the links attached to the message as header.- Returns:
- links, may return empty
Setif no links are present. Never returnsnull.
-
hasLink
boolean hasLink(java.lang.String relation)
Check if link for relation exists.- Parameters:
relation- link relation.- Returns:
trueif the for the relation link exists,falseotherwise.
-
getLink
Link getLink(java.lang.String relation)
Get the link for the relation.- Parameters:
relation- link relation.- Returns:
- the link for the relation, otherwise
nullif not present.
-
getLinkBuilder
Link.Builder getLinkBuilder(java.lang.String relation)
Convenience method that returns aLink.Builderfor the relation.- Parameters:
relation- link relation.- Returns:
- the link builder for the relation, otherwise
nullif not present.
-
hasEntity
boolean hasEntity()
Check if there is an entity available in the response. The method returnstrueif the entity is present, returnsfalseotherwise.- Returns:
trueif there is an entity present in the message,falseotherwise.
-
getEntity
java.lang.Object getEntity()
Get the message entity Java instance. Returnsnullif the message does not contain an entity.- Returns:
- the message entity or
nullif message does not contain an entity body.
-
getEntityClass
java.lang.Class<?> getEntityClass()
Get the raw entity type information.- Returns:
- raw entity type.
-
getEntityType
java.lang.reflect.Type getEntityType()
Get the generic entity type information.- Returns:
- declared generic entity type.
-
setEntity
void setEntity(java.lang.Object entity)
Set a new message entity. The existing entityannotationsandmedia typeare preserved.It is the callers responsibility to wrap the actual entity with
GenericEntityif preservation of its generic type is required.- Parameters:
entity- entity object.- See Also:
setEntity(Object, java.lang.annotation.Annotation[], javax.ws.rs.core.MediaType),MessageBodyWriter
-
setEntity
void setEntity(java.lang.Object entity, java.lang.annotation.Annotation[] annotations, MediaType mediaType)Set a new message entity, including the attached annotations and the media type.It is the callers responsibility to wrap the actual entity with
GenericEntityif preservation of its generic type is required.- Parameters:
entity- entity object.annotations- annotations attached to the entity instance.mediaType- entity media type.- See Also:
setEntity(Object),MessageBodyWriter
-
getEntityAnnotations
java.lang.annotation.Annotation[] getEntityAnnotations()
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 or the ones attached to the resource method that returned the response). The entity instance annotations array does not include annotations declared on the entity implementation class or its ancestors.- Returns:
- annotations attached to the entity instance.
-
getEntityStream
java.io.OutputStream getEntityStream()
Get the entity output stream. The JAX-RS runtime is responsible for closing the output stream.- Returns:
- entity output stream.
-
setEntityStream
void setEntityStream(java.io.OutputStream outputStream)
Set a new entity output stream. The JAX-RS runtime is responsible for closing the output stream.- Parameters:
outputStream- new entity output stream.
-
-