public static class OutboundJaxrsResponse.Builder extends Response.ResponseBuilder
Response.ResponseBuilder
implementation.
The implementation delegates method calls to an underlying
outbound message context
. Upon a call to a build()
method
a new instance of OutboundJaxrsResponse
is produced.Constructor and Description |
---|
Builder(OutboundMessageContext context)
Create new outbound JAX-RS response builder.
|
Modifier and Type | Method and Description |
---|---|
Response.ResponseBuilder |
allow(Set<String> methods)
Set the list of allowed methods for the resource.
|
Response.ResponseBuilder |
allow(String... methods)
Set the list of allowed methods for the resource.
|
Response |
build()
Create a Response instance from the current ResponseBuilder.
|
Response.ResponseBuilder |
cacheControl(CacheControl cacheControl)
Set the cache control data of the message.
|
static void |
clearBaseUri()
Remove the current thread's value for baseUri thread-local variable (set by
setBaseUri(java.net.URI) ). |
Response.ResponseBuilder |
clone() |
Response.ResponseBuilder |
contentLocation(URI location)
Set the content location.
|
Response.ResponseBuilder |
cookie(NewCookie... cookies)
Add cookies to the response message.
|
Response.ResponseBuilder |
encoding(String encoding)
Set the message entity content encoding.
|
Response.ResponseBuilder |
entity(Object entity)
Set the response entity in the builder.
|
Response.ResponseBuilder |
entity(Object entity,
Annotation[] annotations)
Set the response entity in the builder.
|
Response.ResponseBuilder |
expires(Date expires)
Set the response expiration date.
|
Response.ResponseBuilder |
header(String name,
Object value)
Add an arbitrary header.
|
Response.ResponseBuilder |
language(Locale language)
Set the message entity language.
|
Response.ResponseBuilder |
language(String language)
Set the message entity language.
|
Response.ResponseBuilder |
lastModified(Date lastModified)
Set the response entity last modification date.
|
Response.ResponseBuilder |
link(String uri,
String rel)
Add a link header.
|
Response.ResponseBuilder |
link(URI uri,
String rel)
Add a link header.
|
Response.ResponseBuilder |
links(Link... links)
Add one or more link headers.
|
Response.ResponseBuilder |
location(URI location)
Set the location.
|
Response.ResponseBuilder |
replaceAll(MultivaluedMap<String,Object> headers)
Replaces all existing headers with the newly supplied headers.
|
static void |
setBaseUri(URI baseUri)
Set the
baseUri of the actual request into the InheritableThreadLocal . |
Response.ResponseBuilder |
status(int code)
Set the status on the ResponseBuilder.
|
Response.ResponseBuilder |
status(int status,
String reasonPhrase)
Set the status on the ResponseBuilder.
|
Response.ResponseBuilder |
status(Response.StatusType status)
Set the status on the ResponseBuilder.
|
Response.ResponseBuilder |
tag(EntityTag tag)
Set a response entity tag.
|
Response.ResponseBuilder |
tag(String tag)
Set a strong response entity tag.
|
Response.ResponseBuilder |
type(MediaType type)
Set the message entity media type.
|
Response.ResponseBuilder |
type(String type)
Set the message entity media type.
|
Response.ResponseBuilder |
variant(Variant variant)
Set message entity representation metadata.
|
Response.ResponseBuilder |
variants(List<Variant> variants)
Add a Vary header that lists the available variants.
|
Response.ResponseBuilder |
variants(Variant... variants)
Add a Vary header that lists the available variants.
|
newInstance, status
public Builder(OutboundMessageContext context)
context
- underlying outbound message context.public static void setBaseUri(URI baseUri)
baseUri
of the actual request into the InheritableThreadLocal
.
The baseUri
will be used for absolutizing the location header
content in case that only a relative URI is provided.
After resource method invocation when the value is not needed
any more to be stored in ThreadLocal
clearBaseUri()
should be
called for cleanup in order to prevent possible memory leaks.
baseUri
- - baseUri of the actual requestlocation(java.net.URI)
public static void clearBaseUri()
setBaseUri(java.net.URI)
).
Should be called after resource method invocation for cleanup.location(java.net.URI)
public Response build()
Response.ResponseBuilder
build
in class Response.ResponseBuilder
public Response.ResponseBuilder clone()
Response.ResponseBuilder
Create a copy of the ResponseBuilder preserving its state.
clone
in class Response.ResponseBuilder
public Response.ResponseBuilder status(Response.StatusType status)
Response.ResponseBuilder
status
in class Response.ResponseBuilder
status
- the response status.public Response.ResponseBuilder status(int status, String reasonPhrase)
Response.ResponseBuilder
status
in class Response.ResponseBuilder
status
- the response status.reasonPhrase
- the reason phrase.public Response.ResponseBuilder status(int code)
Response.ResponseBuilder
status
in class Response.ResponseBuilder
code
- the response status.public Response.ResponseBuilder entity(Object entity)
Response.ResponseBuilder
Set the response entity in the builder.
Any Java type instance for a response entity, that is supported by the runtime can be passed. It is the callers
responsibility to wrap the actual entity with GenericEntity
if preservation of its generic type is required.
Note that the entity can be also set as an input stream
.
type(...)
methods.entity
in class Response.ResponseBuilder
entity
- the request entity.Response.ResponseBuilder.entity(java.lang.Object, java.lang.annotation.Annotation[])
,
Response.ResponseBuilder.type(jakarta.ws.rs.core.MediaType)
,
Response.ResponseBuilder.type(java.lang.String)
public Response.ResponseBuilder entity(Object entity, Annotation[] annotations)
Response.ResponseBuilder
Set the response entity in the builder.
Any Java type instance for a response entity, that is supported by the runtime can be passed. It is the callers
responsibility to wrap the actual entity with GenericEntity
if preservation of its generic type is required.
Note that the entity can be also set as an input stream
.
type(...)
methods.entity
in class Response.ResponseBuilder
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).Response.ResponseBuilder.entity(java.lang.Object)
,
Response.ResponseBuilder.type(jakarta.ws.rs.core.MediaType)
,
Response.ResponseBuilder.type(java.lang.String)
public Response.ResponseBuilder type(MediaType type)
Response.ResponseBuilder
type
in class Response.ResponseBuilder
type
- the media type of the message entity. If null
, any existing value for type will be removed.public Response.ResponseBuilder type(String type)
Response.ResponseBuilder
type
in class Response.ResponseBuilder
type
- the media type of the message entity. If null
, any existing value for type will be removed.public Response.ResponseBuilder variant(Variant variant)
Response.ResponseBuilder
Set message entity representation metadata.
Equivalent to setting the values of content type, content language, and content encoding separately using the values of the variant properties.variant
in class Response.ResponseBuilder
variant
- metadata of the message entity, a null
value is equivalent to a variant with all null
properties.Response.ResponseBuilder.encoding(java.lang.String)
,
Response.ResponseBuilder.language(java.util.Locale)
,
Response.ResponseBuilder.type(jakarta.ws.rs.core.MediaType)
public Response.ResponseBuilder variants(List<Variant> variants)
Response.ResponseBuilder
variants
in class Response.ResponseBuilder
variants
- a list of available representation variants, a null
value will remove an existing value for
Vary header.public Response.ResponseBuilder language(String language)
Response.ResponseBuilder
language
in class Response.ResponseBuilder
language
- the language of the message entity, if null
any existing value for language will be removed.public Response.ResponseBuilder language(Locale language)
Response.ResponseBuilder
language
in class Response.ResponseBuilder
language
- the language of the message entity, if null
any existing value for type will be removed.public Response.ResponseBuilder location(URI location)
Response.ResponseBuilder
location
in class Response.ResponseBuilder
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 Response.ResponseBuilder contentLocation(URI location)
Response.ResponseBuilder
contentLocation
in class Response.ResponseBuilder
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 Response.ResponseBuilder encoding(String encoding)
Response.ResponseBuilder
encoding
in class Response.ResponseBuilder
encoding
- the content encoding of the message entity, if null
any existing value for content encoding
will be removed.public Response.ResponseBuilder tag(EntityTag tag)
Response.ResponseBuilder
tag
in class Response.ResponseBuilder
tag
- the entity tag, if null
any existing entity tag value will be removed.public Response.ResponseBuilder tag(String tag)
Response.ResponseBuilder
Set a strong response entity tag.
This is a shortcut fortag(new EntityTag(value))
.tag
in class Response.ResponseBuilder
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.public Response.ResponseBuilder lastModified(Date lastModified)
Response.ResponseBuilder
lastModified
in class Response.ResponseBuilder
lastModified
- the last modified date, if null
any existing last modified value will be removed.public Response.ResponseBuilder cacheControl(CacheControl cacheControl)
Response.ResponseBuilder
cacheControl
in class Response.ResponseBuilder
cacheControl
- the cache control directives, if null
any existing cache control directives will be
removed.public Response.ResponseBuilder expires(Date expires)
Response.ResponseBuilder
expires
in class Response.ResponseBuilder
expires
- the expiration date, if null
removes any existing expires value.public Response.ResponseBuilder cookie(NewCookie... cookies)
Response.ResponseBuilder
cookie
in class Response.ResponseBuilder
cookies
- new cookies that will accompany the response. A null
value will remove all cookies, including
those added via the Response.ResponseBuilder.header(java.lang.String, java.lang.Object)
method.public Response.ResponseBuilder header(String name, Object value)
Response.ResponseBuilder
header
in class Response.ResponseBuilder
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 Response.ResponseBuilder variants(Variant... variants)
Response.ResponseBuilder
variants
in class Response.ResponseBuilder
variants
- a list of available representation variants, a null
value will remove an existing value for
Vary header.public Response.ResponseBuilder links(Link... links)
Response.ResponseBuilder
links
in class Response.ResponseBuilder
links
- links to be added to the message as headers, a null
value will remove any existing Link headers.public Response.ResponseBuilder link(URI uri, String rel)
Response.ResponseBuilder
link
in class Response.ResponseBuilder
uri
- underlying URI for link header.rel
- value of "rel" parameter.public Response.ResponseBuilder link(String uri, String rel)
Response.ResponseBuilder
link
in class Response.ResponseBuilder
uri
- underlying URI for link header.rel
- value of "rel" parameter.public Response.ResponseBuilder allow(String... methods)
Response.ResponseBuilder
allow
in class Response.ResponseBuilder
methods
- the methods to be listed as allowed for the resource, if null
any existing allowed method list
will be removed.public Response.ResponseBuilder allow(Set<String> methods)
Response.ResponseBuilder
allow
in class Response.ResponseBuilder
methods
- the methods to be listed as allowed for the resource, if null
any existing allowed method list
will be removed.public Response.ResponseBuilder replaceAll(MultivaluedMap<String,Object> headers)
Response.ResponseBuilder
replaceAll
in class Response.ResponseBuilder
headers
- new headers to be set, if null
all existing headers will be removed.Copyright © 2007-2024, Oracle and/or its affiliates. All Rights Reserved. Use is subject to license terms.