|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.sun.jersey.api.JResponse<E>
E
- The entity typepublic class JResponse<E>
Defines the contract between a returned instance and the runtime when an application needs to provide metadata to the runtime.
JResponse is a type safe alternative to Response
that preserves the
type information of response entity thus it is not necessary to utilize
GenericEntity
. It provides equivalent functonality to
Response
.
JResponse may be extended in combination with JResponse.AJResponseBuilder
specialization when building responses.
Several methods have parameters of type URI, UriBuilder
provides
convenient methods to create such values as does
URI.create().
JResponse.JResponseBuilder
,
Response
Nested Class Summary | |
---|---|
static class |
JResponse.AJResponseBuilder<E,B extends JResponse.AJResponseBuilder>
An abstract response builder that may be utilized to extend response building and the construction of JResponse
instances. |
static class |
JResponse.JResponseBuilder<E>
A class used to build JResponse instances that contain metadata
instead of or in addition to an entity. |
Constructor Summary | |
---|---|
|
JResponse(int status,
OutBoundHeaders headers,
E entity)
Construct given a status, entity and metadata. |
protected |
JResponse(JResponse.AJResponseBuilder<E,?> b)
Construct from a JResponse.AJResponseBuilder . |
|
JResponse(JResponse<E> that)
Construct a shallow copy. |
|
JResponse(Response.StatusType statusType,
OutBoundHeaders headers,
E entity)
Construct given a status type, entity and metadata. |
Method Summary | ||
---|---|---|
static
|
created(java.net.URI location)
Create a new JResponse.JResponseBuilder for a created resource, set the
location header using the supplied value. |
|
static
|
fromResponse(JResponse<E> response)
Create a new JResponse.JResponseBuilder by performing a shallow copy of an
existing JResponse . |
|
static
|
fromResponse(Response response)
Create a new JResponse.JResponseBuilder by performing a shallow copy of an
existing Response . |
|
E |
getEntity()
Get the response entity. |
|
OutBoundHeaders |
getMetadata()
Get metadata associated with the response as a map. |
|
int |
getStatus()
Get the status code associated with the response. |
|
Response.StatusType |
getStatusType()
Get the status type associated with the response. |
|
java.lang.reflect.Type |
getType()
Get the type of the entity. |
|
static
|
noContent()
Create a new JResponse.JResponseBuilder for an empty response. |
|
static
|
notAcceptable(java.util.List<Variant> variants)
Create a new JResponse.JResponseBuilder for a not acceptable response. |
|
static
|
notModified()
Create a new JResponse.JResponseBuilder with a not-modified status. |
|
static
|
notModified(EntityTag tag)
Create a new JResponse.JResponseBuilder with a not-modified status. |
|
static
|
notModified(java.lang.String tag)
Create a new JResponse.JResponseBuilder with a not-modified status
and a strong entity tag. |
|
static
|
ok()
Create a new JResponse.JResponseBuilder with an OK status. |
|
static
|
ok(E entity)
Create a new JResponse.JResponseBuilder that contains a representation. |
|
static
|
ok(E entity,
MediaType type)
Create a new JResponse.JResponseBuilder that contains a representation. |
|
static
|
ok(E entity,
java.lang.String type)
Create a new JResponse.JResponseBuilder that contains a representation. |
|
static
|
ok(E entity,
Variant variant)
Create a new JResponse.JResponseBuilder that contains a representation. |
|
static
|
seeOther(java.net.URI location)
Create a new JResponse.JResponseBuilder for a redirection. |
|
static
|
serverError()
Create a new JResponse.JResponseBuilder with an server error status. |
|
static
|
status(int status)
Create a new JResponse.JResponseBuilder with the supplied status. |
|
static
|
status(Response.Status status)
Create a new JResponse.JResponseBuilder with the supplied status. |
|
static
|
status(Response.StatusType status)
Create a new JResponse.JResponseBuilder with the supplied status. |
|
static
|
temporaryRedirect(java.net.URI location)
Create a new JResponse.JResponseBuilder for a temporary redirection. |
|
JResponseAsResponse |
toResponse()
Convert to a Response compatible instance. |
|
JResponseAsResponse |
toResponse(java.lang.reflect.Type type)
Convert to a Response compatible instance. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public JResponse(Response.StatusType statusType, OutBoundHeaders headers, E entity)
statusType
- the status typeheaders
- the metadata, it is the callers responsibility to copy
the metadata if necessary.entity
- the entitypublic JResponse(int status, OutBoundHeaders headers, E entity)
status
- the statusheaders
- the metadata, it is the callers responsibility to copy
the metadata if necessary.entity
- the entitypublic JResponse(JResponse<E> that)
that
- the JResponse to copy from.protected JResponse(JResponse.AJResponseBuilder<E,?> b)
JResponse.AJResponseBuilder
.
b
- the builder.Method Detail |
---|
public JResponseAsResponse toResponse()
Response
compatible instance.
Response
compatible instance.public JResponseAsResponse toResponse(java.lang.reflect.Type type)
Response
compatible instance.
type
- the entity type
Response
compatible instance.public Response.StatusType getStatusType()
public int getStatus()
public OutBoundHeaders 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.
public E getEntity()
E
.
MessageBodyWriter
public java.lang.reflect.Type getType()
public static <E> JResponse.JResponseBuilder<E> fromResponse(Response response)
JResponse.JResponseBuilder
by performing a shallow copy of an
existing Response
. The returned builder has its own metadata map but
entries are simply references to the keys and values contained in the
supplied Response metadata map.
E
- The entity typeresponse
- a Response from which the status code, entity and metadata
will be copied
public static <E> JResponse.JResponseBuilder<E> fromResponse(JResponse<E> response)
JResponse.JResponseBuilder
by performing a shallow copy of an
existing JResponse
. The returned builder has its own metadata map but
entries are simply references to the keys and values contained in the
supplied Response metadata map.
E
- The entity typeresponse
- a JResponse from which the status code, entity and metadata
will be copied
public static <E> JResponse.JResponseBuilder<E> status(Response.StatusType status)
JResponse.JResponseBuilder
with the supplied status.
E
- The entity typestatus
- the response status
java.lang.IllegalArgumentException
- if status is nullpublic static <E> JResponse.JResponseBuilder<E> status(Response.Status status)
JResponse.JResponseBuilder
with the supplied status.
E
- The entity typestatus
- the response status
java.lang.IllegalArgumentException
- if status is nullpublic static <E> JResponse.JResponseBuilder<E> status(int status)
JResponse.JResponseBuilder
with the supplied status.
E
- The entity typestatus
- the response status
java.lang.IllegalArgumentException
- if status is less than 100 or greater
than 599.public static <E> JResponse.JResponseBuilder<E> ok()
JResponse.JResponseBuilder
with an OK status.
E
- The entity type
public static <E> JResponse.JResponseBuilder<E> ok(E entity)
JResponse.JResponseBuilder
that contains a representation.
E
- The entity typeentity
- the representation entity data
public static <E> JResponse.JResponseBuilder<E> ok(E entity, MediaType type)
JResponse.JResponseBuilder
that contains a representation.
E
- The entity typeentity
- the representation entity datatype
- the media type of the entity
public static <E> JResponse.JResponseBuilder<E> ok(E entity, java.lang.String type)
JResponse.JResponseBuilder
that contains a representation.
E
- The entity typeentity
- the representation entity datatype
- the media type of the entity
public static <E> JResponse.JResponseBuilder<E> ok(E entity, Variant variant)
JResponse.JResponseBuilder
that contains a representation.
E
- The entity typeentity
- the representation entity datavariant
- representation metadata
public static <E> JResponse.JResponseBuilder<E> serverError()
JResponse.JResponseBuilder
with an server error status.
E
- The entity type
public static <E> JResponse.JResponseBuilder<E> created(java.net.URI location)
JResponse.JResponseBuilder
for a created resource, set the
location header using the supplied value.
E
- The entity typelocation
- 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
).
java.lang.IllegalArgumentException
- if location is nullpublic static <E> JResponse.JResponseBuilder<E> noContent()
JResponse.JResponseBuilder
for an empty response.
E
- The entity type
public static <E> JResponse.JResponseBuilder<E> notModified()
JResponse.JResponseBuilder
with a not-modified status.
E
- The entity type
public static <E> JResponse.JResponseBuilder<E> notModified(EntityTag tag)
JResponse.JResponseBuilder
with a not-modified status.
E
- The entity typetag
- a tag for the unmodified entity
java.lang.IllegalArgumentException
- if tag is nullpublic static <E> JResponse.JResponseBuilder<E> notModified(java.lang.String tag)
JResponse.JResponseBuilder
with a not-modified status
and a strong entity tag. This is a shortcut
for notModified(new EntityTag(value))
.
E
- The entity typetag
- the string content of a strong entity tag. The JAX-RS
runtime will quote the supplied value when creating the header.
java.lang.IllegalArgumentException
- if tag is nullpublic static <E> JResponse.JResponseBuilder<E> seeOther(java.net.URI location)
JResponse.JResponseBuilder
for a redirection. Used in the
redirect-after-POST (aka POST/redirect/GET) pattern.
E
- The entity typelocation
- 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
).
java.lang.IllegalArgumentException
- if location is nullpublic static <E> JResponse.JResponseBuilder<E> temporaryRedirect(java.net.URI location)
JResponse.JResponseBuilder
for a temporary redirection.
E
- The entity typelocation
- 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
).
java.lang.IllegalArgumentException
- if location is nullpublic static <E> JResponse.JResponseBuilder<E> notAcceptable(java.util.List<Variant> variants)
JResponse.JResponseBuilder
for a not acceptable response.
E
- The entity typevariants
- 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 |