BoshBackedSessionContext extends AbstractSessionContext implements StanzaWriter { private void requestExpired(final AsyncContext context) { final BoshRequest req = (BoshRequest) context.getRequest().getAttribute(BOSH_REQUEST_ATTRIBUTE); if (req == null) { LOGGER.warn("SID = " + getSessionId() + " - Continuation expired without having " + "an associated request!"); return; } LOGGER.debug("SID = " + getSessionId() + " - rid = {} - BOSH request expired", req.getRid()); while (!requestsWindow.isEmpty() && requestsWindow.firstRid() <= req.getRid()) { writeBoshResponse(BoshStanzaUtils.EMPTY_BOSH_RESPONSE); } } BoshBackedSessionContext(ServerRuntimeContext serverRuntimeContext, StanzaProcessor stanzaProcessor, BoshHandler boshHandler, InactivityChecker inactivityChecker); boolean isWatchedByInactivityChecker(); SessionStateHolder getStateHolder(); StanzaWriter getResponseWriter(); void setIsReopeningXMLStream(); boolean propagateSessionContext(); synchronized void write(Stanza stanza); void sendError(String condition); void close(); void switchToTLS(boolean delayed, boolean clientTls); void setContentType(String contentType); String getContentType(); int getMaxPause(); void setWait(int wait); int getWait(); void setHold(int hold); int getHold(); void setClientAcknowledgements(boolean value); boolean isClientAcknowledgements(); void setBoshVersion(String version); String getBoshVersion(); int getInactivity(); int getPolling(); int getRequests(); void insertRequest(final BoshRequest br); String logSentResponsesBuffer(); final static String HTTP_SESSION_ATTRIBUTE; final static String BOSH_REQUEST_ATTRIBUTE; final static String BOSH_RESPONSE_ATTRIBUTE; }
@Test public void testRequestExpired() throws IOException { Stanza emtpyStanza = BoshStanzaUtils.EMPTY_BOSH_RESPONSE; HttpServletRequest httpServletRequest = mocksControl.createMock(HttpServletRequest.class); AsyncContext asyncContext = mocksControl.createMock(AsyncContext.class); expect(httpServletRequest.startAsync()).andReturn(asyncContext).atLeastOnce(); expect(httpServletRequest.getAsyncContext()).andReturn(asyncContext).atLeastOnce(); asyncContext.setTimeout(anyLong()); httpServletRequest.setAttribute(eq(BOSH_REQUEST_ATTRIBUTE), EasyMock.<BoshRequest>notNull()); expect(asyncContext.getRequest()).andReturn(httpServletRequest).atLeastOnce(); asyncContext.dispatch(); expectLastCall().atLeastOnce(); Capture<AsyncListener> listenerCaptured = new Capture<AsyncListener>(); asyncContext.addListener(EasyMock.<AsyncListener> capture(listenerCaptured)); AsyncEvent asyncEvent = mocksControl.createMock(AsyncEvent.class); BoshRequest br = new BoshRequest(httpServletRequest, emtpyStanza, 1L); expect(httpServletRequest.getAttribute(BOSH_REQUEST_ATTRIBUTE)).andReturn(br); Capture<BoshResponse> responseCaptured = new Capture<BoshResponse>(); httpServletRequest.setAttribute(eq(BOSH_RESPONSE_ATTRIBUTE), EasyMock.<BoshResponse> capture(responseCaptured)); mocksControl.replay(); BoshBackedSessionContext boshBackedSessionContext = new BoshBackedSessionContext(serverRuntimeContext, stanzaProcessor, null, inactivityChecker); boshBackedSessionContext.insertRequest(br); listenerCaptured.getValue().onTimeout(asyncEvent); mocksControl.verify(); assertEquals(new Renderer(emtpyStanza).getComplete(), new String(responseCaptured.getValue().getContent())); assertEquals(BoshServlet.XML_CONTENT_TYPE, responseCaptured.getValue().getContentType()); }