Package javax.ws.rs.core
Class Response
- java.lang.Object
-
- javax.ws.rs.core.Response
-
public abstract class Response extends java.lang.ObjectDefines the contract between a returned instance and the runtime when an application needs to provide metadata 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,UriBuilderprovides convenient methods to create such values as does {@link URI.create()}.- See Also:
Response.ResponseBuilder
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classResponse.ResponseBuilderA class used to build Response instances that contain metadata instead of or in addition to an entity.static classResponse.StatusCommonly used status codes defined by HTTP, see {@link HTTP/1.1 documentation} for the complete list.static interfaceResponse.StatusTypeBase interface for statuses used in responses.
-
Constructor Summary
Constructors Modifier Constructor Description protectedResponse()Protected constructor, use one of the static methods to obtain aResponse.ResponseBuilderinstance and obtain a Response from that.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static Response.ResponseBuildercreated(java.net.URI location)Create a new ResponseBuilder for a created resource, set the location header using the supplied value.static Response.ResponseBuilderfromResponse(Response response)Create a new ResponseBuilder by performing a shallow copy of an existing Response.abstract java.lang.ObjectgetEntity()Return the response entity.abstract MultivaluedMap<java.lang.String,java.lang.Object>getMetadata()Get metadata associated with the response as a map.abstract intgetStatus()Get the status code associated with the response.static Response.ResponseBuildernoContent()Create a new ResponseBuilder for an empty response.static Response.ResponseBuildernotAcceptable(java.util.List<Variant> variants)Create a new ResponseBuilder for a not acceptable response.static Response.ResponseBuildernotModified()Create a new ResponseBuilder with a not-modified status.static Response.ResponseBuildernotModified(java.lang.String tag)Create a new ResponseBuilder with a not-modified status and a strong entity tag.static Response.ResponseBuildernotModified(EntityTag tag)Create a new ResponseBuilder with a not-modified status.static Response.ResponseBuilderok()Create a new ResponseBuilder with an OK status.static Response.ResponseBuilderok(java.lang.Object entity)Create a new ResponseBuilder that contains a representation.static Response.ResponseBuilderok(java.lang.Object entity, java.lang.String type)Create a new ResponseBuilder that contains a representation.static Response.ResponseBuilderok(java.lang.Object entity, MediaType type)Create a new ResponseBuilder that contains a representation.static Response.ResponseBuilderok(java.lang.Object entity, Variant variant)Create a new ResponseBuilder that contains a representation.static Response.ResponseBuilderseeOther(java.net.URI location)Create a new ResponseBuilder for a redirection.static Response.ResponseBuilderserverError()Create a new ResponseBuilder with an server error status.static Response.ResponseBuilderstatus(int status)Create a new ResponseBuilder with the supplied status.static Response.ResponseBuilderstatus(Response.Status status)Create a new ResponseBuilder with the supplied status.static Response.ResponseBuilderstatus(Response.StatusType status)Create a new ResponseBuilder with the supplied status.static Response.ResponseBuildertemporaryRedirect(java.net.URI location)Create a new ResponseBuilder for a temporary redirection.
-
-
-
Constructor Detail
-
Response
protected Response()
Protected constructor, use one of the static methods to obtain aResponse.ResponseBuilderinstance and obtain a Response from that.
-
-
Method Detail
-
getEntity
public abstract java.lang.Object getEntity()
Return the response entity. The response will be serialized using a MessageBodyWriter for either the class of the entity or, in the case ofGenericEntity, the value ofGenericEntity.getRawType().- Returns:
- an object instance or null if there is no entity
- See Also:
MessageBodyWriter
-
getStatus
public abstract int getStatus()
Get the status code associated with the response.- Returns:
- the response status code or -1 if the status was not set.
-
getMetadata
public abstract MultivaluedMap<java.lang.String,java.lang.Object> getMetadata()
Get metadata associated with the response as a map. The returned map may be subsequently modified by the JAX-RS runtime. Values will be serialized using aRuntimeDelegate.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.- Returns:
- response metadata as a map
-
fromResponse
public static Response.ResponseBuilder fromResponse(Response response)
Create a new ResponseBuilder 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.- Parameters:
response- a Response from which the status code, entity and metadata will be copied- Returns:
- a new ReponseBuilder
-
status
public static Response.ResponseBuilder status(Response.StatusType status)
Create a new ResponseBuilder with the supplied status.- Parameters:
status- the response status- Returns:
- a new ResponseBuilder
- Throws:
java.lang.IllegalArgumentException- if status is null
-
status
public static Response.ResponseBuilder status(Response.Status status)
Create a new ResponseBuilder with the supplied status.- Parameters:
status- the response status- Returns:
- a new ResponseBuilder
- Throws:
java.lang.IllegalArgumentException- if status is null
-
status
public static Response.ResponseBuilder status(int status)
Create a new ResponseBuilder with the supplied status.- Parameters:
status- the response status- Returns:
- a new ResponseBuilder
- Throws:
java.lang.IllegalArgumentException- if status is less than 100 or greater than 599.
-
ok
public static Response.ResponseBuilder ok()
Create a new ResponseBuilder with an OK status.- Returns:
- a new ResponseBuilder
-
ok
public static Response.ResponseBuilder ok(java.lang.Object entity)
Create a new ResponseBuilder that contains a representation. It is the callers responsibility to wrap the actual entity withGenericEntityif preservation of its generic type is required.- Parameters:
entity- the representation entity data- Returns:
- a new ResponseBuilder
-
ok
public static Response.ResponseBuilder ok(java.lang.Object entity, MediaType type)
Create a new ResponseBuilder that contains a representation. It is the callers responsibility to wrap the actual entity withGenericEntityif preservation of its generic type is required.- Parameters:
entity- the representation entity datatype- the media type of the entity- Returns:
- a new ResponseBuilder
-
ok
public static Response.ResponseBuilder ok(java.lang.Object entity, java.lang.String type)
Create a new ResponseBuilder that contains a representation. It is the callers responsibility to wrap the actual entity withGenericEntityif preservation of its generic type is required.- Parameters:
entity- the representation entity datatype- the media type of the entity- Returns:
- a new ResponseBuilder
-
ok
public static Response.ResponseBuilder ok(java.lang.Object entity, Variant variant)
Create a new ResponseBuilder that contains a representation. It is the callers responsibility to wrap the actual entity withGenericEntityif preservation of its generic type is required.- Parameters:
entity- the representation entity datavariant- representation metadata- Returns:
- a new ResponseBuilder
-
serverError
public static Response.ResponseBuilder serverError()
Create a new ResponseBuilder with an server error status.- Returns:
- a new ResponseBuilder
-
created
public static Response.ResponseBuilder created(java.net.URI location)
Create a new ResponseBuilder for a created resource, set the location header using the supplied value.- Parameters:
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 (seeUriInfo.getRequestUri()).- Returns:
- a new ResponseBuilder
- Throws:
java.lang.IllegalArgumentException- if location is null
-
noContent
public static Response.ResponseBuilder noContent()
Create a new ResponseBuilder for an empty response.- Returns:
- a new ResponseBuilder
-
notModified
public static Response.ResponseBuilder notModified()
Create a new ResponseBuilder with a not-modified status.- Returns:
- a new ResponseBuilder
-
notModified
public static Response.ResponseBuilder notModified(EntityTag tag)
Create a new ResponseBuilder with a not-modified status.- Parameters:
tag- a tag for the unmodified entity- Returns:
- a new ResponseBuilder
- Throws:
java.lang.IllegalArgumentException- if tag is null
-
notModified
public static Response.ResponseBuilder notModified(java.lang.String tag)
Create a new ResponseBuilder with a not-modified status and a strong entity tag. This is a shortcut fornotModified(new EntityTag(value)).- Parameters:
tag- the string content of a strong entity tag. The JAX-RS runtime will quote the supplied value when creating the header.- Returns:
- a new ResponseBuilder
- Throws:
java.lang.IllegalArgumentException- if tag is null
-
seeOther
public static Response.ResponseBuilder seeOther(java.net.URI location)
Create a new ResponseBuilder for a redirection. Used in the redirect-after-POST (aka POST/redirect/GET) pattern.- Parameters:
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 (seeUriInfo.getBaseUri()).- Returns:
- a new ResponseBuilder
- Throws:
java.lang.IllegalArgumentException- if location is null
-
temporaryRedirect
public static Response.ResponseBuilder temporaryRedirect(java.net.URI location)
Create a new ResponseBuilder for a temporary redirection.- Parameters:
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 (seeUriInfo.getBaseUri()).- Returns:
- a new ResponseBuilder
- Throws:
java.lang.IllegalArgumentException- if location is null
-
notAcceptable
public static Response.ResponseBuilder notAcceptable(java.util.List<Variant> variants)
Create a new ResponseBuilder for a not acceptable response.- Parameters:
variants- list of variants that were available, a null value is equivalent to an empty list.- Returns:
- a new ResponseBuilder
-
-