javax.ws.rs.core
Class Response.ResponseBuilder

java.lang.Object
  extended by javax.ws.rs.core.Response.ResponseBuilder
Enclosing class:
Response

public abstract static class Response.ResponseBuilder
extends java.lang.Object

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().


Constructor Summary
protected Response.ResponseBuilder()
          Protected constructor, use one of the static methods of Response to obtain an instance.
 
Method Summary
abstract  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(java.net.URI location)
          Set the content location on the ResponseBuilder.
abstract  Response.ResponseBuilder cookie(NewCookie... cookies)
          Add cookies to the ResponseBuilder.
abstract  Response.ResponseBuilder entity(java.lang.Object entity)
          Set the entity on the ResponseBuilder.
abstract  Response.ResponseBuilder header(java.lang.String name, java.lang.Object value)
          Set the value of a specific header on the ResponseBuilder.
abstract  Response.ResponseBuilder language(java.lang.String language)
          Set the language on the ResponseBuilder.
abstract  Response.ResponseBuilder lastModified(java.util.Date lastModified)
          Set the last modified date on the ResponseBuilder.
abstract  Response.ResponseBuilder location(java.net.URI location)
          Set the location on the ResponseBuilder.
protected static Response.ResponseBuilder newInstance()
          Create a new builder instance.
abstract  Response.ResponseBuilder status(int status)
          Set the status on the ResponseBuilder.
 Response.ResponseBuilder status(Response.Status status)
          Set the status on the ResponseBuilder.
abstract  Response.ResponseBuilder tag(EntityTag tag)
          Set an entity tag on the ResponseBuilder.
abstract  Response.ResponseBuilder tag(java.lang.String tag)
          Set a strong entity tag on the ResponseBuilder.
abstract  Response.ResponseBuilder type(MediaType type)
          Set the response media type on the ResponseBuilder.
abstract  Response.ResponseBuilder type(java.lang.String type)
          Set the response media type on the ResponseBuilder.
abstract  Response.ResponseBuilder variant(Variant variant)
          Set representation metadata on the ResponseBuilder.
abstract  Response.ResponseBuilder variants(java.util.List<Variant> variants)
          Add a Vary header that lists the available variants.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Response.ResponseBuilder

protected Response.ResponseBuilder()
Protected constructor, use one of the static methods of Response to obtain an instance.

Method Detail

newInstance

protected static Response.ResponseBuilder newInstance()
Create a new builder instance.

Returns:
a new ResponseBuilder

build

public abstract Response 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

public abstract Response.ResponseBuilder clone()
Create a copy of the ResponseBuilder preserving its state.

Overrides:
clone in class java.lang.Object
Returns:
a copy of the ResponseBuilder

status

public abstract Response.ResponseBuilder status(int status)
Set the status on the ResponseBuilder.

Parameters:
status - the response status
Returns:
the updated ResponseBuilder

status

public Response.ResponseBuilder status(Response.Status status)
Set the status on the ResponseBuilder.

Parameters:
status - the response status
Returns:
the updated ResponseBuilder
Throws:
java.lang.IllegalArgumentException - if status is null

entity

public abstract Response.ResponseBuilder entity(java.lang.Object entity)
Set the entity on the ResponseBuilder.

Parameters:
entity - the response entity
Returns:
the updated ResponseBuilder

type

public abstract Response.ResponseBuilder type(MediaType type)
Set the response media type on the ResponseBuilder.

Parameters:
type - the media type of the response entity
Returns:
the updated ResponseBuilder

type

public abstract Response.ResponseBuilder type(java.lang.String type)
Set the response media type on the ResponseBuilder.

Parameters:
type - the media type of the response entity
Returns:
the updated ResponseBuilder
Throws:
java.lang.IllegalArgumentException - if type cannot be parsed

variant

public abstract Response.ResponseBuilder variant(Variant variant)
Set representation metadata on the ResponseBuilder.

Parameters:
variant - metadata of the response entity
Returns:
the updated ResponseBuilder

variants

public abstract Response.ResponseBuilder variants(java.util.List<Variant> variants)
Add a Vary header that lists the available variants.

Parameters:
variants - a list of available representation variants
Returns:
the updated ResponseBuilder

language

public abstract Response.ResponseBuilder language(java.lang.String language)
Set the language on the ResponseBuilder.

Parameters:
language - the language of the response entity
Returns:
the updated ResponseBuilder

location

public abstract Response.ResponseBuilder location(java.net.URI 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 (see UriInfo.getBaseUri()).
Returns:
the updated ResponseBuilder

contentLocation

public abstract Response.ResponseBuilder contentLocation(java.net.URI location)
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.
Returns:
the updated ResponseBuilder

tag

public abstract Response.ResponseBuilder tag(EntityTag tag)
Set an entity tag on the ResponseBuilder.

Parameters:
tag - the entity tag
Returns:
the updated ResponseBuilder

tag

public abstract Response.ResponseBuilder tag(java.lang.String tag)
Set a strong entity tag on the ResponseBuilder. This is a shortcut for tag(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.
Returns:
the updated ResponseBuilder

lastModified

public abstract Response.ResponseBuilder lastModified(java.util.Date lastModified)
Set the last modified date on the ResponseBuilder.

Parameters:
lastModified - the last modified date
Returns:
the updated ResponseBuilder

cacheControl

public abstract Response.ResponseBuilder cacheControl(CacheControl cacheControl)
Set the cache control data on the ResponseBuilder.

Parameters:
cacheControl - the cache control directives
Returns:
the updated ResponseBuilder

header

public abstract Response.ResponseBuilder header(java.lang.String name,
                                                java.lang.Object value)
Set the value of a specific header on the ResponseBuilder.

Parameters:
name - the name of the header
value - the value of the header, the header will be serialized using its toString method
Returns:
the updated ResponseBuilder

cookie

public abstract Response.ResponseBuilder cookie(NewCookie... cookies)
Add cookies to the ResponseBuilder. If more than one cookie with the same is supplied, later ones overwrite earlier ones.

Parameters:
cookies - new cookies that will accompany the response.
Returns:
the updated ResponseBuilder


Copyright © 2008. All Rights Reserved.