Class ContainerResponseContextImpl
- All Implemented Interfaces:
ContainerResponseContext,SuspendableContainerResponseContext
- Version:
- $Revision: 1 $
- Author:
- Bill Burke
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final HttpResponseprotected final BuiltResponseprotected final HttpRequest -
Constructor Summary
ConstructorsConstructorDescriptionContainerResponseContextImpl(HttpRequest request, HttpResponse httpResponse, BuiltResponse serverResponse) Deprecated.ContainerResponseContextImpl(HttpRequest request, HttpResponse httpResponse, BuiltResponse serverResponse, ResponseContainerRequestContext requestContext, ContainerResponseFilter[] responseFilters, Consumer<Throwable> onComplete, ServerResponseWriter.RunnableWithIOException continuation) -
Method Summary
Modifier and TypeMethodDescriptionvoidfilter()Get the allowed HTTP methods from the Allow HTTP header.Get any new cookies set on the response message.getDate()Get message date.Get the message entity Java instance.Get the annotations attached to the entity instance.Class<?>Get the raw entity type information.Get the entity output stream.Get the entity tag.Get the generic entity type information.Get the mutable response headers multivalued map.getHeaderString(String name) Get a message header as a single string value.Get the language of the entity.Get the last modified date.intGet Content-Length value.Get the link for the relation.getLinkBuilder(String relation) Convenience method that returns aLink.Builderfor the relation.getLinks()Get the links attached to the message as header.Get the location.Get the media type of the entity.intGet the status code associated with the response.Get the complete status information associated with the response.Get a string view of header values associated with the message.booleanCheck if there is an entity available in the response.booleanCheck if link for relation exists.voidresume()Resumes the current response, and proceeds to the next response filter, if any, or to send the response.voidAborts the current response with the given exception.voidSet a new message entity.voidsetEntity(Object entity, Annotation[] annotations, MediaType mediaType) Set a new message entity, including the attached annotations and the media type.voidsetEntityStream(OutputStream entityStream) 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.voidsuspend()Suspends the current response.
-
Field Details
-
request
-
httpResponse
-
jaxrsResponse
-
-
Constructor Details
-
ContainerResponseContextImpl
@Deprecated public ContainerResponseContextImpl(HttpRequest request, HttpResponse httpResponse, BuiltResponse serverResponse) Deprecated. -
ContainerResponseContextImpl
public ContainerResponseContextImpl(HttpRequest request, HttpResponse httpResponse, BuiltResponse serverResponse, ResponseContainerRequestContext requestContext, ContainerResponseFilter[] responseFilters, Consumer<Throwable> onComplete, ServerResponseWriter.RunnableWithIOException continuation)
-
-
Method Details
-
getJaxrsResponse
-
getHttpResponse
-
getStatus
public int getStatus()Description copied from interface:ContainerResponseContextGet the status code associated with the response.- Specified by:
getStatusin interfaceContainerResponseContext- Returns:
- the response status code or -1 if the status was not set.
-
setStatus
public void setStatus(int code) Description copied from interface:ContainerResponseContextSet a new response status code.- Specified by:
setStatusin interfaceContainerResponseContext- Parameters:
code- new status code.
-
getStatusInfo
Description copied from interface:ContainerResponseContextGet the complete status information associated with the response.- Specified by:
getStatusInfoin interfaceContainerResponseContext- Returns:
- the response status information or
nullif the status was not set.
-
setStatusInfo
Description copied from interface:ContainerResponseContextSet the complete status information (status code and reason phrase) associated with the response.- Specified by:
setStatusInfoin interfaceContainerResponseContext- Parameters:
statusInfo- the response status information.
-
getEntityClass
Description copied from interface:ContainerResponseContextGet the raw entity type information.- Specified by:
getEntityClassin interfaceContainerResponseContext- Returns:
- raw entity type.
-
getEntityType
Description copied from interface:ContainerResponseContextGet the generic entity type information.- Specified by:
getEntityTypein interfaceContainerResponseContext- Returns:
- declared generic entity type.
-
setEntity
Description copied from interface:ContainerResponseContextSet 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.- Specified by:
setEntityin interfaceContainerResponseContext- Parameters:
entity- entity object.- See Also:
-
setEntity
Description copied from interface:ContainerResponseContextSet 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.- Specified by:
setEntityin interfaceContainerResponseContext- Parameters:
entity- entity object.annotations- annotations attached to the entity instance.mediaType- entity media type.- See Also:
-
getHeaders
Description copied from interface:ContainerResponseContextGet the mutable response headers multivalued map.- Specified by:
getHeadersin interfaceContainerResponseContext- Returns:
- mutable multivalued map of response headers.
- See Also:
-
getAllowedMethods
Description copied from interface:ContainerResponseContextGet the allowed HTTP methods from the Allow HTTP header.- Specified by:
getAllowedMethodsin interfaceContainerResponseContext- Returns:
- the allowed HTTP methods, all methods will returned as upper case strings.
-
getDate
Description copied from interface:ContainerResponseContextGet message date.- Specified by:
getDatein interfaceContainerResponseContext- Returns:
- the message date, otherwise
nullif not present.
-
getLanguage
Description copied from interface:ContainerResponseContextGet the language of the entity.- Specified by:
getLanguagein interfaceContainerResponseContext- Returns:
- the language of the entity or
nullif not specified
-
getLength
public int getLength()Description copied from interface:ContainerResponseContextGet Content-Length value.- Specified by:
getLengthin interfaceContainerResponseContext- Returns:
- Content-Length as integer if present and valid number. In other cases returns -1.
-
getMediaType
Description copied from interface:ContainerResponseContextGet the media type of the entity.- Specified by:
getMediaTypein interfaceContainerResponseContext- Returns:
- the media type or
nullif not specified (e.g. there's no response entity).
-
getCookies
Description copied from interface:ContainerResponseContextGet any new cookies set on the response message.- Specified by:
getCookiesin interfaceContainerResponseContext- Returns:
- a read-only map of cookie name (String) to a
new cookie.
-
getEntityTag
Description copied from interface:ContainerResponseContextGet the entity tag.- Specified by:
getEntityTagin interfaceContainerResponseContext- Returns:
- the entity tag, otherwise
nullif not present.
-
getLastModified
Description copied from interface:ContainerResponseContextGet the last modified date.- Specified by:
getLastModifiedin interfaceContainerResponseContext- Returns:
- the last modified date, otherwise
nullif not present.
-
getLocation
Description copied from interface:ContainerResponseContextGet the location.- Specified by:
getLocationin interfaceContainerResponseContext- Returns:
- the location URI, otherwise
nullif not present.
-
getLinks
Description copied from interface:ContainerResponseContextGet the links attached to the message as header.- Specified by:
getLinksin interfaceContainerResponseContext- Returns:
- links, may return empty
Setif no links are present. Never returnsnull.
-
hasLink
Description copied from interface:ContainerResponseContextCheck if link for relation exists.- Specified by:
hasLinkin interfaceContainerResponseContext- Parameters:
relation- link relation.- Returns:
trueif the for the relation link exists,falseotherwise.
-
getLink
Description copied from interface:ContainerResponseContextGet the link for the relation.- Specified by:
getLinkin interfaceContainerResponseContext- Parameters:
relation- link relation.- Returns:
- the link for the relation, otherwise
nullif not present.
-
getLinkBuilder
Description copied from interface:ContainerResponseContextConvenience method that returns aLink.Builderfor the relation.- Specified by:
getLinkBuilderin interfaceContainerResponseContext- Parameters:
relation- link relation.- Returns:
- the link builder for the relation, otherwise
nullif not present.
-
hasEntity
public boolean hasEntity()Description copied from interface:ContainerResponseContextCheck if there is an entity available in the response. The method returnstrueif the entity is present, returnsfalseotherwise.- Specified by:
hasEntityin interfaceContainerResponseContext- Returns:
trueif there is an entity present in the message,falseotherwise.
-
getEntity
Description copied from interface:ContainerResponseContextGet the message entity Java instance. Returnsnullif the message does not contain an entity.- Specified by:
getEntityin interfaceContainerResponseContext- Returns:
- the message entity or
nullif message does not contain an entity body.
-
getEntityStream
Description copied from interface:ContainerResponseContextGet the entity output stream. The JAX-RS runtime is responsible for closing the output stream.- Specified by:
getEntityStreamin interfaceContainerResponseContext- Returns:
- entity output stream.
-
setEntityStream
Description copied from interface:ContainerResponseContextSet a new entity output stream. The JAX-RS runtime is responsible for closing the output stream.- Specified by:
setEntityStreamin interfaceContainerResponseContext- Parameters:
entityStream- new entity output stream.
-
getEntityAnnotations
Description copied from interface:ContainerResponseContextGet 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 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 thegetAnnotatedMe()method (@GET,@Custom) as well as all the annotations from theextrasfield, 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 thegetMe()method (@GET) as well as all the annotations from theextrasfield. It would however not contain any annotations declared on theAnnotatedMeclass.- Specified by:
getEntityAnnotationsin interfaceContainerResponseContext- Returns:
- annotations attached to the entity instance.
-
getStringHeaders
Description copied from interface:ContainerResponseContextGet 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.- Specified by:
getStringHeadersin interfaceContainerResponseContext- Returns:
- response headers as a string view of header values.
- See Also:
-
getHeaderString
Description copied from interface:ContainerResponseContextGet 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.- Specified by:
getHeaderStringin interfaceContainerResponseContext- 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:
-
suspend
public void suspend()Description copied from interface:SuspendableContainerResponseContextSuspends the current response. This makes the current request asynchronous. No further response filter is executed until this response is resumed. No reply is going to be sent to the client until this response is resumed either withSuspendableContainerResponseContext.resume()or aborted withSuspendableContainerResponseContext.resume(Throwable)orResponseContainerRequestContext.abortWith(jakarta.ws.rs.core.Response).- Specified by:
suspendin interfaceSuspendableContainerResponseContext
-
resume
public void resume()Description copied from interface:SuspendableContainerResponseContextResumes the current response, and proceeds to the next response filter, if any, or to send the response.- Specified by:
resumein interfaceSuspendableContainerResponseContext
-
resume
Description copied from interface:SuspendableContainerResponseContextAborts the current response with the given exception. This behaves as if the request filter threw this exception synchronously, which means that the exception will not be mapped by exception mappers, the response filters will stop running, and the async response callbacks will be called with this exception.- Specified by:
resumein interfaceSuspendableContainerResponseContext- Parameters:
t- the exception to send back to the client, as an internal server error.
-
filter
- Throws:
IOException
-