public interface ContainerResponseContext
Modifier and Type | Method and 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.Date |
getDate()
Get message date.
|
java.lang.Object |
getEntity()
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.OutputStream |
getEntityStream()
Get the entity output stream.
|
EntityTag |
getEntityTag()
Get the entity tag.
|
java.lang.reflect.Type |
getEntityType()
Get the generic entity type information.
|
MultivaluedMap<java.lang.String,java.lang.Object> |
getHeaders()
Get the mutable response headers multivalued map.
|
java.lang.String |
getHeaderString(java.lang.String name)
Get a message header as a single string value.
|
java.util.Locale |
getLanguage()
Get the language of the entity.
|
java.util.Date |
getLastModified()
Get the last modified date.
|
int |
getLength()
Get Content-Length value.
|
Link |
getLink(java.lang.String relation)
Get the link for the relation.
|
Link.Builder |
getLinkBuilder(java.lang.String relation)
Convenience method that returns a
Link.Builder for the relation. |
java.util.Set<Link> |
getLinks()
Get the links attached to the message as header.
|
java.net.URI |
getLocation()
Get the location.
|
MediaType |
getMediaType()
Get the media type of the entity.
|
int |
getStatus()
Get the status code associated with the response.
|
Response.StatusType |
getStatusInfo()
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.
|
boolean |
hasEntity()
Check if there is an entity available in the response.
|
boolean |
hasLink(java.lang.String relation)
Check if link for relation exists.
|
void |
setEntity(java.lang.Object entity)
Set a new message entity.
|
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.
|
void |
setEntityStream(java.io.OutputStream outputStream)
Set a new entity output stream.
|
void |
setStatus(int code)
Set a new response status code.
|
void |
setStatusInfo(Response.StatusType statusInfo)
Set the complete status information (status code and reason phrase) associated with the response.
|
int getStatus()
void setStatus(int code)
code
- new status code.Response.StatusType getStatusInfo()
null
if the status was not set.void setStatusInfo(Response.StatusType statusInfo)
statusInfo
- the response status information.MultivaluedMap<java.lang.String,java.lang.Object> getHeaders()
getStringHeaders()
,
getHeaderString(String)
MultivaluedMap<java.lang.String,java.lang.String> getStringHeaders()
headers map
are reflected in this view.
The method converts the non-string header values to strings using a
RuntimeDelegate.HeaderDelegate
if one is available via
RuntimeDelegate.createHeaderDelegate(java.lang.Class)
for the class of the value or using the
values toString
method if a header delegate is not available.
getHeaders()
,
getHeaderString(String)
java.lang.String getHeaderString(java.lang.String name)
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.name
- the message header.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()
,
getStringHeaders()
java.util.Set<java.lang.String> getAllowedMethods()
java.util.Date getDate()
null
if not present.java.util.Locale getLanguage()
null
if not specifiedint getLength()
MediaType getMediaType()
null
if not specified (e.g. there's no response entity).java.util.Map<java.lang.String,NewCookie> getCookies()
new cookie
.EntityTag getEntityTag()
null
if not present.java.util.Date getLastModified()
null
if not present.java.net.URI getLocation()
null
if not present.java.util.Set<Link> getLinks()
Set
if no links are present. Never returns null
.boolean hasLink(java.lang.String relation)
relation
- link relation.true
if the for the relation link exists, false
otherwise.Link getLink(java.lang.String relation)
relation
- link relation.null
if not present.Link.Builder getLinkBuilder(java.lang.String relation)
Link.Builder
for the relation.relation
- link relation.null
if not present.boolean hasEntity()
true
if the entity is present, returns false
otherwise.true
if there is an entity present in the message, false
otherwise.java.lang.Object getEntity()
null
if the message does not contain an entity.null
if message does not contain an entity body.java.lang.Class<?> getEntityClass()
java.lang.reflect.Type getEntityType()
void setEntity(java.lang.Object entity)
annotations
and media type
are preserved.
It is the callers responsibility to wrap the actual entity with GenericEntity
if
preservation of its generic type is required.
entity
- entity object.setEntity(Object, java.lang.annotation.Annotation[], jakarta.ws.rs.core.MediaType)
,
MessageBodyWriter
void setEntity(java.lang.Object entity, java.lang.annotation.Annotation[] annotations, MediaType mediaType)
It is the callers responsibility to wrap the actual entity with GenericEntity
if
preservation of its generic type is required.
entity
- entity object.annotations
- annotations attached to the entity instance.mediaType
- entity media type.setEntity(Object)
,
MessageBodyWriter
java.lang.annotation.Annotation[] getEntityAnnotations()
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 as well as
the ones attached to the resource method that has returned the response). The entity instance annotations array does
not include annotations declared on the entity implementation class or its ancestors.
Note that container response filters invoked earlier in the filter chain may modify the entity annotations value, in which case this getter method would return the last annotations value set by a container response filter invoked earlier in the filter chain.
For example:
@Path("my-resource") public class MyResource { private final Annotations[] extras = ... ; @GET @Custom public String getAnnotatedMe() { return Response.ok().entity("Annotated me", extras).build(); } ... }
The container response context for a response returned from the getMe()
method above would contain all the
annotations declared on the getAnnotatedMe()
method (@GET
, @Custom
) as well as all the
annotations from the extras
field, provided this value has not been replaced by any container response filter
invoked earlier.
Similarly:
@Custom public class AnnotatedMe { ... } @Path("my-resource") public class MyResource { private final Annotations[] extras = ... ; @GET public AnnotatedMe getMe() { return Response.ok().entity(new AnnotatedMe(), extras).build(); } ... }
Provided that the value has not been replaced by any container response filter invoked earlier, the container
response context for a response returned from the getMe()
method above would contain all the annotations on
the getMe()
method (@GET
) as well as all the annotations from the extras
field. It would
however not contain any annotations declared on the AnnotatedMe
class.
java.io.OutputStream getEntityStream()
void setEntityStream(java.io.OutputStream outputStream)
outputStream
- new entity output stream.