com.google.sitebricks.headless
Class Reply<E>

java.lang.Object
  extended by com.google.sitebricks.headless.Reply<E>

public abstract class Reply<E>
extends Object

Reply to a (headless) web request.


Field Summary
static Reply<?> NO_REPLY
           
static String NO_REPLY_ATTR
           
 
Constructor Summary
Reply()
           
 
Method Summary
abstract  Reply<E> as(Class<? extends Transport> transport)
          Directs sitebricks to use the given Guice key as a transport to marshall the provided entity to the client.
abstract  Reply<E> as(com.google.inject.Key<? extends Transport> transport)
          Same as as(Class).
abstract  Reply<E> error()
          Perform a 500 general error response.
abstract  Reply<E> forbidden()
          Perform a 403 resource forbidden error response.
abstract  Reply<E> headers(Map<String,String> headers)
          A Map of headers to set directly on the response.
abstract  Reply<E> noContent()
          Perform a 204 no content response.
abstract  Reply<E> notFound()
          Perform a 404 not found reply.
abstract  Reply<E> ok()
          Perform a 200 OK response with no body.
abstract  Reply<E> redirect(String uri)
          Perform a 302 redirect to the given uri (moved temporarily).
static
<E> Reply<E>
saying()
          Convenience method to make a reply without any entity or body.
abstract  Reply<E> seeOther(String uri)
          Perform a 301 redirect (moved permanently) to the given uri.
abstract  Reply<E> seeOther(String uri, int statusCode)
          Perform a custom redirect to the given uri.
abstract  Reply<E> status(int code)
          Set a custom status code (call this last, it will be overridden if other response code directives are called afterward).
abstract  Reply<E> template(Class<?> templateKey)
          Render template associated with the given class.
abstract  Reply<E> type(String mediaType)
          The media type of the response data to send to the client.
abstract  Reply<E> unauthorized()
          Perform a 401 not authorized reply.
static
<E> Reply<E>
with(E entity)
          Returns a reply with an entity that is sent back to the client via the specified transport.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NO_REPLY

public static final Reply<?> NO_REPLY

NO_REPLY_ATTR

public static final String NO_REPLY_ATTR
See Also:
Constant Field Values
Constructor Detail

Reply

public Reply()
Method Detail

seeOther

public abstract Reply<E> seeOther(String uri)
Perform a 301 redirect (moved permanently) to the given uri.


seeOther

public abstract Reply<E> seeOther(String uri,
                                  int statusCode)
Perform a custom redirect to the given uri. The status code must be in the 3XX range.


type

public abstract Reply<E> type(String mediaType)
The media type of the response data to send to the client. I.e. the mime-type. Example "application/json" for JSON responses.


headers

public abstract Reply<E> headers(Map<String,String> headers)
A Map of headers to set directly on the response.


notFound

public abstract Reply<E> notFound()
Perform a 404 not found reply.


unauthorized

public abstract Reply<E> unauthorized()
Perform a 401 not authorized reply.


as

public abstract Reply<E> as(Class<? extends Transport> transport)
Directs sitebricks to use the given Guice key as a transport to marshall the provided entity to the client. Example:
   return Reply.with(new Person(..)).as(Xml.class);
 

Will marhall the given Person object into XML using the Guice Key bound to [Xml.class] (by default this is an XStream based XML transport).


as

public abstract Reply<E> as(com.google.inject.Key<? extends Transport> transport)
Same as as(Class).


redirect

public abstract Reply<E> redirect(String uri)
Perform a 302 redirect to the given uri (moved temporarily).


forbidden

public abstract Reply<E> forbidden()
Perform a 403 resource forbidden error response.


noContent

public abstract Reply<E> noContent()
Perform a 204 no content response.


error

public abstract Reply<E> error()
Perform a 500 general error response.


template

public abstract Reply<E> template(Class<?> templateKey)
Render template associated with the given class. The class must have an @Show() annotation pointing to a valid Sitebricks template type (can be any of the supported templates: MVEL, freemarker, SB, etc.)

The entity passed into with() is used as the template's context during render.


status

public abstract Reply<E> status(int code)
Set a custom status code (call this last, it will be overridden if other response code directives are called afterward).


ok

public abstract Reply<E> ok()
Perform a 200 OK response with no body.


saying

public static <E> Reply<E> saying()
Convenience method to make a reply without any entity or body. Example, to send a redirect:
   return Reply.saying().redirect("/other");
 


with

public static <E> Reply<E> with(E entity)
Returns a reply with an entity that is sent back to the client via the specified transport.

Parameters:
entity - An entity to send back for which a valid transport exists (see as(Class)).


Copyright © 2014. All rights reserved.