org.directwebremoting
Interface ServerContext

All Known Subinterfaces:
RealWebContext, WebContext
All Known Implementing Classes:
DefaultServerContext, DefaultWebContext

public interface ServerContext

ServerContext is something of a misnomer - it refers to a running DwrServlet (or a similar concept when DWR is run inside Guice/Spring/etc). ServerContext is useful for threads that are NOT created by DWR to allow them to interact with the environment that the DWR instance knows about.

If you are running in a DWR thread then you are probably better off using WebContext in place of ServerContext.

From DWR 3, you are probably better off looking towards Browser, ScriptSessions or the various reverse ajax proxy APIs in order to interact with web-clients.

ServerContext is accessible from ServerContextFactory.get().

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

Method Summary
 java.util.Collection<ScriptSession> getAllScriptSessions()
          Deprecated. Use Browser.withAllSessions(Runnable) instead
 Container getContainer()
          Accessor for the IoC container.
 java.lang.String getContextPath()
          Returns the portion of the request URI that indicates the context of the request.
 ScriptSession getScriptSessionById(java.lang.String sessionId)
          Deprecated. Use Browser.withSession(String, Runnable) instead
 java.util.Collection<ScriptSession> getScriptSessionsByPage(java.lang.String url)
          Deprecated. Use Browser.withPage(String, Runnable) instead
 javax.servlet.ServletConfig getServletConfig()
          Accessor for the servlet config.
 javax.servlet.ServletContext getServletContext()
          Returns the ServletContext to which this session belongs.
 java.lang.String getVersion()
          Fish the version number out of the dwr.properties file.
 

Method Detail

getScriptSessionsByPage

@Deprecated
java.util.Collection<ScriptSession> getScriptSessionsByPage(java.lang.String url)
Deprecated. Use Browser.withPage(String, Runnable) instead

Get a list of all ScriptSessions on a given page. Note that the list of known sessions is continually changing so it is possible that the list will be out of date by the time it is used. For this reason you should check that getScriptSession(String id) returns something non null.

Parameters:
url - The URL including 'http://', up to (but not including) '?' or '#'
Returns:
A collection of all the ScriptSessions.

getScriptSessionById

@Deprecated
ScriptSession getScriptSessionById(java.lang.String sessionId)
Deprecated. Use Browser.withSession(String, Runnable) instead

You can request access to a specific ScriptSession if you know it's ID.

Take care with this method because it allows actions from one browser to affect another which could be a bad thing. It is certainly a VERY BAD idea to let session id's from one browser escape into another.

Consider that it is entirely possible that the ScriptSession may timeout while you are holding a reference to it.

Parameters:
sessionId - The script session ID to lookup
Returns:
The ScriptSession for the given ID, or null if it does not exist

getAllScriptSessions

@Deprecated
java.util.Collection<ScriptSession> getAllScriptSessions()
Deprecated. Use Browser.withAllSessions(Runnable) instead

Get a list of all the ScriptSessions known to this server at the given time. Note that the list of known sessions is continually changing so it is possible that the list will be out of date by the time it is used. For this reason you should check that getScriptSession(String id) returns something non null.

Returns:
A collection of all the ScriptSessions.

getServletConfig

javax.servlet.ServletConfig getServletConfig()
Accessor for the servlet config.

Returns:
Returns the config.

getServletContext

javax.servlet.ServletContext getServletContext()
Returns the ServletContext to which this session belongs.

Returns:
The servlet context information.

getContextPath

java.lang.String getContextPath()
Returns the portion of the request URI that indicates the context of the request.

Annoyingly you can't get to this from the ServletContext until servlet 2.5 you need to cache the value from a recent HttpServletRequest.

The context path always comes first in a request URI. The path starts with a "/" character but does not end with a "/" character. For servlets in the default (root) context, this method returns "". The container does not decode this string.

WARNING: This method may return null if DWR has not received any requests. If this method is called from outside of DWR, as the servlet environment is starting up you should check for a null reply and try again later.

Returns:
The portion of the request URI that indicates the context or null if DWR has not received and requests so far

getContainer

Container getContainer()
Accessor for the IoC container.

Returns:
The IoC container that created the interface implementations.

getVersion

java.lang.String getVersion()
Fish the version number out of the dwr.properties file.

Returns:
The current version number.

Copyright 2008