use of javax.servlet.AsyncContext in project spring-security by spring-projects.
the class SecurityContextHolderAwareRequestFilterTests method startAsyncWithRequestResponseStart.
@Test
public void startAsyncWithRequestResponseStart() throws Exception {
ArgumentCaptor<Runnable> runnableCaptor = ArgumentCaptor.forClass(Runnable.class);
SecurityContext context = SecurityContextHolder.createEmptyContext();
TestingAuthenticationToken expectedAuth = new TestingAuthenticationToken("user", "password", "ROLE_USER");
context.setAuthentication(expectedAuth);
SecurityContextHolder.setContext(context);
AsyncContext asyncContext = mock(AsyncContext.class);
when(this.request.startAsync(this.request, this.response)).thenReturn(asyncContext);
Runnable runnable = new Runnable() {
@Override
public void run() {
}
};
wrappedRequest().startAsync(this.request, this.response).start(runnable);
verifyZeroInteractions(this.authenticationManager, this.logoutHandler);
verify(asyncContext).start(runnableCaptor.capture());
DelegatingSecurityContextRunnable wrappedRunnable = (DelegatingSecurityContextRunnable) runnableCaptor.getValue();
assertThat(WhiteboxImpl.getInternalState(wrappedRunnable, "delegateSecurityContext")).isEqualTo(context);
assertThat(WhiteboxImpl.getInternalState(wrappedRunnable, "delegate")).isEqualTo(runnable);
}
use of javax.servlet.AsyncContext in project atmosphere by Atmosphere.
the class Servlet30CometSupport method suspend.
/**
* Suspend the connection by invoking {@link AtmosphereRequestImpl#startAsync()}
*
* @param action The {@link org.atmosphere.runtime.Action}
* @param req the {@link AtmosphereRequest}
* @param res the {@link AtmosphereResponse}
* @throws java.io.IOException
* @throws javax.servlet.ServletException
*/
private void suspend(Action action, AtmosphereRequest req, AtmosphereResponse res) throws IOException, ServletException {
if (!req.isAsyncStarted() && !Utils.webSocketEnabled(req)) {
AsyncContext asyncContext = req.startAsync(req, res);
asyncContext.addListener(new CometListener(this, res.uuid()));
// Do nothing except setting the times out
if (action.timeout() != -1) {
asyncContext.setTimeout(action.timeout());
} else {
// Jetty 8 does something really weird if you set it to
// Long.MAX_VALUE, which is to resume automatically.
asyncContext.setTimeout(Integer.MAX_VALUE);
}
req.setAttribute(FrameworkConfig.ASYNC_CONTEXT, asyncContext);
}
}
use of javax.servlet.AsyncContext in project atmosphere by Atmosphere.
the class AtmosphereRequestImpl method startAsync.
@Override
public AsyncContext startAsync(ServletRequest request, ServletResponse response) {
AsyncContext ac;
if (AtmosphereResource.TRANSPORT.WEBSOCKET == resource().transport()) {
noopsAsyncContextStarted = true;
ac = new NoOpsAsyncContext(request, response);
} else {
ac = b.request.startAsync(request, response);
}
return isCompletionAware() ? new CompletionAwareAsyncContext(ac, (CompletionAware) resource().getResponse()) : ac;
}
use of javax.servlet.AsyncContext in project atmosphere by Atmosphere.
the class AtmosphereResourceTest method verifyTestCompletionAwareForGetAsync.
private void verifyTestCompletionAwareForGetAsync(boolean aware) throws IOException {
if (aware) {
framework.addInitParameter(ApplicationConfig.RESPONSE_COMPLETION_AWARE, "true");
}
AtmosphereRequest request = AtmosphereRequestImpl.newInstance();
AtmosphereResponseImpl response = mock(AtmosphereResponseImpl.class);
AtmosphereResourceImpl res = new AtmosphereResourceImpl();
res.initialize(framework.getAtmosphereConfig(), framework.getBroadcasterFactory().get(), request, response, null, null);
res.transport(AtmosphereResource.TRANSPORT.WEBSOCKET);
request.setAttribute(FrameworkConfig.ATMOSPHERE_RESOURCE, res);
AsyncContext ac = request.getAsyncContext();
verify(response, times(0)).onComplete();
ac.complete();
verify(response, times(aware ? 1 : 0)).onComplete();
}
use of javax.servlet.AsyncContext in project wildfly by wildfly.
the class AsyncServlet method service.
@Override
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
HttpSession session = request.getSession(true);
AtomicInteger value = (AtomicInteger) session.getAttribute(ATTRIBUTE);
if (value == null) {
value = new AtomicInteger(0);
session.setAttribute(ATTRIBUTE, value);
}
AsyncContext context = request.startAsync(request, response);
context.start(new AsyncTask(context));
}
Aggregations