com.google.sitebricks.headless
Interface Request


public interface Request

Sitebricks abstraction of a request. May be a standard HTTP request, a tunneled Sitebricks RPC-over-HTTP, or another abstraction entirely.

Author:
dhanji@gmail.com (Dhanji R. Prasanna)

Nested Class Summary
static interface Request.AsyncCompletion<E>
           
static interface Request.AsyncRequestRead<E>
           
static interface Request.RequestRead<E>
           
 
Method Summary
 String context()
           
 String header(String name)
          Returns the only value of a request header or null if the header was not present.
 com.google.common.collect.Multimap<String,String> headers()
          Returns request headers as a multimap (to account for repeated headers).
 com.google.common.collect.Multimap<String,String> matrix()
          Returns matrix parameters as a multimap (to account for repeated values).
 String matrixParam(String name)
          Returns the only value of a matrix parameter or null if the parameter was not present.
 String method()
           
 String param(String name)
          Returns the only value of a request parameter or null if the parameter was not present.
 com.google.common.collect.Multimap<String,String> params()
          Returns request parameters as a multimap (to account for repeated values).
 String path()
           
<E> Request.RequestRead<E>
read(Class<E> type)
          Reads the raw request data into an object of the given type.
<E> Request.AsyncRequestRead<E>
readAsync(Class<E> type)
          Reads the request data into an object of the given type, but does so asynchronously.
 void readTo(OutputStream out)
          Reads the request data directly into the given output stream.
 String uri()
           
 

Method Detail

read

<E> Request.RequestRead<E> read(Class<E> type)
Reads the raw request data into an object of the given type. Must be followed by a transport clause for correct unmarshalling. Example:
   Person p = request.read(Person.class).as(Json.class);
 

Parameters:
type - The target type to unmarshall the raw request data into.
Returns:
an instance containing the deserialized raw data.

readTo

void readTo(OutputStream out)
            throws IOException
Reads the request data directly into the given output stream. Useful for streaming uploads to a file or passthrough socket.

Parameters:
out - Any valid, open outputstream. Not closed after writing.
Throws:
IOException - If an error occurs during the streaming.

readAsync

<E> Request.AsyncRequestRead<E> readAsync(Class<E> type)
Reads the request data into an object of the given type, but does so asynchronously. In Sitebricks Sync (the servlet flavor) this won't do anything special, since the request is read in the same thread. In Sitebricks Async, this will read the request body asynchronously and fire the chained callback when the network is done, freeing up user threads to process other requests.

Parameters:
type - The target type to unmarshall the raw request data into.

headers

com.google.common.collect.Multimap<String,String> headers()
Returns request headers as a multimap (to account for repeated headers).


params

com.google.common.collect.Multimap<String,String> params()
Returns request parameters as a multimap (to account for repeated values).


matrix

com.google.common.collect.Multimap<String,String> matrix()
Returns matrix parameters as a multimap (to account for repeated values).


matrixParam

String matrixParam(String name)
Returns the only value of a matrix parameter or null if the parameter was not present.


param

String param(String name)
Returns the only value of a request parameter or null if the parameter was not present.

Behaves exactly like ServletRequest.getParameter(String).


header

String header(String name)
Returns the only value of a request header or null if the header was not present.

Behaves exactly like HttpServletRequest.getHeader(String).


uri

String uri()

path

String path()

context

String context()

method

String method()


Copyright © 2014. All rights reserved.