Top Description Methods
javax.ws.rs.container

public Interface ContainerResponseContext

Imports
java.io.OutputStream, java.lang.annotation.Annotation, java.lang.reflect.Type, java.net.URI, java.util.Date, .Locale, .Map, .Set, javax.ws.rs.core.EntityTag, .Link, .MediaType, .MultivaluedMap, .NewCookie, .Response, javax.ws.rs.ext.MessageBodyWriter

Container 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.
Author
Marek Potociar
Since
2.0

Method Summary

Modifier and TypeMethod and Description
public Set<String>

Returns:

the allowed HTTP methods, all methods will returned as upper case strings.
getAllowedMethods
()

Get the allowed HTTP methods from the Allow HTTP header.

public Map<String, NewCookie>

Returns:

a read-only map of cookie name (String) to a new cookie.
getCookies
()

Get any new cookies set on the response message.

public Date

Returns:

the message date, otherwise null if not present.
getDate
()

Get message date.

public Object

Returns:

the message entity or null if message does not contain an entity body.
getEntity
()

Get the message entity Java instance.

public Annotation[]

Returns:

annotations attached to the entity instance.
getEntityAnnotations
()

Get the annotations attached to the entity instance.

public Class<?>

Returns:

raw entity type.
getEntityClass
()

Get the raw entity type information.

public OutputStream

Returns:

entity output stream.
getEntityStream
()

Get the entity output stream.

public EntityTag

Returns:

the entity tag, otherwise null if not present.
getEntityTag
()

Get the entity tag.

public Type

Returns:

declared generic entity type.
getEntityType
()

Get the generic entity type information.

public MultivaluedMap<String, Object>

Returns:

mutable multivalued map of response headers.
getHeaders
()

Get the mutable response headers multivalued map.

public String

Returns:

the message header value. If the message header is not present then 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.
getHeaderString
(String
the message header.
name
)

Get a message header as a single string value.

public Locale

Returns:

the language of the entity or null if not specified
getLanguage
()

Get the language of the entity.

public Date

Returns:

the last modified date, otherwise null if not present.
getLastModified
()

Get the last modified date.

public int

Returns:

Content-Length as integer if present and valid number. In other cases returns -1.
getLength
()

Get Content-Length value.

public Link.Builder

Returns:

the link builder for the relation, otherwise null if not present.
getLinkBuilder
(String
link relation.
relation
)

Convenience method that returns a Link.Builder for the relation.

public URI

Returns:

the location URI, otherwise null if not present.
getLocation
()

Get the location.

public MediaType

Returns:

the media type or null if not specified (e.g. there's no response entity).
getMediaType
()

Get the media type of the entity.

public int

Returns:

the response status code or -1 if the status was not set.
getStatus
()

Get the status code associated with the response.

public Response.StatusType

Returns:

the response status information or null if the status was not set.
getStatusInfo
()

Get the complete status information associated with the response.

public MultivaluedMap<String, String>

Returns:

response headers as a string view of header values.
getStringHeaders
()

Get a string view of header values associated with the message.

public boolean

Returns:

true if there is an entity present in the message, false otherwise.
hasEntity
()

Check if there is an entity available in the response.

public void
setEntity(final Object
entity object.
entity
)

Set a new message entity.

public void
setEntity(final Object
entity object.
entity
,
final Annotation[]
annotations attached to the entity instance.
annotations
,
final MediaType
entity media type.
mediaType
)

Set a new message entity, including the attached annotations and the media type.

public void
setEntityStream(OutputStream
new entity output stream.
outputStream
)

Set a new entity output stream.

public void
setStatus(int
new status code.
code
)

Set a new response status code.

public void
setStatusInfo(Response.StatusType
the response status information.
statusInfo
)

Set the complete status information (status code and reason phrase) associated with the response.

Method Detail

getAllowedMethodsback to summary
public Set<String> getAllowedMethods()

Get the allowed HTTP methods from the Allow HTTP header.

Returns:Set<String>

the allowed HTTP methods, all methods will returned as upper case strings.

getCookiesback to summary
public Map<String, NewCookie> getCookies()

Get any new cookies set on the response message.

Returns:Map<String, NewCookie>

a read-only map of cookie name (String) to a new cookie.

getDateback to summary
public Date getDate()

Get message date.

Returns:Date

the message date, otherwise null if not present.

getEntityback to summary
public Object getEntity()

Get the message entity Java instance. Returns null if the message does not contain an entity.

Returns:Object

the message entity or null if message does not contain an entity body.

getEntityAnnotationsback to summary
public 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 javax.ws.rs.core.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.

Returns:Annotation[]

annotations attached to the entity instance.

getEntityClassback to summary
public Class<?> getEntityClass()

Get the raw entity type information.

Returns:Class<?>

raw entity type.

getEntityStreamback to summary
public OutputStream getEntityStream()

Get the entity output stream. The JAX-RS runtime is responsible for closing the output stream.

Returns:OutputStream

entity output stream.

getEntityTagback to summary
public EntityTag getEntityTag()

Get the entity tag.

Returns:EntityTag

the entity tag, otherwise null if not present.

getEntityTypeback to summary
public Type getEntityType()

Get the generic entity type information.

Returns:Type

declared generic entity type.

getHeadersback to summary
public MultivaluedMap<String, Object> getHeaders()

Get the mutable response headers multivalued map.

Returns:MultivaluedMap<String, Object>

mutable multivalued map of response headers.

See Also
getStringHeaders(), getHeaderString(String)
getHeaderStringback to summary
public String getHeaderString(String name)

Get a message header as a single string value. Each single header value is converted to String using a javax.ws.rs.ext.RuntimeDelegate.HeaderDelegate if one is available via javax.ws.rs.ext.RuntimeDelegate#createHeaderDelegate(java.lang.Class) for the header value class or using its toString method if a header delegate is not available.

Parameters
name:String

the message header.

Returns:String

the message header value. If the message header is not present then 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.

See Also
getHeaders(), getStringHeaders()
getLanguageback to summary
public Locale getLanguage()

Get the language of the entity.

Returns:Locale

the language of the entity or null if not specified

getLastModifiedback to summary
public Date getLastModified()

Get the last modified date.

Returns:Date

the last modified date, otherwise null if not present.

getLengthback to summary
public int getLength()

Get Content-Length value.

Returns:int

Content-Length as integer if present and valid number. In other cases returns -1.

getLinkBuilderback to summary
public Link.Builder getLinkBuilder(String relation)

Convenience method that returns a Link.Builder for the relation.

Parameters
relation:String

link relation.

Returns:Link.Builder

the link builder for the relation, otherwise null if not present.

getLocationback to summary
public URI getLocation()

Get the location.

Returns:URI

the location URI, otherwise null if not present.

getMediaTypeback to summary
public MediaType getMediaType()

Get the media type of the entity.

Returns:MediaType

the media type or null if not specified (e.g. there's no response entity).

getStatusback to summary
public int getStatus()

Get the status code associated with the response.

Returns:int

the response status code or -1 if the status was not set.

getStatusInfoback to summary
public Response.StatusType getStatusInfo()

Get the complete status information associated with the response.

Returns:Response.StatusType

the response status information or null if the status was not set.

getStringHeadersback to summary
public MultivaluedMap<String, String> getStringHeaders()

Get a string view of header values associated with the message. Changes in the underlying headers map are reflected in this view.

The method converts the non-string header values to strings using a javax.ws.rs.ext.RuntimeDelegate.HeaderDelegate if one is available via javax.ws.rs.ext.RuntimeDelegate#createHeaderDelegate(java.lang.Class) for the class of the value or using the values toString method if a header delegate is not available.

Returns:MultivaluedMap<String, String>

response headers as a string view of header values.

See Also
getHeaders(), getHeaderString(String)
hasEntityback to summary
public boolean hasEntity()

Check if there is an entity available in the response. The method returns true if the entity is present, returns false otherwise.

Returns:boolean

true if there is an entity present in the message, false otherwise.

setEntityback to summary
public void setEntity(final Object entity)

Set a new message entity. The existing entity annotations and media type are preserved.

It is the callers responsibility to wrap the actual entity with javax.ws.rs.core.GenericEntity if preservation of its generic type is required.

Parameters
entity:Object

entity object.

See Also
setEntity(Object, java.lang.annotation.Annotation[], javax.ws.rs.core.MediaType), MessageBodyWriter
setEntityback to summary
public void setEntity(final Object entity, final Annotation[] annotations, final 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 javax.ws.rs.core.GenericEntity if preservation of its generic type is required.

Parameters
entity:Object

entity object.

annotations:Annotation[]

annotations attached to the entity instance.

mediaType:MediaType

entity media type.

See Also
setEntity(Object), MessageBodyWriter
setEntityStreamback to summary
public void setEntityStream(OutputStream outputStream)

Set a new entity output stream. The JAX-RS runtime is responsible for closing the output stream.

Parameters
outputStream:OutputStream

new entity output stream.

setStatusback to summary
public void setStatus(int code)

Set a new response status code.

Parameters
code:int

new status code.

setStatusInfoback to summary
public void setStatusInfo(Response.StatusType statusInfo)

Set the complete status information (status code and reason phrase) associated with the response.

Parameters
statusInfo:Response.StatusType

the response status information.