List of usage examples for javax.servlet ServletRequest startAsync
public AsyncContext startAsync() throws IllegalStateException;
From source file:org.springframework.http.server.reactive.ServletHttpHandlerAdapter.java
@Override public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException { if (DispatcherType.ASYNC.equals(request.getDispatcherType())) { Throwable ex = (Throwable) request.getAttribute(WRITE_ERROR_ATTRIBUTE_NAME); throw new ServletException("Write publisher error", ex); }//from w w w .java2s. c o m // Start async before Read/WriteListener registration AsyncContext asyncContext = request.startAsync(); asyncContext.setTimeout(-1); ServerHttpRequest httpRequest = createRequest(((HttpServletRequest) request), asyncContext); ServerHttpResponse httpResponse = createResponse(((HttpServletResponse) response), asyncContext); if (HttpMethod.HEAD.equals(httpRequest.getMethod())) { httpResponse = new HttpHeadResponseDecorator(httpResponse); } AtomicBoolean isCompleted = new AtomicBoolean(); HandlerResultAsyncListener listener = new HandlerResultAsyncListener(isCompleted); asyncContext.addListener(listener); HandlerResultSubscriber subscriber = new HandlerResultSubscriber(asyncContext, isCompleted); this.httpHandler.handle(httpRequest, httpResponse).subscribe(subscriber); }