public abstract static class Response.ResponseBuilder extends Object
@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
.
Modifier | Constructor and Description |
---|---|
protected |
ResponseBuilder()
Protected constructor, use one of the static methods of
Response to obtain an instance. |
Modifier and Type | Method and Description |
---|---|
abstract Response.ResponseBuilder |
allow(Set<String> methods)
Set the list of allowed methods for the resource.
|
abstract Response.ResponseBuilder |
allow(String... methods)
Set the list of allowed methods for the resource.
|
abstract Response |
build()
Create a Response instance from the current ResponseBuilder.
|
abstract Response.ResponseBuilder |
cacheControl(CacheControl cacheControl)
Set the cache control data of the message.
|
abstract Response.ResponseBuilder |
clone() |
abstract Response.ResponseBuilder |
contentLocation(URI location)
Set the content location.
|
abstract Response.ResponseBuilder |
cookie(NewCookie... cookies)
Add cookies to the response message.
|
abstract Response.ResponseBuilder |
encoding(String encoding)
Set the message entity content encoding.
|
abstract Response.ResponseBuilder |
entity(Object entity)
Set the response entity in the builder.
|
abstract Response.ResponseBuilder |
entity(Object entity,
Annotation[] annotations)
Set the response entity in the builder.
|
abstract Response.ResponseBuilder |
expires(Date expires)
Set the response expiration date.
|
abstract Response.ResponseBuilder |
header(String name,
Object value)
Add an arbitrary header.
|
abstract Response.ResponseBuilder |
language(Locale language)
Set the message entity language.
|
abstract Response.ResponseBuilder |
language(String language)
Set the message entity language.
|
abstract Response.ResponseBuilder |
lastModified(Date lastModified)
Set the response entity last modification date.
|
abstract Response.ResponseBuilder |
link(String uri,
String rel)
Add a link header.
|
abstract Response.ResponseBuilder |
link(URI uri,
String rel)
Add a link header.
|
abstract Response.ResponseBuilder |
links(Link... links)
Add one or more link headers.
|
abstract Response.ResponseBuilder |
location(URI location)
Set the location.
|
protected static Response.ResponseBuilder |
newInstance()
Create a new builder instance.
|
abstract Response.ResponseBuilder |
replaceAll(MultivaluedMap<String,Object> headers)
Replaces all existing headers with the newly supplied headers.
|
abstract Response.ResponseBuilder |
status(int status)
Set the status on the ResponseBuilder.
|
abstract Response.ResponseBuilder |
status(int status,
String reasonPhrase)
Set the status on the ResponseBuilder.
|
Response.ResponseBuilder |
status(Response.Status status)
Set the status on the ResponseBuilder.
|
Response.ResponseBuilder |
status(Response.StatusType status)
Set the status on the ResponseBuilder.
|
abstract Response.ResponseBuilder |
tag(EntityTag tag)
Set a response entity tag.
|
abstract Response.ResponseBuilder |
tag(String tag)
Set a strong response entity tag.
|
abstract Response.ResponseBuilder |
type(MediaType type)
Set the message entity media type.
|
abstract Response.ResponseBuilder |
type(String type)
Set the message entity media type.
|
abstract Response.ResponseBuilder |
variant(Variant variant)
Set message entity representation metadata.
|
abstract Response.ResponseBuilder |
variants(List<Variant> variants)
Add a Vary header that lists the available variants.
|
abstract Response.ResponseBuilder |
variants(Variant... variants)
Add a Vary header that lists the available variants.
|
protected ResponseBuilder()
Response
to obtain an instance.protected static Response.ResponseBuilder newInstance()
public abstract Response build()
public abstract Response.ResponseBuilder clone()
Create a copy of the ResponseBuilder preserving its state.
public abstract Response.ResponseBuilder status(int status)
status
- the response status.IllegalArgumentException
- if status is less than 100
or greater
than 599
.public abstract Response.ResponseBuilder status(int status, String reasonPhrase)
status
- the response status.reasonPhrase
- the reason phrase.IllegalArgumentException
- if status is less than 100
or greater
than 599
.public Response.ResponseBuilder status(Response.StatusType status)
status
- the response status.IllegalArgumentException
- if status is null
.public Response.ResponseBuilder status(Response.Status status)
status
- the response status.IllegalArgumentException
- if status is null
.public abstract Response.ResponseBuilder entity(Object entity)
GenericEntity
if preservation of its generic
type is required. Note that the entity can be also set as an
input stream
.
A specific entity media type can be set using one of the type(...)
methods.entity
- the request entity.entity(java.lang.Object, java.lang.annotation.Annotation[])
,
type(javax.ws.rs.core.MediaType)
,
type(java.lang.String)
public abstract Response.ResponseBuilder entity(Object entity, Annotation[] annotations)
GenericEntity
if preservation of its generic
type is required. Note that the entity can be also set as an
input stream
.
A specific entity media type can be set using one of the type(...)
methods.entity
- the request entity.annotations
- annotations that will be passed to the MessageBodyWriter
,
(in addition to any annotations declared directly on a resource
method that returns the built response).entity(java.lang.Object)
,
type(javax.ws.rs.core.MediaType)
,
type(java.lang.String)
public abstract Response.ResponseBuilder allow(String... methods)
methods
- the methods to be listed as allowed for the resource,
if null
any existing allowed method list will be removed.public abstract Response.ResponseBuilder allow(Set<String> methods)
methods
- the methods to be listed as allowed for the resource,
if null
any existing allowed method list will be removed.public abstract Response.ResponseBuilder cacheControl(CacheControl cacheControl)
cacheControl
- the cache control directives, if null
any existing cache control directives will be removed.public abstract Response.ResponseBuilder encoding(String encoding)
encoding
- the content encoding of the message entity,
if null
any existing value for content encoding will be
removed.public abstract Response.ResponseBuilder header(String name, Object value)
name
- the name of the headervalue
- the value of the header, the header will be serialized
using a RuntimeDelegate.HeaderDelegate
if
one is available via RuntimeDelegate.createHeaderDelegate(java.lang.Class)
for the class of value
or using its toString
method
if a header delegate is not available. If value
is null
then all current headers of the same name will be removed.public abstract Response.ResponseBuilder replaceAll(MultivaluedMap<String,Object> headers)
headers
- new headers to be set, if null
all existing
headers will be removed.public abstract Response.ResponseBuilder language(String language)
language
- the language of the message entity, if null
any
existing value for language will be removed.public abstract Response.ResponseBuilder language(Locale language)
language
- the language of the message entity, if null
any
existing value for type will be removed.public abstract Response.ResponseBuilder type(MediaType type)
type
- the media type of the message entity. If null
, any
existing value for type will be removed.public abstract Response.ResponseBuilder type(String type)
type
- the media type of the message entity. If null
, any
existing value for type will be removed.public abstract Response.ResponseBuilder variant(Variant variant)
variant
- metadata of the message entity, a null
value is
equivalent to a variant with all null
properties.encoding(java.lang.String)
,
language(java.util.Locale)
,
type(javax.ws.rs.core.MediaType)
public abstract Response.ResponseBuilder contentLocation(URI location)
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.public abstract Response.ResponseBuilder cookie(NewCookie... cookies)
cookies
- new cookies that will accompany the response. A null
value will remove all cookies, including those added via the
header(java.lang.String, java.lang.Object)
method.public abstract Response.ResponseBuilder expires(Date expires)
expires
- the expiration date, if null
removes any existing
expires value.public abstract Response.ResponseBuilder lastModified(Date lastModified)
lastModified
- the last modified date, if null
any existing
last modified value will be removed.public abstract Response.ResponseBuilder location(URI location)
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 (see UriInfo.getBaseUri()
).
If null
any existing value for location will be removed.public abstract Response.ResponseBuilder tag(EntityTag tag)
tag
- the entity tag, if null
any existing entity tag
value will be removed.public abstract Response.ResponseBuilder tag(String tag)
tag(new EntityTag(value))
.tag
- the string content of a strong entity tag. The
runtime will quote the supplied value when creating the header.
If null
any existing entity tag value will be removed.public abstract Response.ResponseBuilder variants(Variant... variants)
variants
- a list of available representation variants, a null
value will remove an existing value for Vary header.public abstract Response.ResponseBuilder variants(List<Variant> variants)
variants
- a list of available representation variants, a null
value will remove an existing value for Vary header.public abstract Response.ResponseBuilder links(Link... links)
links
- links to be added to the message as headers, a null
value will remove any existing Link headers.public abstract Response.ResponseBuilder link(URI uri, String rel)
uri
- underlying URI for link header.rel
- value of "rel" parameter.public abstract Response.ResponseBuilder link(String uri, String rel)
uri
- underlying URI for link header.rel
- value of "rel" parameter.Copyright © 2020 JBoss by Red Hat. All rights reserved.