org.directwebremoting.impl
Class DefaultWebContext

java.lang.Object
  extended by org.directwebremoting.impl.DefaultServerContext
      extended by org.directwebremoting.impl.DefaultWebContext
All Implemented Interfaces:
RealWebContext, ServerContext, WebContext

public class DefaultWebContext
extends DefaultServerContext
implements RealWebContext

A default implementation of WebContext.

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

Field Summary
 
Fields inherited from interface org.directwebremoting.WebContext
ATTRIBUTE_DWR
 
Method Summary
 void checkPageInformation(java.lang.String sentPage, java.lang.String sentScriptId, java.lang.String windowName)
          Fill in the page details from the servlet request.
 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.
 java.lang.String toString()
           
 
Methods inherited from class org.directwebremoting.impl.DefaultServerContext
equals, getAllScriptSessions, getContainer, getContextPath, getScriptSessionById, getScriptSessionsByPage, getServletConfig, getServletContext, getVersion, setContainer, setServletConfig, setServletContext
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.directwebremoting.ServerContext
getAllScriptSessions, getContainer, getContextPath, getScriptSessionById, getScriptSessionsByPage, getServletConfig, getServletContext, getVersion
 

Method Detail

checkPageInformation

public void checkPageInformation(java.lang.String sentPage,
                                 java.lang.String sentScriptId,
                                 java.lang.String windowName)
Description copied from interface: RealWebContext
Fill in the page details from the servlet request.

This method should be used by anything that parses a batch, and then allows either uses a WebContext or allows other things to use a WebContext.

Caution Following this call, the passed scriptSessionId may be wrong. scriptSessionIds can become invalid due to server re-start, a timeout, or a back-button.

It seems wrong to throw a security exception, because it could be totally innocent. So this method will create a new script session and insert a script into the script session so that the page becomes synced with the new ID at the earliest possible opportunity.

Specified by:
checkPageInformation in interface RealWebContext
Parameters:
sentPage - The URL of the current page
sentScriptId - The session id passed in by the browser
windowName - Reverse Ajax uses window.name to avoid 2 connection limit

getCurrentPage

public java.lang.String getCurrentPage()
Description copied from interface: WebContext
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.

Specified by:
getCurrentPage in interface WebContext
See Also:
for details on how pages are converted from external form to this form.

getScriptSession

public ScriptSession getScriptSession()
Description copied from interface: WebContext
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

Specified by:
getScriptSession in interface WebContext
Returns:
A browser object for this user

getSession

public javax.servlet.http.HttpSession getSession()
Description copied from interface: WebContext
Returns the current session associated with this request, or if the request does not have a session, creates one.

Specified by:
getSession in interface WebContext
Returns:
Returns the http session.
See Also:
HttpServletRequest.getSession()

getSession

public javax.servlet.http.HttpSession getSession(boolean create)
Description copied from interface: WebContext
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.

Specified by:
getSession in interface WebContext
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

public javax.servlet.http.HttpServletRequest getHttpServletRequest()
Description copied from interface: WebContext
Accessor for the http request information.

Specified by:
getHttpServletRequest in interface WebContext
Returns:
Returns the request.

getHttpServletResponse

public javax.servlet.http.HttpServletResponse getHttpServletResponse()
Description copied from interface: WebContext
Accessor for the http response bean.

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

Specified by:
getHttpServletResponse in interface WebContext
Returns:
Returns the response.

forwardToString

public java.lang.String forwardToString(java.lang.String url)
                                 throws javax.servlet.ServletException,
                                        java.io.IOException
Description copied from interface: WebContext
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);
 

Specified by:
forwardToString in interface WebContext
Parameters:
url - The URL to forward to
Returns:
The text that results from forwarding to the given URL
Throws:
javax.servlet.ServletException - if the target resource throws this exception
java.io.IOException - if the target resource throws this exception

toString

public java.lang.String toString()
Overrides:
toString in class DefaultServerContext

Copyright 2008