org.directwebremoting
Interface WebContext

All Superinterfaces:
ServerContext
All Known Subinterfaces:
RealWebContext
All Known Implementing Classes:
DefaultWebContext

public interface WebContext
extends ServerContext

Class to enable us to access servlet parameters. WebContext is only available from a DWR thread. If you need to access web data from a non-DWR thread, use the superclass, ServerContext.

Author:
Joe Walker [joe at getahead dot ltd dot uk]

Field Summary
static java.lang.String ATTRIBUTE_DWR
          An attribute used by forwardToString(String) to inform anyone that wants to know that this is a request from DWR.
 
Method Summary
 java.lang.String forwardToString(java.lang.String url)
          Forward a request to a given URL and catch the data written to it.
 java.lang.String getCurrentPage()
          Returns the partial-URL of the page from which the current thread originated.
 javax.servlet.http.HttpServletRequest getHttpServletRequest()
          Accessor for the http request information.
 javax.servlet.http.HttpServletResponse getHttpServletResponse()
          Accessor for the http response bean.
 ScriptSession getScriptSession()
          Get the script session that represents the currently viewed page in the same way that an HttpSession represents a cookie.
 javax.servlet.http.HttpSession getSession()
          Returns the current session associated with this request, or if the request does not have a session, creates one.
 javax.servlet.http.HttpSession getSession(boolean create)
          Returns the current HttpSession associated with this request or, if there is no current session and create is true, returns a new session.
 
Methods inherited from interface org.directwebremoting.ServerContext
getAllScriptSessions, getContainer, getContextPath, getScriptSessionById, getScriptSessionsByPage, getServletConfig, getServletContext, getVersion
 

Field Detail

ATTRIBUTE_DWR

static final java.lang.String ATTRIBUTE_DWR
An attribute used by forwardToString(String) to inform anyone that wants to know that this is a request from DWR.

See Also:
Constant Field Values
Method Detail

getScriptSession

ScriptSession getScriptSession()
                               throws java.lang.UnsupportedOperationException
Get the script session that represents the currently viewed page in the same way that an HttpSession represents a cookie.

If the DWR thread that gave rise to this WebContext is as a result of a JSON call, this method will throw an UnsupportedOperationException

Returns:
A browser object for this user
Throws:
java.lang.UnsupportedOperationException - If this is part of a JSON call

getCurrentPage

java.lang.String getCurrentPage()
                                throws java.lang.UnsupportedOperationException
Returns the partial-URL of the page from which the current thread originated. This string starts from (and includes) the application's context path, and therefore excludes the scheme, host, and port of the URL. If the URL has a query string (starting with and including a '?' character) and/or an in-page location (starting with and including a '#' character), these portions will be excluded. If the URL has a session identifier, i.e. via an application server's URL-rewriting behavior, this may not necessarily be excluded. e.g. Tomcat's default is to use ";jsessionid=123...". NOTE: this means that DWR will consider a session-appended URL to be distinct from a non-session-appended URL.

Throws:
java.lang.UnsupportedOperationException - If this is part of a JSON call
See Also:
for details on how pages are converted from external form to this form.

getSession

javax.servlet.http.HttpSession getSession()
Returns the current session associated with this request, or if the request does not have a session, creates one.

Returns:
Returns the http session.
See Also:
HttpServletRequest.getSession()

getSession

javax.servlet.http.HttpSession getSession(boolean create)
Returns the current HttpSession associated with this request or, if there is no current session and create is true, returns a new session. If create is false and the request has no valid HttpSession, this method returns null.

Parameters:
create - false to return null if there's no current session
Returns:
the session associated with this request
See Also:
HttpServletRequest.getSession(boolean)

getHttpServletRequest

javax.servlet.http.HttpServletRequest getHttpServletRequest()
Accessor for the http request information.

Returns:
Returns the request.

getHttpServletResponse

javax.servlet.http.HttpServletResponse getHttpServletResponse()
Accessor for the http response bean.

You can't use this request to directly reply to the response or to add headers or cookies.

Returns:
Returns the response.

forwardToString

java.lang.String forwardToString(java.lang.String url)
                                 throws javax.servlet.ServletException,
                                        java.io.IOException
Forward a request to a given URL and catch the data written to it. It is possible to distinguish requests that arrive normally and requests that come from a DWR forwardToString() by the presence of a request attribute. Before the request is forwarded, DWR will call:
 request.setAttribute(WebContext.ATTRIBUTE_DWR, Boolean.TRUE);
 

Parameters:
url - The URL to forward to
Returns:
The text that results from forwarding to the given URL
Throws:
java.io.IOException - if the target resource throws this exception
javax.servlet.ServletException - if the target resource throws this exception
java.lang.IllegalStateException - if the response was already committed

Copyright 2008