Class OutboundJaxrsResponse.Builder
- java.lang.Object
-
- jakarta.ws.rs.core.Response.ResponseBuilder
-
- org.glassfish.jersey.message.internal.OutboundJaxrsResponse.Builder
-
- Enclosing class:
- OutboundJaxrsResponse
public static class OutboundJaxrsResponse.Builder extends Response.ResponseBuilder
Outbound JAX-RSResponse.ResponseBuilderimplementation. The implementation delegates method calls to anunderlying outbound message context. Upon a call to abuild()method a new instance ofOutboundJaxrsResponseis produced.
-
-
Constructor Summary
Constructors Constructor Description Builder(OutboundMessageContext context)Create new outbound JAX-RS response builder.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Response.ResponseBuilderallow(String... methods)Set the list of allowed methods for the resource.Response.ResponseBuilderallow(Set<String> methods)Set the list of allowed methods for the resource.Responsebuild()Create a Response instance from the current ResponseBuilder.Response.ResponseBuildercacheControl(CacheControl cacheControl)Set the cache control data of the message.static voidclearBaseUri()Remove the current thread's value for baseUri thread-local variable (set bysetBaseUri(java.net.URI)).Response.ResponseBuilderclone()Response.ResponseBuildercontentLocation(URI location)Set the content location.Response.ResponseBuildercookie(NewCookie... cookies)Add cookies to the response message.Response.ResponseBuilderencoding(String encoding)Set the message entity content encoding.Response.ResponseBuilderentity(Object entity)Set the response entity in the builder.Response.ResponseBuilderentity(Object entity, Annotation[] annotations)Set the response entity in the builder.Response.ResponseBuilderexpires(Date expires)Set the response expiration date.Response.ResponseBuilderheader(String name, Object value)Add an arbitrary header.Response.ResponseBuilderlanguage(String language)Set the message entity language.Response.ResponseBuilderlanguage(Locale language)Set the message entity language.Response.ResponseBuilderlastModified(Date lastModified)Set the response entity last modification date.Response.ResponseBuilderlink(String uri, String rel)Add a link header.Response.ResponseBuilderlink(URI uri, String rel)Add a link header.Response.ResponseBuilderlinks(Link... links)Add one or more link headers.Response.ResponseBuilderlocation(URI location)Set the location.Response.ResponseBuilderreplaceAll(MultivaluedMap<String,Object> headers)Replaces all existing headers with the newly supplied headers.static voidsetBaseUri(URI baseUri)Set thebaseUriof the actual request into theInheritableThreadLocal.Response.ResponseBuilderstatus(int code)Set the status on the ResponseBuilder.Response.ResponseBuilderstatus(int status, String reasonPhrase)Set the status on the ResponseBuilder.Response.ResponseBuilderstatus(Response.StatusType status)Set the status on the ResponseBuilder.Response.ResponseBuildertag(EntityTag tag)Set a response entity tag.Response.ResponseBuildertag(String tag)Set a strong response entity tag.Response.ResponseBuildertype(MediaType type)Set the message entity media type.Response.ResponseBuildertype(String type)Set the message entity media type.Response.ResponseBuildervariant(Variant variant)Set message entity representation metadata.Response.ResponseBuildervariants(Variant... variants)Add a Vary header that lists the available variants.Response.ResponseBuildervariants(List<Variant> variants)Add a Vary header that lists the available variants.-
Methods inherited from class jakarta.ws.rs.core.Response.ResponseBuilder
newInstance, status
-
-
-
-
Constructor Detail
-
Builder
public Builder(OutboundMessageContext context)
Create new outbound JAX-RS response builder.- Parameters:
context- underlying outbound message context.
-
-
Method Detail
-
setBaseUri
public static void setBaseUri(URI baseUri)
Set thebaseUriof the actual request into theInheritableThreadLocal.The
baseUriwill 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
ThreadLocalclearBaseUri()should be called for cleanup in order to prevent possible memory leaks.- Parameters:
baseUri- - baseUri of the actual request- Since:
- 2.4
- See Also:
location(java.net.URI)
-
clearBaseUri
public static void clearBaseUri()
Remove the current thread's value for baseUri thread-local variable (set bysetBaseUri(java.net.URI)). Should be called after resource method invocation for cleanup.- Since:
- 2.4
- See Also:
location(java.net.URI)
-
build
public Response build()
Description copied from class:Response.ResponseBuilderCreate a Response instance from the current ResponseBuilder. The builder is reset to a blank state equivalent to calling the ok method.- Specified by:
buildin classResponse.ResponseBuilder- Returns:
- a Response instance.
-
clone
public Response.ResponseBuilder clone()
Description copied from class:Response.ResponseBuilderCreate a copy of the ResponseBuilder preserving its state.
- Specified by:
clonein classResponse.ResponseBuilder- Returns:
- a copy of the ResponseBuilder.
-
status
public Response.ResponseBuilder status(Response.StatusType status)
Description copied from class:Response.ResponseBuilderSet the status on the ResponseBuilder.- Overrides:
statusin classResponse.ResponseBuilder- Parameters:
status- the response status.- Returns:
- the updated response builder.
-
status
public Response.ResponseBuilder status(int status, String reasonPhrase)
Description copied from class:Response.ResponseBuilderSet the status on the ResponseBuilder.- Specified by:
statusin classResponse.ResponseBuilder- Parameters:
status- the response status.reasonPhrase- the reason phrase.- Returns:
- the updated response builder.
-
status
public Response.ResponseBuilder status(int code)
Description copied from class:Response.ResponseBuilderSet the status on the ResponseBuilder.- Specified by:
statusin classResponse.ResponseBuilder- Parameters:
code- the response status.- Returns:
- the updated response builder.
-
entity
public Response.ResponseBuilder entity(Object entity)
Description copied from class:Response.ResponseBuilderSet 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
A specific entity media type can be set using one of theGenericEntityif preservation of its generic type is required. Note that the entity can be also set as aninput stream.type(...)methods.- Specified by:
entityin classResponse.ResponseBuilder- Parameters:
entity- the request entity.- Returns:
- updated response builder instance.
- See Also:
Response.ResponseBuilder.entity(java.lang.Object, java.lang.annotation.Annotation[]),Response.ResponseBuilder.type(jakarta.ws.rs.core.MediaType),Response.ResponseBuilder.type(java.lang.String)
-
entity
public Response.ResponseBuilder entity(Object entity, Annotation[] annotations)
Description copied from class:Response.ResponseBuilderSet 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
A specific entity media type can be set using one of theGenericEntityif preservation of its generic type is required. Note that the entity can be also set as aninput stream.type(...)methods.- Specified by:
entityin classResponse.ResponseBuilder- Parameters:
entity- the request entity.annotations- annotations that will be passed to theMessageBodyWriter, (in addition to any annotations declared directly on a resource method that returns the built response).- Returns:
- updated response builder instance.
- See Also:
Response.ResponseBuilder.entity(java.lang.Object),Response.ResponseBuilder.type(jakarta.ws.rs.core.MediaType),Response.ResponseBuilder.type(java.lang.String)
-
type
public Response.ResponseBuilder type(MediaType type)
Description copied from class:Response.ResponseBuilderSet the message entity media type.- Specified by:
typein classResponse.ResponseBuilder- Parameters:
type- the media type of the message entity. Ifnull, any existing value for type will be removed.- Returns:
- the updated response builder.
-
type
public Response.ResponseBuilder type(String type)
Description copied from class:Response.ResponseBuilderSet the message entity media type.- Specified by:
typein classResponse.ResponseBuilder- Parameters:
type- the media type of the message entity. Ifnull, any existing value for type will be removed.- Returns:
- the updated response builder.
-
variant
public Response.ResponseBuilder variant(Variant variant)
Description copied from class:Response.ResponseBuilderSet 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.- Specified by:
variantin classResponse.ResponseBuilder- Parameters:
variant- metadata of the message entity, anullvalue is equivalent to a variant with allnullproperties.- Returns:
- the updated response builder.
- See Also:
Response.ResponseBuilder.encoding(java.lang.String),Response.ResponseBuilder.language(java.util.Locale),Response.ResponseBuilder.type(jakarta.ws.rs.core.MediaType)
-
variants
public Response.ResponseBuilder variants(List<Variant> variants)
Description copied from class:Response.ResponseBuilderAdd a Vary header that lists the available variants.- Specified by:
variantsin classResponse.ResponseBuilder- Parameters:
variants- a list of available representation variants, anullvalue will remove an existing value for Vary header.- Returns:
- the updated response builder.
-
language
public Response.ResponseBuilder language(String language)
Description copied from class:Response.ResponseBuilderSet the message entity language.- Specified by:
languagein classResponse.ResponseBuilder- Parameters:
language- the language of the message entity, ifnullany existing value for language will be removed.- Returns:
- the updated response builder.
-
language
public Response.ResponseBuilder language(Locale language)
Description copied from class:Response.ResponseBuilderSet the message entity language.- Specified by:
languagein classResponse.ResponseBuilder- Parameters:
language- the language of the message entity, ifnullany existing value for type will be removed.- Returns:
- the updated response builder.
-
location
public Response.ResponseBuilder location(URI location)
Description copied from class:Response.ResponseBuilderSet the location.- Specified by:
locationin classResponse.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()). Ifnullany existing value for location will be removed.- Returns:
- the updated response builder.
-
contentLocation
public Response.ResponseBuilder contentLocation(URI location)
Description copied from class:Response.ResponseBuilderSet the content location.- Specified by:
contentLocationin classResponse.ResponseBuilder- Parameters:
location- the content location. Relative or absolute URIs may be used for the value of content location. Ifnullany existing value for content location will be removed.- Returns:
- the updated response builder.
-
encoding
public Response.ResponseBuilder encoding(String encoding)
Description copied from class:Response.ResponseBuilderSet the message entity content encoding.- Specified by:
encodingin classResponse.ResponseBuilder- Parameters:
encoding- the content encoding of the message entity, ifnullany existing value for content encoding will be removed.- Returns:
- the updated response builder.
-
tag
public Response.ResponseBuilder tag(EntityTag tag)
Description copied from class:Response.ResponseBuilderSet a response entity tag.- Specified by:
tagin classResponse.ResponseBuilder- Parameters:
tag- the entity tag, ifnullany existing entity tag value will be removed.- Returns:
- the updated response builder.
-
tag
public Response.ResponseBuilder tag(String tag)
Description copied from class:Response.ResponseBuilderSet a strong response entity tag.
This is a shortcut fortag(new EntityTag(value)).- Specified by:
tagin classResponse.ResponseBuilder- Parameters:
tag- the string content of a strong entity tag. The JAX-RS runtime will quote the supplied value when creating the header. Ifnullany existing entity tag value will be removed.- Returns:
- the updated response builder.
-
lastModified
public Response.ResponseBuilder lastModified(Date lastModified)
Description copied from class:Response.ResponseBuilderSet the response entity last modification date.- Specified by:
lastModifiedin classResponse.ResponseBuilder- Parameters:
lastModified- the last modified date, ifnullany existing last modified value will be removed.- Returns:
- the updated response builder.
-
cacheControl
public Response.ResponseBuilder cacheControl(CacheControl cacheControl)
Description copied from class:Response.ResponseBuilderSet the cache control data of the message.- Specified by:
cacheControlin classResponse.ResponseBuilder- Parameters:
cacheControl- the cache control directives, ifnullany existing cache control directives will be removed.- Returns:
- the updated response builder.
-
expires
public Response.ResponseBuilder expires(Date expires)
Description copied from class:Response.ResponseBuilderSet the response expiration date.- Specified by:
expiresin classResponse.ResponseBuilder- Parameters:
expires- the expiration date, ifnullremoves any existing expires value.- Returns:
- the updated response builder.
-
cookie
public Response.ResponseBuilder cookie(NewCookie... cookies)
Description copied from class:Response.ResponseBuilderAdd cookies to the response message.- Specified by:
cookiein classResponse.ResponseBuilder- Parameters:
cookies- new cookies that will accompany the response. Anullvalue will remove all cookies, including those added via theResponse.ResponseBuilder.header(java.lang.String, java.lang.Object)method.- Returns:
- the updated response builder.
-
header
public Response.ResponseBuilder header(String name, Object value)
Description copied from class:Response.ResponseBuilderAdd an arbitrary header.- Specified by:
headerin classResponse.ResponseBuilder- Parameters:
name- the name of the headervalue- the value of the header, the header will be serialized using aRuntimeDelegate.HeaderDelegateif one is available viaRuntimeDelegate.createHeaderDelegate(java.lang.Class)for the class ofvalueor using itstoStringmethod if a header delegate is not available. Ifvalueisnullthen all current headers of the same name will be removed.- Returns:
- the updated response builder.
-
variants
public Response.ResponseBuilder variants(Variant... variants)
Description copied from class:Response.ResponseBuilderAdd a Vary header that lists the available variants.- Specified by:
variantsin classResponse.ResponseBuilder- Parameters:
variants- a list of available representation variants, anullvalue will remove an existing value for Vary header.- Returns:
- the updated response builder.
-
links
public Response.ResponseBuilder links(Link... links)
Description copied from class:Response.ResponseBuilderAdd one or more link headers.- Specified by:
linksin classResponse.ResponseBuilder- Parameters:
links- links to be added to the message as headers, anullvalue will remove any existing Link headers.- Returns:
- the updated response builder.
-
link
public Response.ResponseBuilder link(URI uri, String rel)
Description copied from class:Response.ResponseBuilderAdd a link header.- Specified by:
linkin classResponse.ResponseBuilder- Parameters:
uri- underlying URI for link header.rel- value of "rel" parameter.- Returns:
- the updated response builder.
-
link
public Response.ResponseBuilder link(String uri, String rel)
Description copied from class:Response.ResponseBuilderAdd a link header.- Specified by:
linkin classResponse.ResponseBuilder- Parameters:
uri- underlying URI for link header.rel- value of "rel" parameter.- Returns:
- the updated response builder.
-
allow
public Response.ResponseBuilder allow(String... methods)
Description copied from class:Response.ResponseBuilderSet the list of allowed methods for the resource. Any duplicate method names will be truncated to a single entry.- Specified by:
allowin classResponse.ResponseBuilder- Parameters:
methods- the methods to be listed as allowed for the resource, ifnullany existing allowed method list will be removed.- Returns:
- the updated response builder.
-
allow
public Response.ResponseBuilder allow(Set<String> methods)
Description copied from class:Response.ResponseBuilderSet the list of allowed methods for the resource.- Specified by:
allowin classResponse.ResponseBuilder- Parameters:
methods- the methods to be listed as allowed for the resource, ifnullany existing allowed method list will be removed.- Returns:
- the updated response builder.
-
replaceAll
public Response.ResponseBuilder replaceAll(MultivaluedMap<String,Object> headers)
Description copied from class:Response.ResponseBuilderReplaces all existing headers with the newly supplied headers.- Specified by:
replaceAllin classResponse.ResponseBuilder- Parameters:
headers- new headers to be set, ifnullall existing headers will be removed.- Returns:
- the updated response builder.
-
-