use of jakarta.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.cpr.Action}
* @param req the {@link AtmosphereRequest}
* @param res the {@link AtmosphereResponse}
*/
private void suspend(Action action, AtmosphereRequest req, AtmosphereResponse res) {
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 jakarta.servlet.AsyncContext in project atmosphere by Atmosphere.
the class AtmosphereRequestImpl method startAsync.
@Override
public AsyncContext startAsync() {
AsyncContext ac;
if (AtmosphereResource.TRANSPORT.WEBSOCKET == resource().transport()) {
noopsAsyncContextStarted = true;
ac = new NoOpsAsyncContext(getRequest(), resource().getResponse().getResponse());
} else {
ac = b.request.startAsync();
}
return isCompletionAware() ? new CompletionAwareAsyncContext(ac, (CompletionAware) resource().getResponse()) : ac;
}
use of jakarta.servlet.AsyncContext in project atmosphere by Atmosphere.
the class AtmosphereRequestImpl method getAsyncContext.
@Override
public AsyncContext getAsyncContext() {
AsyncContext ac;
if (AtmosphereResource.TRANSPORT.WEBSOCKET == resource().transport()) {
noopsAsyncContextStarted = true;
ac = new NoOpsAsyncContext(getRequest(), resource().getResponse().getResponse());
} else {
ac = b.request.getAsyncContext();
}
return isCompletionAware() ? new CompletionAwareAsyncContext(ac, (CompletionAware) resource().getResponse()) : ac;
}
use of jakarta.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);
given(this.request.startAsync(this.request, this.response)).willReturn(asyncContext);
Runnable runnable = () -> {
};
wrappedRequest().startAsync(this.request, this.response).start(runnable);
verifyZeroInteractions(this.authenticationManager, this.logoutHandler);
verify(asyncContext).start(runnableCaptor.capture());
DelegatingSecurityContextRunnable wrappedRunnable = (DelegatingSecurityContextRunnable) runnableCaptor.getValue();
assertThat(ReflectionTestUtils.getField(wrappedRunnable, "delegateSecurityContext")).isEqualTo(context);
assertThat(ReflectionTestUtils.getField(wrappedRunnable, "delegate"));
}
use of jakarta.servlet.AsyncContext in project spring-framework by spring-projects.
the class WebLogicRequestUpgradeStrategy method handleSuccess.
@Override
protected void handleSuccess(HttpServletRequest request, HttpServletResponse response, UpgradeInfo upgradeInfo, TyrusUpgradeResponse upgradeResponse) throws IOException, ServletException {
response.setStatus(upgradeResponse.getStatus());
upgradeResponse.getHeaders().forEach((key, value) -> response.addHeader(key, Utils.getHeaderFromList(value)));
AsyncContext asyncContext = request.startAsync();
asyncContext.setTimeout(-1L);
Object nativeRequest = getNativeRequest(request);
BeanWrapper beanWrapper = new BeanWrapperImpl(nativeRequest);
Object httpSocket = beanWrapper.getPropertyValue("connection.connectionHandler.rawConnection");
Object webSocket = webSocketHelper.newInstance(request, httpSocket);
webSocketHelper.upgrade(webSocket, httpSocket, request.getServletContext());
response.flushBuffer();
boolean isProtected = request.getUserPrincipal() != null;
Writer servletWriter = servletWriterHelper.newInstance(webSocket, isProtected);
Connection connection = upgradeInfo.createConnection(servletWriter, noOpCloseListener);
new BeanWrapperImpl(webSocket).setPropertyValue("connection", connection);
new BeanWrapperImpl(servletWriter).setPropertyValue("connection", connection);
webSocketHelper.registerForReadEvent(webSocket);
}
Aggregations