|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjavax.ws.rs.core.Response
public abstract class Response
Defines the contract between a returned instance and the runtime when an application needs to provide meta-data to the runtime. An application class can extend this class directly or can use one of the static methods to create an instance using a ResponseBuilder.
Several methods have parameters of type URI,UriBuilder provides
convenient methods to create such values as does URI.create(java.lang.String).
Response.ResponseBuilder| Nested Class Summary | |
|---|---|
static class |
Response.ResponseBuilder
A class used to build Response instances that contain metadata instead of or in addition to an entity. |
static class |
Response.Status
Commonly used status codes defined by HTTP, see HTTP/1.1 documentation for the complete list. |
static interface |
Response.StatusType
Base interface for statuses used in responses. |
| Constructor Summary | |
|---|---|
protected |
Response()
Protected constructor, use one of the static methods to obtain a Response.ResponseBuilder instance and obtain a Response from that. |
| Method Summary | ||
|---|---|---|
abstract void |
bufferEntity()
Buffer the message entity. |
|
abstract void |
close()
Close the message entity input stream (if available and open). |
|
static Response.ResponseBuilder |
created(URI location)
Create a new ResponseBuilder for a created resource, set the location header using the supplied value. |
|
static Response.ResponseBuilder |
fromResponse(Response response)
Create a new ResponseBuilder by performing a shallow copy of an existing Response. |
|
abstract Object |
getEntity()
Get the message entity Java instance. |
|
abstract ResponseHeaders |
getHeaders()
Get the response message headers. |
|
abstract MultivaluedMap<String,Object> |
getMetadata()
Get metadata (headers) associated with the response as a map. |
|
abstract Map<String,Object> |
getProperties()
Get a mutable map of request-scoped properties that can be used for communication between different request/response processing components. |
|
abstract int |
getStatus()
Get the status code associated with the response. |
|
abstract Response.Status |
getStatusEnum()
Get the response status represented as a response Response.Status enumeration
value. |
|
abstract boolean |
hasEntity()
Check if there is an entity available in the response. |
|
abstract boolean |
isEntityRetrievable()
Check if the entity instance is present and available
for a retrieval via getEntity(). |
|
static Response.ResponseBuilder |
noContent()
Create a new ResponseBuilder for an empty response. |
|
static Response.ResponseBuilder |
notAcceptable(List<Variant> variants)
Create a new ResponseBuilder for a not acceptable response. |
|
static Response.ResponseBuilder |
notModified()
Create a new ResponseBuilder with a not-modified status. |
|
static Response.ResponseBuilder |
notModified(EntityTag tag)
Create a new ResponseBuilder with a not-modified status. |
|
static Response.ResponseBuilder |
notModified(String tag)
Create a new ResponseBuilder with a not-modified status and a strong entity tag. |
|
static Response.ResponseBuilder |
ok()
Create a new ResponseBuilder with an OK status. |
|
static Response.ResponseBuilder |
ok(Object entity)
Create a new ResponseBuilder that contains a representation. |
|
static Response.ResponseBuilder |
ok(Object entity,
MediaType type)
Create a new ResponseBuilder that contains a representation. |
|
static Response.ResponseBuilder |
ok(Object entity,
String type)
Create a new ResponseBuilder that contains a representation. |
|
static Response.ResponseBuilder |
ok(Object entity,
Variant variant)
Create a new ResponseBuilder that contains a representation. |
|
abstract
|
readEntity(Class<T> type)
Read the message entity as an instance of specified Java type using a MessageBodyReader that supports mapping the
message entity stream onto the requested type. |
|
abstract
|
readEntity(Class<T> type,
Annotation[] annotations)
Read the message entity as an instance of specified Java type using a MessageBodyReader that supports mapping the
message entity stream onto the requested type. |
|
abstract
|
readEntity(TypeLiteral<T> entityType)
Read the message entity as an instance of specified (generic) Java type using a MessageBodyReader that supports mapping the
message entity stream onto the requested type. |
|
abstract
|
readEntity(TypeLiteral<T> entityType,
Annotation[] annotations)
Read the message entity as an instance of specified (generic) Java type using a MessageBodyReader that supports mapping the
message entity stream onto the requested type. |
|
static Response.ResponseBuilder |
seeOther(URI location)
Create a new ResponseBuilder for a redirection. |
|
static Response.ResponseBuilder |
serverError()
Create a new ResponseBuilder with an server error status. |
|
static Response.ResponseBuilder |
status(int status)
Create a new ResponseBuilder with the supplied status. |
|
static Response.ResponseBuilder |
status(Response.Status status)
Create a new ResponseBuilder with the supplied status. |
|
static Response.ResponseBuilder |
status(Response.StatusType status)
Create a new ResponseBuilder with the supplied status. |
|
static Response.ResponseBuilder |
temporaryRedirect(URI location)
Create a new ResponseBuilder for a temporary redirection. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
protected Response()
Response.ResponseBuilder instance and obtain a Response from that.
| Method Detail |
|---|
public abstract Map<String,Object> getProperties()
null. In the scope of a single request/response processing,
a same property map instance is shared by the following methods:
Request.getProperties()getProperties()FilterContext.getProperties()InterceptorContext.getProperties()Configuration.setProperties(java.util.Map) or
Configuration.setProperty(java.lang.String, java.lang.Object)
on the configuration object associated with the corresponding
request invocation.
On the server side, specifying the initial values is implementation-specific.
If there are no initial properties set, the request-scoped property map is
initialized to an empty map.
Configurationpublic abstract int getStatus()
public abstract Response.Status getStatusEnum()
Response.Status enumeration
value.
null if there is no
mapping between the integer status code and the
response status enumeration value.public abstract ResponseHeaders getHeaders()
null.
null.RuntimeDelegate.HeaderDelegate
public abstract Object getEntity()
throws IllegalStateException,
MessageProcessingException
null if the message
does not contain an entity body.
null if message does not contain an
entity body.
IllegalStateException - in case the existing message entity is not
retrievable as a Java type. This is
typically the case (on the client side) when the entity input stream
has not been read as a Java type using one of the readEntity(...)
methods yet.
MessageProcessingException - if the entity was previously fully consumed
as an input stream.hasEntity(),
isEntityRetrievable(),
readEntity(java.lang.Class),
readEntity(javax.ws.rs.core.TypeLiteral),
bufferEntity(),
MessageBodyWriter
public abstract <T> T readEntity(Class<T> type)
throws MessageProcessingException
MessageBodyReader that supports mapping the
message entity stream onto the requested type. Returns null if
the message does not contain an entity body. Unless the supplied entity
type is an input stream, this method automatically
closes the consumed response entity stream (if open) and
makes the entity available for retrieval.
A non-null message instance returned from this method will be cached for
subsequent retrievals via getEntity().
If the message has previously been read as an instance of a different Java type,
invoking this method will cause the cached entity instance to be serialized
into a temporary input stream using a compatible MessageBodyWriter
and then read again from the stream. This operation is thus potentially
expensive and should be used with care.
Note that a message entity can also be read as a raw entity
input stream, in which case it will be fully
consumed once the reading from the entity input stream is finished.
Once the entity is read as an input stream, any subsequent calls to
one of the readEntity(...) methods or getEntity() method
on the same message instance will result in a MessageProcessingException
being thrown. It is up to the consumer of the entity input stream to ensure
that consuming the stream is properly mitigated (e.g. by substituting the
consumed response instance with a new one etc.).
T - entity instance Java type.type - the type of entity.
null if message does not contain an
entity body.
MessageProcessingException - if the content of the message cannot be
mapped to an entity of the requested type or if the entity input stream
was previously directly consumed by invoking readEntity(InputStream.class).hasEntity(),
isEntityRetrievable(),
getEntity(),
readEntity(java.lang.Class, java.lang.annotation.Annotation[]),
readEntity(javax.ws.rs.core.TypeLiteral),
readEntity(javax.ws.rs.core.TypeLiteral, java.lang.annotation.Annotation[]),
bufferEntity(),
close(),
MessageBodyWriter,
MessageBodyReader
public abstract <T> T readEntity(TypeLiteral<T> entityType)
throws MessageProcessingException
MessageBodyReader that supports mapping the
message entity stream onto the requested type. Returns null if
the message does not contain an entity body. Unless the supplied entity
type is an input stream, this method automatically
closes the consumed response entity stream (if open) and
makes the entity available for retrieval.
A non-null message instance returned from this method will be cached for
subsequent retrievals via getEntity().
If the message has previously been read as an instance of a different Java type,
invoking this method will cause the cached entity instance to be serialized
into a temporary input stream using a compatible MessageBodyWriter
and then read again from the stream. This operation is thus potentially
expensive and should be used with care.
Note that a message entity can also be read as a raw entity
input stream, in which case it will be fully
consumed once the reading from the entity input stream is finished.
Once the entity is read as an input stream, any subsequent calls to
one of the readEntity(...) methods or getEntity() method
on the same message instance will result in a MessageProcessingException
being thrown. It is up to the consumer of the entity input stream to ensure
that consuming the stream is properly mitigated (e.g. by substituting the
consumed response instance with a new one etc.).
T - entity instance Java type.entityType - the type of entity; may be generic.
null if message does not contain an
entity body.
MessageProcessingException - if the content of the message cannot be
mapped to an entity of the requested type or if the entity input stream
was previously directly consumed by invoking readEntity(InputStream.class).hasEntity(),
isEntityRetrievable(),
getEntity(),
readEntity(javax.ws.rs.core.TypeLiteral, java.lang.annotation.Annotation[]),
readEntity(java.lang.Class),
readEntity(java.lang.Class, java.lang.annotation.Annotation[]),
bufferEntity(),
close(),
MessageBodyWriter,
MessageBodyReader
public abstract <T> T readEntity(Class<T> type,
Annotation[] annotations)
throws MessageProcessingException
MessageBodyReader that supports mapping the
message entity stream onto the requested type. Returns null if
the message does not contain an entity body. Unless the supplied entity
type is an input stream, this method automatically
closes the consumed response entity stream (if open) and
makes the entity available for retrieval.
A non-null message instance returned from this method will be cached for
subsequent retrievals via getEntity().
If the message has previously been read as an instance of a different Java type,
invoking this method will cause the cached entity instance to be serialized
into a temporary input stream using a compatible MessageBodyWriter
and then read again from the stream. This operation is thus potentially
expensive and should be used with care.
Note that a message entity can also be read as a raw entity
input stream, in which case it will be fully
consumed once the reading from the entity input stream is finished.
Once the entity is read as an input stream, any subsequent calls to
one of the readEntity(...) methods or getEntity() method
on the same message instance will result in a MessageProcessingException
being thrown. It is up to the consumer of the entity input stream to ensure
that consuming the stream is properly mitigated (e.g. by substituting the
consumed response instance with a new one etc.).
T - entity instance Java type.type - the type of entity.annotations - annotations that will be passed to the MessageBodyReader.
null if message does not contain an
entity body.
MessageProcessingException - if the content of the message cannot be
mapped to an entity of the requested type or if the entity input stream
was previously directly consumed by invoking readEntity(InputStream.class).hasEntity(),
isEntityRetrievable(),
getEntity(),
readEntity(java.lang.Class),
readEntity(javax.ws.rs.core.TypeLiteral),
readEntity(javax.ws.rs.core.TypeLiteral, java.lang.annotation.Annotation[]),
bufferEntity(),
close(),
MessageBodyWriter,
MessageBodyReader
public abstract <T> T readEntity(TypeLiteral<T> entityType,
Annotation[] annotations)
throws MessageProcessingException
MessageBodyReader that supports mapping the
message entity stream onto the requested type. Returns null if
the message does not contain an entity body. Unless the supplied entity
type is an input stream, this method automatically
closes the consumed response entity stream (if open) and
makes the entity available for retrieval.
A non-null message instance returned from this method will be cached for
subsequent retrievals via getEntity().
If the message has previously been read as an instance of a different Java type,
invoking this method will cause the cached entity instance to be serialized
into a temporary input stream using a compatible MessageBodyWriter
and then read again from the stream. This operation is thus potentially
expensive and should be used with care.
Note that a message entity can also be read as a raw entity
input stream, in which case it will be fully
consumed once the reading from the entity input stream is finished.
Once the entity is read as an input stream, any subsequent calls to
one of the readEntity(...) methods or getEntity() method
on the same message instance will result in a MessageProcessingException
being thrown. It is up to the consumer of the entity input stream to ensure
that consuming the stream is properly mitigated (e.g. by substituting the
consumed response instance with a new one etc.).
T - entity instance Java type.entityType - the type of entity; may be generic.annotations - annotations that will be passed to the MessageBodyReader.
null if message does not contain an
entity body.
MessageProcessingException - if the content of the message cannot be
mapped to an entity of the requested type or if the entity input stream
was previously directly consumed by invoking readEntity(InputStream.class).hasEntity(),
isEntityRetrievable(),
getEntity(),
readEntity(javax.ws.rs.core.TypeLiteral),
readEntity(java.lang.Class),
readEntity(java.lang.Class, java.lang.annotation.Annotation[]),
bufferEntity(),
close(),
MessageBodyWriter,
MessageBodyReaderpublic abstract boolean hasEntity()
true if the entity is present, returns false otherwise.
In case the message contained an entity, but it was already consumed as
an input stream via readEntity(InputStream.class), the method
returns false.
true if there is an entity present in the message,
false otherwise.isEntityRetrievable(),
getEntity(),
readEntity(java.lang.Class),
readEntity(java.lang.Class, java.lang.annotation.Annotation[]),
readEntity(javax.ws.rs.core.TypeLiteral),
readEntity(javax.ws.rs.core.TypeLiteral, java.lang.annotation.Annotation[])public abstract boolean isEntityRetrievable()
present and available
for a retrieval via getEntity().
The method returns true if the entity is retrievable, returns false
in case there is no entity associated with the message or if the existing
message entity is not available as a Java type. This is typically the case
(on the client side) when the entity input stream has not been consumed
using one of the readEntity(...) methods yet.
Note that even though entity buffering closes
the original entity input stream, the buffered entity may still not be
retrievable, unless the buffered data was previously read using one of the
readEntity(...) methods.
true if there is a retrievable message entity instance
present, false otherwise.hasEntity(),
getEntity(),
readEntity(java.lang.Class),
readEntity(javax.ws.rs.core.TypeLiteral),
bufferEntity()
public abstract void bufferEntity()
throws MessageProcessingException
closed as part of
the operation.
This operation is idempotent, i.e. it can be invoked multiple times with
the same effect which also means that calling the bufferEntity()
method on an already buffered (and thus closed) message instance is legal
and has no further effect.
Note that even though entity buffering closes the original entity input
stream, the buffered entity may still not be retrievable, unless the buffered data was previously read using one of
the readEntity(...) methods.
MessageProcessingException - if there is an error buffering the
message entity.hasEntity(),
isEntityRetrievable(),
getEntity(),
readEntity(java.lang.Class),
readEntity(javax.ws.rs.core.TypeLiteral),
close()
public abstract void close()
throws MessageProcessingException
close() method on an
already closed message instance is legal and has no further effect.
The close() method should be invoked on all instances that
contain an un-consumed entity input stream to ensure the resources associated
with the instance are properly cleaned-up and prevent potential memory leaks.
This is typical for client-side scenarios where application layer code
processes only the response headers and ignores the response entity.
If the close() method is invoked before the message entity has been
fully read from the input stream, any subsequent attempt to read the entity
will result in an MessageProcessingException being thrown.
Closing an instance that has already been consumed has no effect. Similarly,
closing an instance with no entity has not effect.
MessageProcessingException - if there is an error closing the response.readEntity(java.lang.Class),
readEntity(javax.ws.rs.core.TypeLiteral)public abstract MultivaluedMap<String,Object> getMetadata()
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.
This method is effectively a shortcut for
getHeaders().asMap() and may be
deprecated in the future versions of JAX-RS API.
public static Response.ResponseBuilder fromResponse(Response response)
response headers
but the header values are shared with the original Response instance.
If retrievable, the original response entity
instance is set in the new response builder.
response - a Response from which the status code, entity
(if retrievable) and response headers
will be copied.
public static Response.ResponseBuilder status(Response.StatusType status)
status - the response status
IllegalArgumentException - if status is nullpublic static Response.ResponseBuilder status(Response.Status status)
status - the response status
IllegalArgumentException - if status is nullpublic static Response.ResponseBuilder status(int status)
status - the response status
IllegalArgumentException - if status is less than 100 or greater
than 599.public static Response.ResponseBuilder ok()
public static Response.ResponseBuilder ok(Object entity)
GenericEntity if preservation of its generic type is required.
entity - the representation entity data
public static Response.ResponseBuilder ok(Object entity,
MediaType type)
GenericEntity if preservation of its generic type is required.
entity - the representation entity datatype - the media type of the entity
public static Response.ResponseBuilder ok(Object entity,
String type)
GenericEntity if preservation of its generic type is required.
entity - the representation entity datatype - the media type of the entity
public static Response.ResponseBuilder ok(Object entity,
Variant variant)
GenericEntity if preservation of its generic type is required.
entity - the representation entity datavariant - representation metadata
public static Response.ResponseBuilder serverError()
public static Response.ResponseBuilder created(URI location)
location - the URI of the new resource. If a relative URI is
supplied it will be converted into an absolute URI by resolving it
relative to the request URI (see UriInfo.getRequestUri()).
IllegalArgumentException - if location is nullpublic static Response.ResponseBuilder noContent()
public static Response.ResponseBuilder notModified()
public static Response.ResponseBuilder notModified(EntityTag tag)
tag - a tag for the unmodified entity
IllegalArgumentException - if tag is nullpublic static Response.ResponseBuilder notModified(String tag)
notModified(new EntityTag(value)).
tag - the string content of a strong entity tag. The JAX-RS
runtime will quote the supplied value when creating the header.
IllegalArgumentException - if tag is nullpublic static Response.ResponseBuilder seeOther(URI location)
location - the redirection URI. If a relative URI is
supplied it will be converted into an absolute URI by resolving it
relative to the base URI of the application (see
UriInfo.getBaseUri()).
IllegalArgumentException - if location is nullpublic static Response.ResponseBuilder temporaryRedirect(URI location)
location - the redirection URI. If a relative URI is
supplied it will be converted into an absolute URI by resolving it
relative to the base URI of the application (see
UriInfo.getBaseUri()).
IllegalArgumentException - if location is nullpublic static Response.ResponseBuilder notAcceptable(List<Variant> variants)
variants - list of variants that were available, a null value is
equivalent to an empty list.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||