org.directwebremoting.dwrp
Class PollHandler

java.lang.Object
  extended by org.directwebremoting.dwrp.PollHandler
All Implemented Interfaces:
Handler
Direct Known Subclasses:
HtmlPollHandler, PlainPollHandler

public class PollHandler
extends java.lang.Object
implements Handler

A Marshaller that output plain Javascript. This marshaller can be tweaked to output Javascript in an HTML context. This class works in concert with CallScriptConduit, they should be considered closely related and it is important to understand what one does while editing the other.

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

Field Summary
protected  boolean activeReverseAjaxEnabled
          Are we doing full reverse ajax
protected  boolean allowGetForSafariButMakeForgeryEasier
          By default we disable GET, but this hinders old Safaris
static java.lang.String ATTRIBUTE_CALL_ID
          How we stash away the results of the request parse
static java.lang.String ATTRIBUTE_LONGPOLL_SESSION_ID
          We remember people that are in a long poll so we can kick them out
static java.lang.String ATTRIBUTE_PAGE
          How we stash away the results of the request parse
static java.lang.String ATTRIBUTE_PARAMETERS
          How we stash away the results of the request parse
static java.lang.String ATTRIBUTE_PARTIAL_RESPONSE
          How we stash away the results of the request parse
static java.lang.String ATTRIBUTE_SESSION_ID
          How we stash away the results of the request parse
protected  ConverterManager converterManager
          How we convert parameters
protected  int maxWaitAfterWrite
          Sometimes with proxies, you need to close the stream all the time to make the flush work.
protected  PageNormalizer pageNormalizer
          How we turn pages into the canonical form.
protected static int PARTIAL_RESPONSE_FLUSH
          The client can only handle partial responses with a 4k data post (can be whitespace) - we're talking IE here.
protected static int PARTIAL_RESPONSE_NO
          The client can not handle partial responses
protected static int PARTIAL_RESPONSE_YES
          The client can handle partial responses
protected  boolean plain
          Are we using plain javascript or html wrapped javascript
protected  ScriptSessionManager scriptSessionManager
          The owner of script sessions
protected  ServerLoadMonitor serverLoadMonitor
          We need to tell the system that we are waiting so it can load adjust
 
Constructor Summary
PollHandler(boolean plain)
           
 
Method Summary
protected  java.lang.String extractParameter(javax.servlet.http.HttpServletRequest request, java.util.Map parameters, java.lang.String attrName, java.lang.String paramName)
          Extract a parameter and ensure it is in the request.
 void handle(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Handle a URL request that has been mapped to this Handler
protected  void notifyThreadsFromSameBrowser(javax.servlet.http.HttpServletRequest request, java.lang.String scriptId)
          Make other threads from the same browser stop waiting and continue
protected  void sendErrorScript(javax.servlet.http.HttpServletResponse response, java.lang.String script)
          Send a script to the browser and wrap it in the required prefixes etc.
 void setActiveReverseAjaxEnabled(boolean activeReverseAjaxEnabled)
          Are we doing full reverse ajax
 void setAllowGetForSafariButMakeForgeryEasier(boolean allowGetForSafariButMakeForgeryEasier)
           
 void setConverterManager(ConverterManager converterManager)
          Accessor for the DefaultCreatorManager that we configure
 void setMaxWaitAfterWrite(int maxWaitAfterWrite)
          Sometimes with proxies, you need to close the stream all the time to make the flush work.
 void setPageNormalizer(PageNormalizer pageNormalizer)
          Accessor for the PageNormalizer.
 void setPollAndCometEnabled(boolean pollAndCometEnabled)
          Deprecated. Use setActiveReverseAjaxEnabled(boolean)
 void setScriptSessionManager(ScriptSessionManager scriptSessionManager)
           
 void setServerLoadMonitor(ServerLoadMonitor serverLoadMonitor)
          Accessor for the server load monitor
protected  boolean sleepWithContinuation(RealScriptSession scriptSession, Continuation continuation, long preStreamWaitTime)
          Use a ResumeContinuationScriptConduit to wait
protected  boolean streamWait(javax.servlet.http.HttpServletRequest request, ScriptConduit conduit, RealScriptSession scriptSession, long wait)
          Perform a wait.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

activeReverseAjaxEnabled

protected boolean activeReverseAjaxEnabled
Are we doing full reverse ajax


allowGetForSafariButMakeForgeryEasier

protected boolean allowGetForSafariButMakeForgeryEasier
By default we disable GET, but this hinders old Safaris


maxWaitAfterWrite

protected int maxWaitAfterWrite
Sometimes with proxies, you need to close the stream all the time to make the flush work. A value of -1 indicated that we do not do early closing after writes.


plain

protected boolean plain
Are we using plain javascript or html wrapped javascript


pageNormalizer

protected PageNormalizer pageNormalizer
How we turn pages into the canonical form.


serverLoadMonitor

protected ServerLoadMonitor serverLoadMonitor
We need to tell the system that we are waiting so it can load adjust


converterManager

protected ConverterManager converterManager
How we convert parameters


scriptSessionManager

protected ScriptSessionManager scriptSessionManager
The owner of script sessions


ATTRIBUTE_PARAMETERS

public static final java.lang.String ATTRIBUTE_PARAMETERS
How we stash away the results of the request parse

See Also:
Constant Field Values

ATTRIBUTE_CALL_ID

public static final java.lang.String ATTRIBUTE_CALL_ID
How we stash away the results of the request parse

See Also:
Constant Field Values

ATTRIBUTE_SESSION_ID

public static final java.lang.String ATTRIBUTE_SESSION_ID
How we stash away the results of the request parse

See Also:
Constant Field Values

ATTRIBUTE_PAGE

public static final java.lang.String ATTRIBUTE_PAGE
How we stash away the results of the request parse

See Also:
Constant Field Values

ATTRIBUTE_PARTIAL_RESPONSE

public static final java.lang.String ATTRIBUTE_PARTIAL_RESPONSE
How we stash away the results of the request parse

See Also:
Constant Field Values

ATTRIBUTE_LONGPOLL_SESSION_ID

public static final java.lang.String ATTRIBUTE_LONGPOLL_SESSION_ID
We remember people that are in a long poll so we can kick them out

See Also:
Constant Field Values

PARTIAL_RESPONSE_NO

protected static final int PARTIAL_RESPONSE_NO
The client can not handle partial responses

See Also:
Constant Field Values

PARTIAL_RESPONSE_YES

protected static final int PARTIAL_RESPONSE_YES
The client can handle partial responses

See Also:
Constant Field Values

PARTIAL_RESPONSE_FLUSH

protected static final int PARTIAL_RESPONSE_FLUSH
The client can only handle partial responses with a 4k data post (can be whitespace) - we're talking IE here.

See Also:
Constant Field Values
Constructor Detail

PollHandler

public PollHandler(boolean plain)
Parameters:
plain - Are we using plain javascript or html wrapped javascript
Method Detail

handle

public void handle(javax.servlet.http.HttpServletRequest request,
                   javax.servlet.http.HttpServletResponse response)
            throws java.io.IOException
Description copied from interface: Handler
Handle a URL request that has been mapped to this Handler

Specified by:
handle in interface Handler
Parameters:
request - The HTTP request data
response - Where we write the HTTP response data
Throws:
java.io.IOException - If the write process fails

streamWait

protected boolean streamWait(javax.servlet.http.HttpServletRequest request,
                             ScriptConduit conduit,
                             RealScriptSession scriptSession,
                             long wait)
                      throws java.io.IOException
Perform a wait.

Parameters:
request - The HTTP request, needed to start a Jetty continuation
conduit - A conduit if there is an open stream or null if not
scriptSession - The script that we lock against
wait - How long do we wait for?
Returns:
True if the wait did not end in a shutdown request
Throws:
java.io.IOException - If an IO error occurs

sleepWithContinuation

protected boolean sleepWithContinuation(RealScriptSession scriptSession,
                                        Continuation continuation,
                                        long preStreamWaitTime)
Use a ResumeContinuationScriptConduit to wait

Parameters:
scriptSession - The session that we add the conduit to
continuation - The Jetty continuation object
preStreamWaitTime - The length of time to wait
Returns:
True if the continuation wait worked

notifyThreadsFromSameBrowser

protected void notifyThreadsFromSameBrowser(javax.servlet.http.HttpServletRequest request,
                                            java.lang.String scriptId)
Make other threads from the same browser stop waiting and continue

Parameters:
request - The HTTP request
scriptId - The session id of the current page

extractParameter

protected java.lang.String extractParameter(javax.servlet.http.HttpServletRequest request,
                                            java.util.Map parameters,
                                            java.lang.String attrName,
                                            java.lang.String paramName)
Extract a parameter and ensure it is in the request. This is needed to cope with Jetty continuations that are not real continuations.

Parameters:
request - The HTTP request
parameters - The parameter list parsed out of the request
attrName - The name of the request attribute
paramName - The name of the parameter sent
Returns:
The found value

sendErrorScript

protected void sendErrorScript(javax.servlet.http.HttpServletResponse response,
                               java.lang.String script)
                        throws java.io.IOException
Send a script to the browser and wrap it in the required prefixes etc.

Parameters:
response - The http response to write to
script - The script to write
Throws:
java.io.IOException - if writing fails.

setConverterManager

public void setConverterManager(ConverterManager converterManager)
Accessor for the DefaultCreatorManager that we configure

Parameters:
converterManager - The new DefaultConverterManager

setServerLoadMonitor

public void setServerLoadMonitor(ServerLoadMonitor serverLoadMonitor)
Accessor for the server load monitor

Parameters:
serverLoadMonitor - the new server load monitor

setPageNormalizer

public void setPageNormalizer(PageNormalizer pageNormalizer)
Accessor for the PageNormalizer.

Parameters:
pageNormalizer - The new PageNormalizer

setScriptSessionManager

public void setScriptSessionManager(ScriptSessionManager scriptSessionManager)
Parameters:
scriptSessionManager - the scriptSessionManager to set

setPollAndCometEnabled

public void setPollAndCometEnabled(boolean pollAndCometEnabled)
Deprecated. Use setActiveReverseAjaxEnabled(boolean)

Use setActiveReverseAjaxEnabled(boolean)

Parameters:
pollAndCometEnabled - Are we doing full reverse ajax

setActiveReverseAjaxEnabled

public void setActiveReverseAjaxEnabled(boolean activeReverseAjaxEnabled)
Are we doing full reverse ajax

Parameters:
activeReverseAjaxEnabled - Are we doing full reverse ajax

setAllowGetForSafariButMakeForgeryEasier

public void setAllowGetForSafariButMakeForgeryEasier(boolean allowGetForSafariButMakeForgeryEasier)
Parameters:
allowGetForSafariButMakeForgeryEasier - Do we reduce security to help Safari

setMaxWaitAfterWrite

public void setMaxWaitAfterWrite(int maxWaitAfterWrite)
Sometimes with proxies, you need to close the stream all the time to make the flush work. A value of -1 indicated that we do not do early closing after writes.

Parameters:
maxWaitAfterWrite - the maxWaitAfterWrite to set


Copyright © 2007. All Rights Reserved.