org.exoplatform.services.rest
Class Response.Builder

java.lang.Object
  extended by org.exoplatform.services.rest.Response.Builder
Enclosing class:
Response

public static class Response.Builder
extends Object

REST Response builder.


Constructor Summary
protected Response.Builder()
          Must not be visible for external class.
 
Method Summary
static Response.Builder accepted()
          create Builder with HTTP status 202 (ACCEPTED).
static Response.Builder badRequest()
          create Builder with HTTP status 400 (BAD REQUEST).
 Response build()
          create REST Response with parameters collected by Builder.
 Response.Builder cacheControl(CacheControl c)
           
 Response.Builder contentLenght(long length)
          set Content-Length header.
 Response.Builder cookies(Cookie... cc)
          Add new cookies.
static Response.Builder created(Object e, String location)
          create Builder with status 201 (CREATED) and entity.
static Response.Builder created(String location)
          create Builder with status 201 (CREATED).
 Response.Builder encodings(List<String> encodings)
          set Content-Encoding.
 Response.Builder entity(Object e)
          add entity to the Builder.
 Response.Builder entity(Object e, String mediaType)
          add entity to the Builder and set entity Content-Type.
 Response.Builder errorMessage(String message)
          Prepared error response and set transformer.
static Response.Builder forbidden()
          create Builder with HTTP status 403 (FORBIDDEN).
 Response.Builder header(String key, String value)
          add response single header.
 Response.Builder headers(MultivaluedMetadata headers)
          set response headers.
 Response.Builder languages(List<String> languages)
          set Content-Language.
 Response.Builder lastModified(Date lastModified)
          set Last-Modified header.
 Response.Builder locations(String location)
          set Location header.
 Response.Builder mediaType(String mediaType)
          set entity Content-Type.
protected static Response.Builder newInstance()
          Create a new instance of builder.
static Response.Builder noContent()
          create Builder with HTTP status 204 (NO CONTENT).
static Response.Builder notFound()
          create Builder with HTTP status 404 (NOT FOUND).
static Response.Builder notModified()
          create Builder with HTTP status 304 (NOT MODIFIED).
static Response.Builder notModified(String tag)
          create Builder with HTTP status 304 (NOT MODIFIED) and HTTP EntityTag.
static Response.Builder ok()
          create Builder with HTTP status 200 (OK).
static Response.Builder ok(Object e)
          create Builder with HTTP status 200 (OK) and entity.
static Response.Builder ok(Object e, String mediaType)
          create Builder with HTTP status 200 (OK),entity and set entity type.
static Response.Builder representation(Object e)
          create Builder with HTTP status 200 (OK) and entity.
static Response.Builder representation(Object e, String type)
          create Builder with HTTP status 200 (OK), entity and set entity type.
static Response.Builder serverError()
          create Builder with HTTP status 500 (INTERNAL SERVER ERROR).
 Response.Builder setTransformerParameters(Map<String,String> trfParams)
          set parameters for OutputEntityTransformer.
 Response.Builder status(int st)
          return Buider with changed status.
 Response.Builder tag(String tag)
          set HTTP EntityTag header.
static Response.Builder temporaryRedirect(String location)
          created Builder with HTTP status 307 (TEMPORARY REDIRECT).
 Response.Builder transformer(OutputEntityTransformer trf)
          set OutputEntityTransformer.
static Response.Builder withStatus(int st)
          create Builder with selected status.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Response.Builder

protected Response.Builder()
Must not be visible for external class.

Method Detail

newInstance

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

Returns:
the new instance of Builder.

build

public Response build()
create REST Response with parameters collected by Builder.

Returns:
the REST Response.

withStatus

public static Response.Builder withStatus(int st)
create Builder with selected status.

Parameters:
st - the HTTP status
Returns:
the new instance of Builder with given status.

representation

public static Response.Builder representation(Object e)
create Builder with HTTP status 200 (OK) and entity.

Parameters:
e - the entity.
Returns:
the new Builder instance with status 200 (OK) and entity.

representation

public static Response.Builder representation(Object e,
                                              String type)
create Builder with HTTP status 200 (OK), entity and set entity type.

Parameters:
e - the entity.
type - the entity type.
Returns:
the new instance of Builder with status 200 (OK), entity and media type.

ok

public static Response.Builder ok()
create Builder with HTTP status 200 (OK).

Returns:
new instance of Builder with status 200 (OK).

ok

public static Response.Builder ok(Object e)
create Builder with HTTP status 200 (OK) and entity.

Parameters:
e - the entity.
Returns:
the new Builder instance with status 200 (OK) and entity.

ok

public static Response.Builder ok(Object e,
                                  String mediaType)
create Builder with HTTP status 200 (OK),entity and set entity type.

Parameters:
e - the entity.
mediaType - the entity type.
Returns:
the new instance of Builder with status 200 (OK), entity and media type.

created

public static Response.Builder created(String location)
create Builder with status 201 (CREATED).

Parameters:
location - the location created resources.
Returns:
the new instance of Builder with status 201 (CREATED) and header Location.

created

public static Response.Builder created(Object e,
                                       String location)
create Builder with status 201 (CREATED) and entity.

Parameters:
e - the entity.
location - the location created resources.
Returns:
the new instance of Builder with status 201 (CREATED), header Location and Location in entity body.

accepted

public static Response.Builder accepted()
create Builder with HTTP status 202 (ACCEPTED).

Returns:
the new instance of Builder with status 202 (ACCEPTED).

noContent

public static Response.Builder noContent()
create Builder with HTTP status 204 (NO CONTENT).

Returns:
the new instance of Builder with status 204 (NO CONTENT).

temporaryRedirect

public static Response.Builder temporaryRedirect(String location)
created Builder with HTTP status 307 (TEMPORARY REDIRECT).

Parameters:
location - the new resource location.
Returns:
the new instance of Builder with status 307 (TEMPORARY REDIRECT).

notModified

public static Response.Builder notModified()
create Builder with HTTP status 304 (NOT MODIFIED).

Returns:
the new instance of Builder with status 304 (NOT MODIFIED).

notModified

public static Response.Builder notModified(String tag)
create Builder with HTTP status 304 (NOT MODIFIED) and HTTP EntityTag.

Parameters:
tag - the HTTP EntityTag.
Returns:
the new instance of Builder with status 304 (NOT MODIFIED) and HTTP EntityTag.

forbidden

public static Response.Builder forbidden()
create Builder with HTTP status 403 (FORBIDDEN).

Returns:
the new instance of Builder with status 403 (FORBIDDEN).

notFound

public static Response.Builder notFound()
create Builder with HTTP status 404 (NOT FOUND).

Returns:
the new instance of Builder with status 404 (NOT FOUND).

badRequest

public static Response.Builder badRequest()
create Builder with HTTP status 400 (BAD REQUEST).

Returns:
the new instance of Builder with status 400 (BAD REQUEST).

serverError

public static Response.Builder serverError()
create Builder with HTTP status 500 (INTERNAL SERVER ERROR).

Returns:
the new instance of Builder with status 500 (INTERNAL SERVER ERROR).

status

public Response.Builder status(int st)
return Buider with changed status.

Parameters:
st - the HTTP status.
Returns:
the Builder with changed status.

entity

public Response.Builder entity(Object e)
add entity to the Builder.

Parameters:
e - the entity (object with represents requested resource).
Returns:
the Builder with added entity.

entity

public Response.Builder entity(Object e,
                               String mediaType)
add entity to the Builder and set entity Content-Type.

Parameters:
e - the entity (object with represents requested resource).
mediaType - the entity media type.
Returns:
the Builder with added entity and media type.

mediaType

public Response.Builder mediaType(String mediaType)
set entity Content-Type.

Parameters:
mediaType - the entity media type.
Returns:
the Builder with added media type.

languages

public Response.Builder languages(List<String> languages)
set Content-Language.

Parameters:
languages - the List < String > of language.
Returns:
the Builder with added header "Content-Language".

encodings

public Response.Builder encodings(List<String> encodings)
set Content-Encoding.

Parameters:
encodings - the List < String > of content encoding.
Returns:
the Builder with added header "Content-Encoding".

locations

public Response.Builder locations(String location)
set Location header.

Parameters:
location - the Location string.
Returns:
the Builder with added "Location" header.

lastModified

public Response.Builder lastModified(Date lastModified)
set Last-Modified header.

Parameters:
lastModified - the date of last change in resource.
Returns:
the Builder with added "Last-Modified" header.

contentLenght

public Response.Builder contentLenght(long length)
set Content-Length header.

Parameters:
length - the size of data in bytes.
Returns:
the Builder with added "Content-Length" header.

tag

public Response.Builder tag(String tag)
set HTTP EntityTag header.

Parameters:
tag - the HTTP entity tag.
Returns:
the Builder with added "ETag" header.

transformer

public Response.Builder transformer(OutputEntityTransformer trf)
set OutputEntityTransformer.

Parameters:
trf - the output transformer.
Returns:
the Builder with added entity transformer.
See Also:
org.exoplatform.services.rest.transformer.OutputEntityTransformer.

setTransformerParameters

public Response.Builder setTransformerParameters(Map<String,String> trfParams)
set parameters for OutputEntityTransformer.

Parameters:
trfParams - parameters.
Returns:
the Builder with added transformer parameters.

header

public Response.Builder header(String key,
                               String value)
add response single header.

Parameters:
key - the key.
value - the value.
Returns:
the Builder with added single header.

headers

public Response.Builder headers(MultivaluedMetadata headers)
set response headers.

Parameters:
headers - key-values pair of HTTP response header.
Returns:
the Builder with new sets of HTTP headers.

cacheControl

public Response.Builder cacheControl(CacheControl c)
Parameters:
c - the CacheControl.
Returns:
the Builder with added Cache-Control header.
See Also:
org.exoplatform.services.rest.CacheControl.

cookies

public Response.Builder cookies(Cookie... cc)
Add new cookies.

Parameters:
cc - the new cookies that will be added to response.
Returns:
the Builder instance.

errorMessage

public Response.Builder errorMessage(String message)
Prepared error response and set transformer.

Parameters:
message - - error message.
Returns:
the instance of Builder with entity represented by String and StringOutputTransformer.


Copyright © 2009 eXo Platform SAS. All Rights Reserved.