|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.tapestry.request.RequestContext
public class RequestContext
This class encapsulates all the relevant data for one request cycle of an
ApplicationServlet
. This includes:
It also provides methods for:
RequestContext
(for debugging).
If some cases, it is necesary to provide an implementation of
IRequestDecoder
(often, due to a firewall).
If the application specifification
provides an extension named
org.apache.tapestry.request-decoder
then it will be used, instead of a default decoder.
This class is not a component, but does implement IRender
. When asked to render
(perhaps as the delegate of a Delegator
component}
it simply invokes write(IMarkupWriter)
to display all debugging output.
This class is derived from the original class
com.primix.servlet.RequestContext
,
part of the ServletUtils framework available from
The Giant
Java Tree.
Constructor Summary | |
---|---|
RequestContext(ApplicationServlet servlet,
HttpServletRequest request,
HttpServletResponse response)
Creates a RequestContext from its components. |
Method Summary | |
---|---|
void |
addCookie(Cookie cookie)
Adds a Cookie to the response. |
void |
addCookie(String name,
String value)
Adds a simple Cookie . |
void |
cleanup()
Invoked at the end of the request cycle to cleanup and temporary resources. |
HttpSession |
createSession()
Like getSession() , but forces the creation of
the HttpSession , if necessary. |
String |
getAbsoluteURL(String URI)
Builds an absolute URL from the given URI, using the HttpServletRequest
as the source for scheme, server name and port. |
String |
getAbsoluteURL(String URI,
String scheme,
String server,
int port)
Does some easy checks to turn a path (or URI) into an absolute URL. |
Object |
getAttribute(String name)
Convienience method for getting a HttpServletRequest attribute. |
Cookie |
getCookie(String name)
Gets a named Cookie . |
String |
getCookieValue(String name)
Reads the named Cookie and returns its value (if it exists), or
null if it does not exist. |
String |
getParameter(String name)
Returns the named parameter from the HttpServletRequest . |
String[] |
getParameters(String name)
For parameters that are, or are possibly, multi-valued, this method returns all the values as an array of Strings. |
HttpServletRequest |
getRequest()
Returns the request which initiated the current request cycle. |
String |
getRequestURI()
Returns the actual request URI, possibly decoded from the request. |
HttpServletResponse |
getResponse()
|
String |
getScheme()
Returns the actual scheme, possibly decoded from the request. |
String |
getServerName()
Returns the actual server name, possibly decoded from the request. |
int |
getServerPort()
Returns the actual server port, possibly decoded from the request. |
ApplicationServlet |
getServlet()
|
HttpSession |
getSession()
Returns the HttpSession , if necessary, invoking
HttpServletRequest.getSession(boolean) . |
IUploadFile |
getUploadFile(String name)
Returns the named IUploadFile , if it exists, or null if it doesn't. |
protected IMultipartDecoder |
obtainMultipartDecoder(ApplicationServlet servlet,
HttpServletRequest request)
Invoked from the constructor to create a DefaultMultipartDecoder instance. |
void |
redirect(String path)
Invokes HttpServletResponse.sendRedirect(String) ,
but massages path , supplying missing elements to
make it an absolute URL (i.e., specifying scheme, server, port, etc.). |
void |
render(IMarkupWriter writer,
IRequestCycle cycle)
Invokes write(IMarkupWriter) , which is used for debugging. |
void |
setDecoder(IMultipartDecoder decoder)
Sets the multipart decoder to be used for the request. |
void |
write(IMarkupWriter writer)
Writes the state of the context to the writer, typically for inclusion in a HTML page returned to the user. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public RequestContext(ApplicationServlet servlet, HttpServletRequest request, HttpServletResponse response) throws IOException
RequestContext
from its components.
IOException
Method Detail |
---|
protected IMultipartDecoder obtainMultipartDecoder(ApplicationServlet servlet, HttpServletRequest request) throws IOException
DefaultMultipartDecoder
instance.
Applications with specific upload needs may need to override this to
provide a subclass instance instead. The caller will invoke
IMultipartDecoder.decode(HttpServletRequest)
on the
returned object.
This implementation checks for application extension
Tapestry.MULTIPART_DECODER_EXTENSION_NAME
. If that is not
defined, a shared instance of DefaultMultipartDecoder
is returned.
IOException
ApplicationServlet.createRequestContext(HttpServletRequest, HttpServletResponse)
public void addCookie(String name, String value)
Cookie
. To set a Cookie with attributes,
use addCookie(Cookie)
.
public void addCookie(Cookie cookie)
Cookie
to the response. Once added, the
Cookie will also be available to getCookie(String)
method.
Cookies should only be added before invoking
ServletResponse.getWriter()
..
public String getScheme()
IRequestDecoder
,
ServletRequest.getScheme()
public String getServerName()
IRequestDecoder
,
ServletRequest.getServerName()
public int getServerPort()
IRequestDecoder
,
ServletRequest.getServerPort()
public String getRequestURI()
IRequestDecoder
,
HttpServletRequest.getRequestURI()
public String getAbsoluteURL(String URI)
HttpServletRequest
as the source for scheme, server name and port.
getAbsoluteURL(String, String, String, int)
public String getAbsoluteURL(String URI, String scheme, String server, int port)
public Cookie getCookie(String name)
Cookie
.
name
- The name of the Cookie.
public String getCookieValue(String name)
Cookie
and returns its value (if it exists), or
null if it does not exist.
public String getParameter(String name)
HttpServletRequest
.
Use getParameters(String)
for parameters that may
include multiple values.
This is the preferred way to obtain parameter values (rather than
obtaining the HttpServletRequest
itself). For form/multipart-data
encoded requests, this method will still work.
public Object getAttribute(String name)
HttpServletRequest
attribute.
public String[] getParameters(String name)
getParameter(String)
public IUploadFile getUploadFile(String name)
IUploadFile
, if it exists, or null if it doesn't.
Uploads require an encoding of multipart/form-data
(this is specified in the
form's enctype attribute). If the encoding type
is not so, or if no upload matches the name, then this method returns null.
public void cleanup()
DefaultMultipartDecoder
, if there is one.
public HttpServletRequest getRequest()
getParameter(String)
and getParameters(String)
should be used, rather than obtaining parameters directly from the request
(since the RequestContext handles the differences between normal and multipart/form
requests).
public HttpServletResponse getResponse()
public ApplicationServlet getServlet()
public HttpSession getSession()
HttpSession
, if necessary, invoking
HttpServletRequest.getSession(boolean)
. However,
this method will not create a session.
public HttpSession createSession()
getSession()
, but forces the creation of
the HttpSession
, if necessary.
public void redirect(String path) throws IOException
HttpServletResponse.sendRedirect(String)
,
but massages path
, supplying missing elements to
make it an absolute URL (i.e., specifying scheme, server, port, etc.).
The 2.2 Servlet API will do this automatically, and a little more, according to the early documentation.
IOException
public void write(IMarkupWriter writer)
public void render(IMarkupWriter writer, IRequestCycle cycle)
write(IMarkupWriter)
, which is used for debugging.
Does nothing if the cycle is rewinding.
render
in interface IRender
public void setDecoder(IMultipartDecoder decoder)
decoder
- the multipart decoder
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |