checkGetAllowed(batch);
checkNotCsrfAttack(request, batch);
// Check to see that the page and script session id are valid
String normalizedPage = pageNormalizer.normalizePage(batch.getPage());
RealWebContext webContext = (RealWebContext) WebContextFactory.get();
webContext.checkPageInformation(normalizedPage, batch.getScriptSessionId(), batch.getWindowName());
// We might need to complain that reverse ajax is not enabled.
if (!activeReverseAjaxEnabled)
{
log.error("Polling and Comet are disabled. To enable them set the init-param activeReverseAjaxEnabled to true. See http://getahead.org/dwr/server/servlet for more.");
String script = EnginePrivate.getRemotePollCometDisabledScript(batch.getBatchId());
sendErrorScript(response, batch.getInstanceId(), script);
return;
}
// A script conduit is some route from a ScriptSession back to the page
// that belongs to the session. There may be zero or many of these
// conduits (although if there are more than 2, something is strange)
// All scripts destined for a page go to a ScriptSession and then out
// via a ScriptConduit.
final RealScriptSession scriptSession = (RealScriptSession) webContext.getScriptSession();
// So we're going to go to sleep. How do we wake up?
Sleeper sleeper = containerAbstraction.createSleeper(request);
// Create a conduit depending on the type of request (from the URL)
final BaseScriptConduit conduit = createScriptConduit(sleeper, batch, response);
// There are various reasons why we want to wake up and carry on ...
final List<Alarm> alarms = new ArrayList<Alarm>();
// If the conduit has an error flushing data, it needs to give up
alarms.add(conduit);
// Use of comet depends on the type of browser and the number of current
// connections from this browser (detected by cookies)
boolean clientSupportsLongRequests = BrowserDetect.supportsComet(request);
boolean clientSupportsStreamingUpdates = (batch.getPartialResponse() != PartialResponse.NO);
boolean configurationSaysFullStreaming = streamingEnabled || (maxWaitAfterWrite == -1);
boolean canWeHaveFullStreaming = clientSupportsLongRequests && clientSupportsStreamingUpdates && configurationSaysFullStreaming;
// For early closing mode add an output listener to the script session that calls the
// "wake me" method on whatever is putting us to sleep - if the client
// does not support streaming or streaming has not been configured.
if (!canWeHaveFullStreaming) {
int earlyCloseTimeout = (maxWaitAfterWrite == -1) ? ProtocolConstants.DEFAULT_MAX_WAIT_AFTER_WRITE : maxWaitAfterWrite;
alarms.add(new OutputAlarm(sleeper, scriptSession, earlyCloseTimeout, executor));
}
if (clientSupportsLongRequests)
{
// Nasty 2 connection limit hack. How many times is this browser connected?
String httpSessionId = webContext.getSession(true).getId();
Collection<ScriptSession> sessions = scriptSessionManager.getScriptSessionsByHttpSessionId(httpSessionId);
int persistentConnections = 0;
for (ScriptSession session : sessions)
{
persistentConnections += ((RealScriptSession) session).countPersistentConnections();