org.directwebremoting.impl
Class DefaultWebContext

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

public class DefaultWebContext
extends DefaultServerContext
implements WebContext

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
 
Constructor Summary
DefaultWebContext(HttpServletRequest request, HttpServletResponse response, ServletConfig config, ServletContext context, Container container)
          Create a new DefaultWebContext
 
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()
          What is the URL of the current page.
 HttpServletRequest getHttpServletRequest()
          Accessor for the http request information.
 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.
 HttpSession getSession()
          Returns the current session associated with this request, or if the request does not have a session, creates one.
 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 getVersion()
          Fish the version number out of the dwr.properties file.
 void setCurrentPageInformation(java.lang.String page, java.lang.String scriptSessionId)
          For system use only: This method allows the system to fill in the session id and page id when they are discovered.
 
Methods inherited from class org.directwebremoting.impl.DefaultServerContext
getAllScriptSessions, getContainer, getConverterManager, getScriptSessionManager, getScriptSessionsByPage, getServletConfig, getServletContext
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.directwebremoting.ServerContext
getAllScriptSessions, getContainer, getScriptSessionsByPage, getServletConfig, getServletContext
 

Constructor Detail

DefaultWebContext

public DefaultWebContext(HttpServletRequest request,
                         HttpServletResponse response,
                         ServletConfig config,
                         ServletContext context,
                         Container container)
Create a new DefaultWebContext

Parameters:
request - The incoming http request
response - The outgoing http reply
config - The servlet configuration
context - The servlet context
container - The IoC container
See Also:
WebContextFactory.WebContextBuilder.set(HttpServletRequest, HttpServletResponse, ServletConfig, ServletContext, Container)
Method Detail

setCurrentPageInformation

public void setCurrentPageInformation(java.lang.String page,
                                      java.lang.String scriptSessionId)
Description copied from interface: WebContext
For system use only: This method allows the system to fill in the session id and page id when they are discovered.

Specified by:
setCurrentPageInformation in interface WebContext
Parameters:
page - The URL of the current page
scriptSessionId - The session id passed in by the browser

getCurrentPage

public java.lang.String getCurrentPage()
Description copied from interface: WebContext
What is the URL of the current page. This includes 'http://', up to (but not including) '?' or '#'

Specified by:
getCurrentPage in interface WebContext
Returns:
The URL of the current page

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.

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

getSession

public 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 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 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 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 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:
ServletException - if the target resource throws this exception
java.io.IOException - if the target resource throws this exception

getVersion

public java.lang.String getVersion()
Description copied from interface: ServerContext
Fish the version number out of the dwr.properties file.

Specified by:
getVersion in interface ServerContext
Overrides:
getVersion in class DefaultServerContext
Returns:
The current version number.