E
- The entity typepublic class JResponse<E>
extends java.lang.Object
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 functionality 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
Modifier and Type | Class and Description |
---|---|
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. |
Modifier | Constructor and Description |
---|---|
|
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.
|
Modifier and Type | Method and Description |
---|---|
static <E> JResponse.JResponseBuilder<E> |
created(java.net.URI location)
Create a new
JResponse.JResponseBuilder for a created resource, set the
location header using the supplied value. |
static <E> JResponse.JResponseBuilder<E> |
fromResponse(JResponse<E> response)
Create a new
JResponse.JResponseBuilder by performing a shallow copy of an
existing JResponse . |
static <E> JResponse.JResponseBuilder<E> |
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 <E> JResponse.JResponseBuilder<E> |
noContent()
Create a new
JResponse.JResponseBuilder for an empty response. |
static <E> JResponse.JResponseBuilder<E> |
notAcceptable(java.util.List<Variant> variants)
Create a new
JResponse.JResponseBuilder for a not acceptable response. |
static <E> JResponse.JResponseBuilder<E> |
notModified()
Create a new
JResponse.JResponseBuilder with a not-modified status. |
static <E> JResponse.JResponseBuilder<E> |
notModified(EntityTag tag)
Create a new
JResponse.JResponseBuilder with a not-modified status. |
static <E> JResponse.JResponseBuilder<E> |
notModified(java.lang.String tag)
Create a new
JResponse.JResponseBuilder with a not-modified status
and a strong entity tag. |
static <E> JResponse.JResponseBuilder<E> |
ok()
Create a new
JResponse.JResponseBuilder with an OK status. |
static <E> JResponse.JResponseBuilder<E> |
ok(E entity)
Create a new
JResponse.JResponseBuilder that contains a representation. |
static <E> JResponse.JResponseBuilder<E> |
ok(E entity,
MediaType type)
Create a new
JResponse.JResponseBuilder that contains a representation. |
static <E> JResponse.JResponseBuilder<E> |
ok(E entity,
java.lang.String type)
Create a new
JResponse.JResponseBuilder that contains a representation. |
static <E> JResponse.JResponseBuilder<E> |
ok(E entity,
Variant variant)
Create a new
JResponse.JResponseBuilder that contains a representation. |
static <E> JResponse.JResponseBuilder<E> |
seeOther(java.net.URI location)
Create a new
JResponse.JResponseBuilder for a redirection. |
static <E> JResponse.JResponseBuilder<E> |
serverError()
Create a new
JResponse.JResponseBuilder with an server error status. |
static <E> JResponse.JResponseBuilder<E> |
status(int status)
Create a new
JResponse.JResponseBuilder with the supplied status. |
static <E> JResponse.JResponseBuilder<E> |
status(Response.Status status)
Create a new
JResponse.JResponseBuilder with the supplied status. |
static <E> JResponse.JResponseBuilder<E> |
status(Response.StatusType status)
Create a new
JResponse.JResponseBuilder with the supplied status. |
static <E> JResponse.JResponseBuilder<E> |
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. |
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.public JResponseAsResponse toResponse()
Response
compatible instance.Response
compatible instance.public JResponseAsResponse toResponse(java.lang.reflect.Type type)
Response
compatible instance.type
- the entity typeResponse
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 copiedpublic 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 copiedpublic static <E> JResponse.JResponseBuilder<E> status(Response.StatusType status)
JResponse.JResponseBuilder
with the supplied status.E
- The entity typestatus
- the response statusjava.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 statusjava.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 statusjava.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 typepublic static <E> JResponse.JResponseBuilder<E> ok(E entity)
JResponse.JResponseBuilder
that contains a representation.E
- The entity typeentity
- the representation entity datapublic 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 entitypublic 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 entitypublic 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 metadatapublic static <E> JResponse.JResponseBuilder<E> serverError()
JResponse.JResponseBuilder
with an server error status.E
- The entity typepublic 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 typepublic static <E> JResponse.JResponseBuilder<E> notModified()
JResponse.JResponseBuilder
with a not-modified status.E
- The entity typepublic static <E> JResponse.JResponseBuilder<E> notModified(EntityTag tag)
JResponse.JResponseBuilder
with a not-modified status.E
- The entity typetag
- a tag for the unmodified entityjava.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.Copyright © 2016 Oracle Corporation. All Rights Reserved.