Package javax.ws.rs.core
Class Response.ResponseBuilder
java.lang.Object
javax.ws.rs.core.Response.ResponseBuilder
- Enclosing class:
Response
A class used to build Response instances that contain metadata instead
of or in addition to an entity. An initial instance may be obtained via
static methods of the Response class, instance methods provide the
ability to set metadata. E.g. to create a response that indicates the
creation of a new resource:
@POST Response addWidget(...) { Widget w = ... URI widgetId = UriBuilder.fromResource(Widget.class)... return Response.created(widgetId).build(); }
Several methods have parameters of type URI, UriBuilder
provides
convenient methods to create such values as does URI.create()
.
Where multiple variants of the same method are provided, the type of
the supplied parameter is retained in the metadata of the built
Response
.
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
Protected constructor, use one of the static methods ofResponse
to obtain an instance. -
Method Summary
Modifier and TypeMethodDescriptionabstract Response
build()
Create a Response instance from the current ResponseBuilder.abstract Response.ResponseBuilder
cacheControl
(CacheControl cacheControl) Set the cache control data on the ResponseBuilder.abstract Response.ResponseBuilder
clone()
Create a copy of the ResponseBuilder preserving its state.abstract Response.ResponseBuilder
contentLocation
(URI location) Set the content location on the ResponseBuilder.abstract Response.ResponseBuilder
Add cookies to the ResponseBuilder.abstract Response.ResponseBuilder
Set the entity on the ResponseBuilder.abstract Response.ResponseBuilder
Set the expires date on the ResponseBuilder.abstract Response.ResponseBuilder
Add a header to the ResponseBuilder.abstract Response.ResponseBuilder
Set the language on the ResponseBuilder.abstract Response.ResponseBuilder
Set the language on the ResponseBuilder.abstract Response.ResponseBuilder
lastModified
(Date lastModified) Set the last modified date on the ResponseBuilder.abstract Response.ResponseBuilder
Set the location on the ResponseBuilder.protected static Response.ResponseBuilder
Create a new builder instance.abstract Response.ResponseBuilder
status
(int status) Set the status on the ResponseBuilder.status
(Response.Status status) Set the status on the ResponseBuilder.status
(Response.StatusType status) Set the status on the ResponseBuilder.abstract Response.ResponseBuilder
Set a strong entity tag on the ResponseBuilder.abstract Response.ResponseBuilder
Set an entity tag on the ResponseBuilder.abstract Response.ResponseBuilder
Set the response media type on the ResponseBuilder.abstract Response.ResponseBuilder
Set the response media type on the ResponseBuilder.abstract Response.ResponseBuilder
Set representation metadata on the ResponseBuilder.abstract Response.ResponseBuilder
Add a Vary header that lists the available variants.
-
Constructor Details
-
ResponseBuilder
protected ResponseBuilder()Protected constructor, use one of the static methods ofResponse
to obtain an instance.
-
-
Method Details
-
newInstance
Create a new builder instance.- Returns:
- a new ResponseBuilder
-
build
Create a Response instance from the current ResponseBuilder. The builder is reset to a blank state equivalent to calling the ok method.- Returns:
- a Response instance
-
clone
Create a copy of the ResponseBuilder preserving its state. -
status
Set the status on the ResponseBuilder.- Parameters:
status
- the response status- Returns:
- the updated ResponseBuilder
- Throws:
IllegalArgumentException
- if status is less than 100 or greater than 599.
-
status
Set the status on the ResponseBuilder.- Parameters:
status
- the response status- Returns:
- the updated ResponseBuilder
- Throws:
IllegalArgumentException
- if status is null
-
status
Set the status on the ResponseBuilder.- Parameters:
status
- the response status- Returns:
- the updated ResponseBuilder
- Throws:
IllegalArgumentException
- if status is null
-
entity
Set the entity on the ResponseBuilder. It is the callers responsibility to wrap the actual entity withGenericEntity
if preservation of its generic type is required.- Parameters:
entity
- the response entity- Returns:
- the updated ResponseBuilder
-
type
Set the response media type on the ResponseBuilder.- Parameters:
type
- the media type of the response entity, if null any existing value for type will be removed- Returns:
- the updated ResponseBuilder
-
type
Set the response media type on the ResponseBuilder.- Parameters:
type
- the media type of the response entity, if null any existing value for type will be removed- Returns:
- the updated ResponseBuilder
- Throws:
IllegalArgumentException
- if type cannot be parsed
-
variant
Set representation metadata on the ResponseBuilder. Equivalent to setting the values of content type, content language, and content encoding separately using the values of the variant properties.- Parameters:
variant
- metadata of the response entity, a null value is equivalent to a variant with all null properties.- Returns:
- the updated ResponseBuilder
-
variants
Add a Vary header that lists the available variants.- Parameters:
variants
- a list of available representation variants, a null value will remove an existing value for vary.- Returns:
- the updated ResponseBuilder
-
language
Set the language on the ResponseBuilder.- Parameters:
language
- the language of the response entity, if null any existing value for language will be removed- Returns:
- the updated ResponseBuilder
-
language
Set the language on the ResponseBuilder.- Parameters:
language
- the language of the response entity, if null any existing value for type will be removed- Returns:
- the updated ResponseBuilder
-
location
Set the location on the ResponseBuilder.- Parameters:
location
- the location. 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()
). If null any existing value for location will be removed.- Returns:
- the updated ResponseBuilder
-
contentLocation
Set the content location on the ResponseBuilder.- Parameters:
location
- the content location. Relative or absolute URIs may be used for the value of content location. If null any existing value for content location will be removed.- Returns:
- the updated ResponseBuilder
-
tag
Set an entity tag on the ResponseBuilder.- Parameters:
tag
- the entity tag, if null any existing entity tag value will be removed.- Returns:
- the updated ResponseBuilder
-
tag
Set a strong entity tag on the ResponseBuilder. This is a shortcut fortag(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. If null any existing entity tag value will be removed.- Returns:
- the updated ResponseBuilder
-
lastModified
Set the last modified date on the ResponseBuilder.- Parameters:
lastModified
- the last modified date, if null any existing last modified value will be removed.- Returns:
- the updated ResponseBuilder
-
cacheControl
Set the cache control data on the ResponseBuilder.- Parameters:
cacheControl
- the cache control directives, if null removes any existing cache control directives.- Returns:
- the updated ResponseBuilder
-
expires
Set the expires date on the ResponseBuilder.- Parameters:
expires
- the expiration date, if null removes any existing expires value.- Returns:
- the updated ResponseBuilder
-
header
Add a header to the ResponseBuilder.- Parameters:
name
- the name of the headervalue
- the value of the header, the header will be serialized using aRuntimeDelegate.HeaderDelegate
if one is available viaRuntimeDelegate.createHeaderDelegate(java.lang.Class)
for the class ofvalue
or using itstoString
method if a header delegate is not available. Ifvalue
is null then all current headers of the same name will be removed.- Returns:
- the updated ResponseBuilder
-
cookie
Add cookies to the ResponseBuilder.- Parameters:
cookies
- new cookies that will accompany the response. A null value will remove all cookies, including those added via theheader(java.lang.String, java.lang.Object)
method.- Returns:
- the updated ResponseBuilder
-