Class Response.ResponseBuilder
- Enclosing class:
- Response
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.
 
- 
Constructor SummaryConstructors Modifier Constructor Description protectedResponseBuilder()Protected constructor, use one of the static methods ofResponseto obtain an instance.
- 
Method SummaryModifier and Type Method Description abstract Response.ResponseBuilderallow(String... methods)Set the list of allowed methods for the resource.abstract Response.ResponseBuilderallow(Set<String> methods)Set the list of allowed methods for the resource.abstract Responsebuild()Create a Response instance from the current ResponseBuilder.abstract Response.ResponseBuildercacheControl(CacheControl cacheControl)Set the cache control data of the message.abstract Response.ResponseBuilderclone()abstract Response.ResponseBuildercontentLocation(URI location)Set the content location.abstract Response.ResponseBuildercookie(NewCookie... cookies)Add cookies to the response message.abstract Response.ResponseBuilderencoding(String encoding)Set the message entity content encoding.abstract Response.ResponseBuilderentity(Object entity)Set the response entity in the builder.abstract Response.ResponseBuilderentity(Object entity, Annotation[] annotations)Set the response entity in the builder.abstract Response.ResponseBuilderexpires(Date expires)Set the response expiration date.abstract Response.ResponseBuilderheader(String name, Object value)Add an arbitrary header.abstract Response.ResponseBuilderlanguage(String language)Set the message entity language.abstract Response.ResponseBuilderlanguage(Locale language)Set the message entity language.abstract Response.ResponseBuilderlastModified(Date lastModified)Set the response entity last modification date.abstract Response.ResponseBuilderlink(String uri, String rel)Add a link header.abstract Response.ResponseBuilderlink(URI uri, String rel)Add a link header.abstract Response.ResponseBuilderlinks(Link... links)Add one or more link headers.abstract Response.ResponseBuilderlocation(URI location)Set the location.protected static Response.ResponseBuildernewInstance()Create a new builder instance.abstract Response.ResponseBuilderreplaceAll(MultivaluedMap<String,Object> headers)Replaces all existing headers with the newly supplied headers.abstract Response.ResponseBuilderstatus(int status)Set the status on the ResponseBuilder.abstract Response.ResponseBuilderstatus(int status, String reasonPhrase)Set the status on the ResponseBuilder.Response.ResponseBuilderstatus(Response.Status status)Set the status on the ResponseBuilder.Response.ResponseBuilderstatus(Response.StatusType status)Set the status on the ResponseBuilder.abstract Response.ResponseBuildertag(EntityTag tag)Set a response entity tag.abstract Response.ResponseBuildertag(String tag)Set a strong response entity tag.abstract Response.ResponseBuildertype(MediaType type)Set the message entity media type.abstract Response.ResponseBuildertype(String type)Set the message entity media type.abstract Response.ResponseBuildervariant(Variant variant)Set message entity representation metadata.abstract Response.ResponseBuildervariants(Variant... variants)Add a Vary header that lists the available variants.abstract Response.ResponseBuildervariants(List<Variant> variants)Add a Vary header that lists the available variants.
- 
Constructor Details- 
ResponseBuilderprotected ResponseBuilder()Protected constructor, use one of the static methods ofResponseto obtain an instance.
 
- 
- 
Method Details- 
newInstanceCreate a new builder instance.- Returns:
- a new response builder.
 
- 
buildCreate 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.
 
- 
cloneCreate a copy of the ResponseBuilder preserving its state. 
- 
statusSet the status on the ResponseBuilder.- Parameters:
- status- the response status.
- Returns:
- the updated response builder.
- Throws:
- IllegalArgumentException- if status is less than- 100or greater than- 599.
 
- 
statusSet the status on the ResponseBuilder.- Parameters:
- status- the response status.
- reasonPhrase- the reason phrase.
- Returns:
- the updated response builder.
- Throws:
- IllegalArgumentException- if status is less than- 100or greater than- 599.
- Since:
- 2.1
 
- 
statusSet the status on the ResponseBuilder.- Parameters:
- status- the response status.
- Returns:
- the updated response builder.
- Throws:
- IllegalArgumentException- if status is- null.
- Since:
- 1.1
 
- 
statusSet the status on the ResponseBuilder.- Parameters:
- status- the response status.
- Returns:
- the updated response builder.
- Throws:
- IllegalArgumentException- if status is- null.
 
- 
entitySet 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.- Parameters:
- entity- the request entity.
- Returns:
- updated response builder instance.
- See Also:
- entity(java.lang.Object, java.lang.annotation.Annotation[]),- type(jakarta.ws.rs.core.MediaType),- type(java.lang.String)
 
- 
entitySet 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.- Parameters:
- 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).
- Returns:
- updated response builder instance.
- Since:
- 2.0
- See Also:
- entity(java.lang.Object),- type(jakarta.ws.rs.core.MediaType),- type(java.lang.String)
 
- 
allowSet the list of allowed methods for the resource. Any duplicate method names will be truncated to a single entry.- Parameters:
- methods- the methods to be listed as allowed for the resource, if- nullany existing allowed method list will be removed.
- Returns:
- the updated response builder.
- Since:
- 2.0
 
- 
allowSet the list of allowed methods for the resource.- Parameters:
- methods- the methods to be listed as allowed for the resource, if- nullany existing allowed method list will be removed.
- Returns:
- the updated response builder.
- Since:
- 2.0
 
- 
cacheControlSet the cache control data of the message.- Parameters:
- cacheControl- the cache control directives, if- nullany existing cache control directives will be removed.
- Returns:
- the updated response builder.
 
- 
encodingSet the message entity content encoding.- Parameters:
- encoding- the content encoding of the message entity, if- nullany existing value for content encoding will be removed.
- Returns:
- the updated response builder.
- Since:
- 2.0
 
- 
headerAdd an arbitrary header.- Parameters:
- name- the name of the header
- value- the value of the header, the header will be serialized using a- RuntimeDelegate.HeaderDelegateif one is available via- RuntimeDelegate.createHeaderDelegate(java.lang.Class)for the class of- valueor using its- toStringmethod if a header delegate is not available. If- valueis- nullthen all current headers of the same name will be removed.
- Returns:
- the updated response builder.
 
- 
replaceAllReplaces all existing headers with the newly supplied headers.- Parameters:
- headers- new headers to be set, if- nullall existing headers will be removed.
- Returns:
- the updated response builder.
- Since:
- 2.0
 
- 
languageSet the message entity language.- Parameters:
- language- the language of the message entity, if- nullany existing value for language will be removed.
- Returns:
- the updated response builder.
 
- 
languageSet the message entity language.- Parameters:
- language- the language of the message entity, if- nullany existing value for type will be removed.
- Returns:
- the updated response builder.
 
- 
typeSet the message entity media type.- Parameters:
- type- the media type of the message entity. If- null, any existing value for type will be removed.
- Returns:
- the updated response builder.
 
- 
typeSet the message entity media type.- Parameters:
- type- the media type of the message entity. If- null, any existing value for type will be removed.
- Returns:
- the updated response builder.
 
- 
variantSet 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.- Parameters:
- variant- metadata of the message entity, a- nullvalue is equivalent to a variant with all- nullproperties.
- Returns:
- the updated response builder.
- Since:
- 2.0
- See Also:
- encoding(java.lang.String),- language(java.util.Locale),- type(jakarta.ws.rs.core.MediaType)
 
- 
contentLocationSet the content location.- Parameters:
- location- the content location. Relative or absolute URIs may be used for the value of content location. If- nullany existing value for content location will be removed.
- Returns:
- the updated response builder.
 
- 
cookieAdd cookies to the response message.- Parameters:
- cookies- new cookies that will accompany the response. A- nullvalue will remove all cookies, including those added via the- header(java.lang.String, java.lang.Object)method.
- Returns:
- the updated response builder.
 
- 
expiresSet the response expiration date.- Parameters:
- expires- the expiration date, if- nullremoves any existing expires value.
- Returns:
- the updated response builder.
 
- 
lastModifiedSet the response entity last modification date.- Parameters:
- lastModified- the last modified date, if- nullany existing last modified value will be removed.
- Returns:
- the updated response builder.
 
- 
locationSet the location.- 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 (see- UriInfo.getBaseUri()). If- nullany existing value for location will be removed.
- Returns:
- the updated response builder.
 
- 
tagSet a response entity tag.- Parameters:
- tag- the entity tag, if- nullany existing entity tag value will be removed.
- Returns:
- the updated response builder.
 
- 
tagSet a strong response entity tag. 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- nullany existing entity tag value will be removed.
- Returns:
- the updated response builder.
 
- 
variantsAdd a Vary header that lists the available variants.- Parameters:
- variants- a list of available representation variants, a- nullvalue will remove an existing value for Vary header.
- Returns:
- the updated response builder.
- Since:
- 2.0
 
- 
variantsAdd a Vary header that lists the available variants.- Parameters:
- variants- a list of available representation variants, a- nullvalue will remove an existing value for Vary header.
- Returns:
- the updated response builder.
 
- 
linksAdd one or more link headers.- Parameters:
- links- links to be added to the message as headers, a- nullvalue will remove any existing Link headers.
- Returns:
- the updated response builder.
- Since:
- 2.0
 
- 
linkAdd a link header.- Parameters:
- uri- underlying URI for link header.
- rel- value of "rel" parameter.
- Returns:
- the updated response builder.
- Since:
- 2.0
 
- 
linkAdd a link header.- Parameters:
- uri- underlying URI for link header.
- rel- value of "rel" parameter.
- Returns:
- the updated response builder.
- Since:
- 2.0
 
 
-