public class ContainerResponseContextImpl extends Object implements SuspendableContainerResponseContext
Modifier and Type | Field and Description |
---|---|
protected HttpResponse |
httpResponse |
protected BuiltResponse |
jaxrsResponse |
protected HttpRequest |
request |
Constructor and Description |
---|
ContainerResponseContextImpl(HttpRequest request,
HttpResponse httpResponse,
BuiltResponse serverResponse)
Deprecated.
|
ContainerResponseContextImpl(HttpRequest request,
HttpResponse httpResponse,
BuiltResponse serverResponse,
ResponseContainerRequestContext requestContext,
ContainerResponseFilter[] responseFilters,
Consumer<Throwable> onComplete,
ServerResponseWriter.RunnableWithIOException continuation) |
Modifier and Type | Method and Description |
---|---|
void |
filter() |
Set<String> |
getAllowedMethods()
Get the allowed HTTP methods from the Allow HTTP header.
|
Map<String,NewCookie> |
getCookies()
Get any new cookies set on the response message.
|
Date |
getDate()
Get message date.
|
Object |
getEntity()
Get the message entity Java instance.
|
Annotation[] |
getEntityAnnotations()
Get the annotations attached to the entity instance.
|
Class<?> |
getEntityClass()
Get the raw entity type information.
|
OutputStream |
getEntityStream()
Get the entity output stream.
|
EntityTag |
getEntityTag()
Get the entity tag.
|
Type |
getEntityType()
Get the generic entity type information.
|
MultivaluedMap<String,Object> |
getHeaders()
Get the mutable response headers multivalued map.
|
String |
getHeaderString(String name)
Get a message header as a single string value.
|
HttpResponse |
getHttpResponse() |
BuiltResponse |
getJaxrsResponse() |
Locale |
getLanguage()
Get the language of the entity.
|
Date |
getLastModified()
Get the last modified date.
|
int |
getLength()
Get Content-Length value.
|
Link |
getLink(String relation)
Get the link for the relation.
|
Link.Builder |
getLinkBuilder(String relation)
Convenience method that returns a
Link.Builder
for the relation. |
Set<Link> |
getLinks()
Get the links attached to the message as header.
|
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<String,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(String relation)
Check if link for relation exists.
|
void |
resume()
Resumes the current response, and proceeds to the next response filter, if any,
or to send the response.
|
void |
resume(Throwable t)
Aborts the current response with the given exception.
|
void |
setEntity(Object entity)
Set a new message entity.
|
void |
setEntity(Object entity,
Annotation[] annotations,
MediaType mediaType)
Set a new message entity, including the attached annotations and the media type.
|
void |
setEntityStream(OutputStream entityStream)
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.
|
void |
suspend()
Suspends the current response.
|
protected final HttpRequest request
protected final HttpResponse httpResponse
protected final BuiltResponse jaxrsResponse
@Deprecated public ContainerResponseContextImpl(HttpRequest request, HttpResponse httpResponse, BuiltResponse serverResponse)
public ContainerResponseContextImpl(HttpRequest request, HttpResponse httpResponse, BuiltResponse serverResponse, ResponseContainerRequestContext requestContext, ContainerResponseFilter[] responseFilters, Consumer<Throwable> onComplete, ServerResponseWriter.RunnableWithIOException continuation)
public BuiltResponse getJaxrsResponse()
public HttpResponse getHttpResponse()
public int getStatus()
ContainerResponseContext
getStatus
in interface ContainerResponseContext
public void setStatus(int code)
ContainerResponseContext
setStatus
in interface ContainerResponseContext
code
- new status code.public Response.StatusType getStatusInfo()
ContainerResponseContext
getStatusInfo
in interface ContainerResponseContext
null
if the status was
not set.public void setStatusInfo(Response.StatusType statusInfo)
ContainerResponseContext
setStatusInfo
in interface ContainerResponseContext
statusInfo
- the response status information.public Class<?> getEntityClass()
ContainerResponseContext
getEntityClass
in interface ContainerResponseContext
public Type getEntityType()
ContainerResponseContext
getEntityType
in interface ContainerResponseContext
public void setEntity(Object entity)
ContainerResponseContext
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.
setEntity
in interface ContainerResponseContext
entity
- entity object.ContainerResponseContext.setEntity(Object, java.lang.annotation.Annotation[], javax.ws.rs.core.MediaType)
,
MessageBodyWriter
public void setEntity(Object entity, Annotation[] annotations, MediaType mediaType)
ContainerResponseContext
It is the callers responsibility to wrap the actual entity with
GenericEntity
if preservation of its generic
type is required.
setEntity
in interface ContainerResponseContext
entity
- entity object.annotations
- annotations attached to the entity instance.mediaType
- entity media type.ContainerResponseContext.setEntity(Object)
,
MessageBodyWriter
public MultivaluedMap<String,Object> getHeaders()
ContainerResponseContext
getHeaders
in interface ContainerResponseContext
ContainerResponseContext.getStringHeaders()
,
ContainerResponseContext.getHeaderString(String)
public Set<String> getAllowedMethods()
ContainerResponseContext
getAllowedMethods
in interface ContainerResponseContext
public Date getDate()
ContainerResponseContext
getDate
in interface ContainerResponseContext
null
if not present.public Locale getLanguage()
ContainerResponseContext
getLanguage
in interface ContainerResponseContext
null
if not specifiedpublic int getLength()
ContainerResponseContext
getLength
in interface ContainerResponseContext
public MediaType getMediaType()
ContainerResponseContext
getMediaType
in interface ContainerResponseContext
null
if not specified (e.g. there's no
response entity).public Map<String,NewCookie> getCookies()
ContainerResponseContext
getCookies
in interface ContainerResponseContext
new cookie
.public EntityTag getEntityTag()
ContainerResponseContext
getEntityTag
in interface ContainerResponseContext
null
if not present.public Date getLastModified()
ContainerResponseContext
getLastModified
in interface ContainerResponseContext
null
if not present.public URI getLocation()
ContainerResponseContext
getLocation
in interface ContainerResponseContext
null
if not present.public Set<Link> getLinks()
ContainerResponseContext
getLinks
in interface ContainerResponseContext
Set
if no links are present. Never
returns null
.public boolean hasLink(String relation)
ContainerResponseContext
hasLink
in interface ContainerResponseContext
relation
- link relation.true
if the for the relation link exists, false
otherwise.public Link getLink(String relation)
ContainerResponseContext
getLink
in interface ContainerResponseContext
relation
- link relation.null
if not present.public Link.Builder getLinkBuilder(String relation)
ContainerResponseContext
Link.Builder
for the relation.getLinkBuilder
in interface ContainerResponseContext
relation
- link relation.null
if not
present.public boolean hasEntity()
ContainerResponseContext
true
if the entity is present, returns
false
otherwise.hasEntity
in interface ContainerResponseContext
true
if there is an entity present in the message,
false
otherwise.public Object getEntity()
ContainerResponseContext
null
if the message does not contain an entity.getEntity
in interface ContainerResponseContext
null
if message does not contain an
entity body.public OutputStream getEntityStream()
ContainerResponseContext
getEntityStream
in interface ContainerResponseContext
public void setEntityStream(OutputStream entityStream)
ContainerResponseContext
setEntityStream
in interface ContainerResponseContext
entityStream
- new entity output stream.public Annotation[] getEntityAnnotations()
ContainerResponseContext
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.
getEntityAnnotations
in interface ContainerResponseContext
public MultivaluedMap<String,String> getStringHeaders()
ContainerResponseContext
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.
getStringHeaders
in interface ContainerResponseContext
ContainerResponseContext.getHeaders()
,
ContainerResponseContext.getHeaderString(String)
public String getHeaderString(String name)
ContainerResponseContext
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.getHeaderString
in interface ContainerResponseContext
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.ContainerResponseContext.getHeaders()
,
ContainerResponseContext.getStringHeaders()
public void suspend()
SuspendableContainerResponseContext
SuspendableContainerResponseContext.resume()
or aborted with SuspendableContainerResponseContext.resume(Throwable)
or
ResponseContainerRequestContext.abortWith(javax.ws.rs.core.Response)
.suspend
in interface SuspendableContainerResponseContext
public void resume()
SuspendableContainerResponseContext
resume
in interface SuspendableContainerResponseContext
public void resume(Throwable t)
SuspendableContainerResponseContext
resume
in interface SuspendableContainerResponseContext
t
- the exception to send back to the client, as an internal server error.public void filter() throws IOException
IOException
Copyright © 2021 JBoss by Red Hat. All rights reserved.