|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.apache.tapestry.request.RequestContext
This class encapsulates all the relevant data for one request cycle of an
ApplicationServlet
. This includes:
HttpServletRequest
HttpServletResponse
HttpSession
HttpServlet
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(javax.servlet.http.HttpServlet servlet,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
IApplicationSpecification specification)
Creates a RequestContext from its components. |
Method Summary | |
void |
addCookie(javax.servlet.http.Cookie cookie)
Adds a Cookie to the response. |
void |
addCookie(java.lang.String name,
java.lang.String value)
Adds a simple Cookie . |
void |
cleanup()
Invoked at the end of the request cycle to cleanup and temporary resources. |
javax.servlet.http.HttpSession |
createSession()
Like getSession() , but forces the creation of the HttpSession , if
necessary. |
java.lang.String |
getAbsoluteURL(java.lang.String URI)
Builds an absolute URL from the given URI, using the HttpServletRequest as the source
for scheme, server name and port. |
java.lang.String |
getAbsoluteURL(java.lang.String URI,
java.lang.String scheme,
java.lang.String server,
int port)
Does some easy checks to turn a path (or URI) into an absolute URL. |
IApplicationSpecification |
getApplicationSpecification()
|
java.lang.Object |
getAttribute(java.lang.String name)
Convienience method for getting a HttpServletRequest attribute. |
java.lang.String |
getContextPath()
Returns the context path, which is the portion of the URL that identifies the web application context. |
javax.servlet.http.Cookie |
getCookie(java.lang.String name)
Gets a named Cookie . |
java.lang.String |
getCookieValue(java.lang.String name)
Reads the named Cookie and returns its value (if it exists), or null if it does not
exist. |
java.lang.String |
getParameter(java.lang.String name)
Returns the named parameter from the HttpServletRequest . |
java.lang.String[] |
getParameterNames()
|
java.lang.String[] |
getParameters(java.lang.String name)
For parameters that are, or are possibly, multi-valued, this method returns all the values as an array of Strings. |
javax.servlet.http.HttpServletRequest |
getRequest()
Returns the request which initiated the current request cycle. |
java.lang.String |
getRequestURI()
Returns the actual request URI, possibly decoded from the request. |
javax.servlet.http.HttpServletResponse |
getResponse()
|
java.lang.String |
getScheme()
Returns the actual scheme, possibly decoded from the request. |
java.lang.String |
getServerName()
Returns the actual server name, possibly decoded from the request. |
int |
getServerPort()
Returns the actual server port, possibly decoded from the request. |
javax.servlet.http.HttpServlet |
getServlet()
|
javax.servlet.http.HttpSession |
getSession()
Returns the HttpSession , if necessary, invoking
HttpServletRequest.getSession(boolean) . |
IUploadFile |
getUploadFile(java.lang.String name)
Returns the named IUploadFile , if it exists, or null if it doesn't. |
protected IMultipartDecoder |
obtainMultipartDecoder(javax.servlet.http.HttpServlet servlet,
javax.servlet.http.HttpServletRequest request)
Invoked from the constructor to create a DefaultMultipartDecoder instance. |
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(javax.servlet.http.HttpServlet servlet, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, IApplicationSpecification specification) throws java.io.IOException
RequestContext
from its components.
Method Detail |
protected IMultipartDecoder obtainMultipartDecoder(javax.servlet.http.HttpServlet servlet, javax.servlet.http.HttpServletRequest request) throws java.io.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.
java.io.IOException
ApplicationServlet#createRequestContext(HttpServletRequest, HttpServletResponse)
public void addCookie(java.lang.String name, java.lang.String value)
Cookie
. To set a Cookie with attributes, use
addCookie(Cookie)
.
public void addCookie(javax.servlet.http.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 java.lang.String getScheme()
IRequestDecoder
,
ServletRequest.getScheme()
public java.lang.String getServerName()
IRequestDecoder
,
ServletRequest.getServerName()
public int getServerPort()
IRequestDecoder
,
ServletRequest.getServerPort()
public java.lang.String getRequestURI()
IRequestDecoder
,
HttpServletRequest.getRequestURI()
public java.lang.String getAbsoluteURL(java.lang.String URI)
HttpServletRequest
as the source
for scheme, server name and port.
getAbsoluteURL(String, String, String, int)
public java.lang.String getAbsoluteURL(java.lang.String URI, java.lang.String scheme, java.lang.String server, int port)
public javax.servlet.http.Cookie getCookie(java.lang.String name)
Cookie
.
name
- The name of the Cookie.
public java.lang.String getCookieValue(java.lang.String name)
Cookie
and returns its value (if it exists), or null if it does not
exist.
public java.lang.String getParameter(java.lang.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 java.lang.Object getAttribute(java.lang.String name)
HttpServletRequest
attribute.
public java.lang.String[] getParameters(java.lang.String name)
getParameter(String)
public java.lang.String[] getParameterNames()
public IUploadFile getUploadFile(java.lang.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 javax.servlet.http.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 javax.servlet.http.HttpServletResponse getResponse()
public javax.servlet.http.HttpServlet getServlet()
public javax.servlet.http.HttpSession getSession()
HttpSession
, if necessary, invoking
HttpServletRequest.getSession(boolean)
. However, this method will not
create a session.
public javax.servlet.http.HttpSession createSession()
getSession()
, but forces the creation of the HttpSession
, if
necessary.
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 decoderpublic IApplicationSpecification getApplicationSpecification()
public java.lang.String getContextPath()
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |