ninja
Class ContextImpl

java.lang.Object
  extended by ninja.ContextImpl
All Implemented Interfaces:
Context

public class ContextImpl
extends Object
implements Context


Nested Class Summary
 
Nested classes/interfaces inherited from interface ninja.Context
Context.HTTP_STATUS
 
Constructor Summary
ContextImpl(BodyParserEngineManager bodyParserEngineManager, FlashCookie flashCookie, SessionCookie sessionCookie, ResultHandler resultHandler, Validation validation)
           
 
Method Summary
 Context addCookie(Cookie cookie)
          Add the given cookie to the response
 void asyncRequestComplete()
          Indicate that processing this request is complete.
 Result controllerReturned()
          Used to indicate that the controller has finished executing
 ResponseStreams finalizeHeaders(Result result)
          Finalizing the headers copies all stuff into the headers.
 String getCookieValue(String name)
          Get the cookie value from the request, if defined
 org.apache.commons.fileupload.FileItemIterator getFileItemIterator()
          Gets the FileItemIterator of the input.
 FlashCookie getFlashCookie()
          Returns the flash cookie.
 String getHeader(String name)
          Get the request header with the given name
 Map<String,String> getHeaders()
          Get all the headers from the request
 javax.servlet.http.HttpServletRequest getHttpServletRequest()
          Get the underlying HTTP servlet request
 javax.servlet.http.HttpServletResponse getHttpServletResponse()
          Get the underlying HTTP servlet response
 InputStream getInputStream()
          Get the input stream to read the request.
 String getParameter(String key)
          Get the parameter with the given key from the request.
 String getParameter(String key, String defaultValue)
          Same like Context.getParameter(String), but returns given defaultValue instead of null in case parameter cannot be found
 Integer getParameterAsInteger(String key)
          Same like Context.getParameter(String), but converts the parameter to Integer if found.
 Integer getParameterAsInteger(String key, Integer defaultValue)
          Same like Context.getParameter(String, String), but converts the parameter to Integer if found.
 Map<String,String[]> getParameters()
          Get all the parameters from the request
 String getPathParameter(String key)
          Get the path parameter for the given key
 Integer getPathParameterAsInteger(String key)
          Get the path parameter for the given key and convert it to Integer.
 BufferedReader getReader()
          Get the reader to read the request.
 String getRequestContentType()
          Content type of the request we got.
 String getRequestPath()
          Returns the path as seen by the server.
 String getRequestUri()
          Deprecated. 
 Route getRoute()
          Get the route for this context
 SessionCookie getSessionCookie()
          Returns the client side session.
 Validation getValidation()
          Get the validation context
 void handleAsync()
          Indicate that this request is going to be handled asynchronously
 void init(javax.servlet.http.HttpServletRequest httpServletRequest, javax.servlet.http.HttpServletResponse httpServletResponse)
           
 boolean isMultipart()
          Check if request is of type multipart.
<T> T
parseBody(Class<T> classOfT)
          This will give you the request body nicely parsed.
 void returnResultAsync(Result result)
          Indicate that request processing of an async request is complete.
 void setRoute(Route route)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ContextImpl

@Inject
public ContextImpl(BodyParserEngineManager bodyParserEngineManager,
                          FlashCookie flashCookie,
                          SessionCookie sessionCookie,
                          ResultHandler resultHandler,
                          Validation validation)
Method Detail

init

public void init(javax.servlet.http.HttpServletRequest httpServletRequest,
                 javax.servlet.http.HttpServletResponse httpServletResponse)

setRoute

public void setRoute(Route route)

getHttpServletRequest

public javax.servlet.http.HttpServletRequest getHttpServletRequest()
Description copied from interface: Context
Get the underlying HTTP servlet request

Specified by:
getHttpServletRequest in interface Context
Returns:
The HTTP servlet request

getHttpServletResponse

public javax.servlet.http.HttpServletResponse getHttpServletResponse()
Description copied from interface: Context
Get the underlying HTTP servlet response

Specified by:
getHttpServletResponse in interface Context
Returns:
The HTTP servlet response

getPathParameter

public String getPathParameter(String key)
Description copied from interface: Context
Get the path parameter for the given key

Specified by:
getPathParameter in interface Context
Parameters:
key - The key of the path parameter
Returns:
The path parameter, or null if no such path parameter is defined

getPathParameterAsInteger

public Integer getPathParameterAsInteger(String key)
Description copied from interface: Context
Get the path parameter for the given key and convert it to Integer.

Specified by:
getPathParameterAsInteger in interface Context
Parameters:
key - the key of the path parameter
Returns:
the numeric path parameter, or null of no such path parameter is defined, or if it cannot be parsed to int

getParameter

public String getParameter(String key)
Description copied from interface: Context
Get the parameter with the given key from the request. The parameter may either be a query parameter, or in the case of form submissions, may be a form parameter

Specified by:
getParameter in interface Context
Parameters:
key - The key of the parameter
Returns:
The value, or null if no parameter was found

getParameter

public String getParameter(String key,
                           String defaultValue)
Description copied from interface: Context
Same like Context.getParameter(String), but returns given defaultValue instead of null in case parameter cannot be found

Specified by:
getParameter in interface Context
Returns:

getParameterAsInteger

public Integer getParameterAsInteger(String key)
Description copied from interface: Context
Same like Context.getParameter(String), but converts the parameter to Integer if found.

Specified by:
getParameterAsInteger in interface Context
Returns:

getParameterAsInteger

public Integer getParameterAsInteger(String key,
                                     Integer defaultValue)
Description copied from interface: Context
Same like Context.getParameter(String, String), but converts the parameter to Integer if found.

Specified by:
getParameterAsInteger in interface Context
Returns:

getParameters

public Map<String,String[]> getParameters()
Description copied from interface: Context
Get all the parameters from the request

Specified by:
getParameters in interface Context
Returns:
The parameters

getHeader

public String getHeader(String name)
Description copied from interface: Context
Get the request header with the given name

Specified by:
getHeader in interface Context
Returns:
The header value

getHeaders

public Map<String,String> getHeaders()
Description copied from interface: Context
Get all the headers from the request

Specified by:
getHeaders in interface Context
Returns:
The headers

getCookieValue

public String getCookieValue(String name)
Description copied from interface: Context
Get the cookie value from the request, if defined

Specified by:
getCookieValue in interface Context
Parameters:
name - The name of the cookie
Returns:
The cookie value, or null if the cookie was not found

parseBody

public <T> T parseBody(Class<T> classOfT)
Description copied from interface: Context
This will give you the request body nicely parsed. You can register your own parsers depending on the request type. Have a look at BodyParserEngine BodyParserEngineJson and BodyParserEngineManager

Specified by:
parseBody in interface Context
Parameters:
classOfT - The class of the result.
Returns:
The parsed request or null if something went wrong.

getFlashCookie

public FlashCookie getFlashCookie()
Description copied from interface: Context
Returns the flash cookie. Flash cookies only live for one request. Good uses are error messages to display. Almost everything else is bad use of Flash Cookies. A FlashCookie is usually not signed. Don't trust the content.

Specified by:
getFlashCookie in interface Context
Returns:
the flash cookie of that request.

getSessionCookie

public SessionCookie getSessionCookie()
Description copied from interface: Context
Returns the client side session. It is a cookie. Therefore you cannot store a lot of information inside the cookie. This is by intention. If you have the feeling that the session cookie is too small for what you want to achieve thing again. Most likely your design is wrong.

Specified by:
getSessionCookie in interface Context
Returns:
the Session of that request / response cycle.

addCookie

public Context addCookie(Cookie cookie)
Description copied from interface: Context
Add the given cookie to the response

Specified by:
addCookie in interface Context
Parameters:
cookie - The cookie to add
Returns:
This context

getRequestUri

@Deprecated
public String getRequestUri()
Deprecated. 

Description copied from interface: Context
Returns the uri as seen by the server. http://example.com/index would return "/index". This is ambiguous. Please use the new method getRequestPath. It will also take care of any prefixes and contexts set by your servlet container

Specified by:
getRequestUri in interface Context
Returns:
the uri as seen by the server

handleAsync

public void handleAsync()
Description copied from interface: Context
Indicate that this request is going to be handled asynchronously

Specified by:
handleAsync in interface Context

returnResultAsync

public void returnResultAsync(Result result)
Description copied from interface: Context
Indicate that request processing of an async request is complete.

Specified by:
returnResultAsync in interface Context

asyncRequestComplete

public void asyncRequestComplete()
Description copied from interface: Context
Indicate that processing this request is complete.

Specified by:
asyncRequestComplete in interface Context

controllerReturned

public Result controllerReturned()
Used to indicate that the controller has finished executing

Specified by:
controllerReturned in interface Context

getInputStream

public InputStream getInputStream()
                           throws IOException
Description copied from interface: Context
Get the input stream to read the request. Must not be used if getReader has been called.

Specified by:
getInputStream in interface Context
Returns:
The input stream
Throws:
IOException

getReader

public BufferedReader getReader()
                         throws IOException
Description copied from interface: Context
Get the reader to read the request. Must not be used if getInputStream has been called.

Specified by:
getReader in interface Context
Returns:
The reader
Throws:
IOException

finalizeHeaders

public ResponseStreams finalizeHeaders(Result result)
Description copied from interface: Context
Finalizing the headers copies all stuff into the headers. After finalizing the headers you can access the responseStreams.

Specified by:
finalizeHeaders in interface Context
Returns:

getRequestContentType

public String getRequestContentType()
Description copied from interface: Context
Content type of the request we got. Important for content negotiation...

Specified by:
getRequestContentType in interface Context
Returns:
the content type of the incoming request.

getRoute

public Route getRoute()
Description copied from interface: Context
Get the route for this context

Specified by:
getRoute in interface Context
Returns:
The route

isMultipart

public boolean isMultipart()
Description copied from interface: Context
Check if request is of type multipart. Important when you want to process uploads for instance. Also check out: http://commons.apache.org/fileupload/streaming.html

Specified by:
isMultipart in interface Context
Returns:
true if request is of type multipart.

getFileItemIterator

public org.apache.commons.fileupload.FileItemIterator getFileItemIterator()
Description copied from interface: Context
Gets the FileItemIterator of the input. Can be used to process uploads in a streaming fashion. Check out: http://commons.apache.org/fileupload/streaming.html

Specified by:
getFileItemIterator in interface Context
Returns:
the FileItemIterator of the request or null if there was an error.

getRequestPath

public String getRequestPath()
Description copied from interface: Context
Returns the path as seen by the server. http://example.com/index would return "/index". It will also take care of any prefixes and contexts set by your servlet container

Specified by:
getRequestPath in interface Context
Returns:
the path as seen by the server

getValidation

public Validation getValidation()
Description copied from interface: Context
Get the validation context

Specified by:
getValidation in interface Context
Returns:
The validation context


Copyright © 2012. All Rights Reserved.