/** * Create an AsyncWebRequest instance. By default, an instance of * {@link StandardServletAsyncWebRequest} gets created. * @param request the current request * @param response the current response * @return an AsyncWebRequest instance (never {@code null}) */ public static AsyncWebRequest createAsyncWebRequest(HttpServletRequest request, HttpServletResponse response) { return new StandardServletAsyncWebRequest(request, response); }
@Override public void startAsync() { Assert.state(getRequest().isAsyncSupported(), "Async support must be enabled on a servlet and for all filters involved " + "in async request processing. This is done in Java code using the Servlet API " + "or by adding \"<async-supported>true</async-supported>\" to servlet and " + "filter declarations in web.xml."); Assert.state(!isAsyncComplete(), "Async processing has already completed"); if (isAsyncStarted()) { return; } this.asyncContext = getRequest().startAsync(getRequest(), getResponse()); this.asyncContext.addListener(this); if (this.timeout != null) { this.asyncContext.setTimeout(this.timeout); } }
@Test public void onCompletionHandlerAfterOnCompleteEvent() throws Exception { Runnable handler = mock(Runnable.class); this.asyncRequest.addCompletionHandler(handler); this.asyncRequest.startAsync(); this.asyncRequest.onComplete(new AsyncEvent(this.request.getAsyncContext())); verify(handler).run(); assertTrue(this.asyncRequest.isAsyncComplete()); } }
@Test public void isAsyncStarted() throws Exception { assertFalse(this.asyncRequest.isAsyncStarted()); this.asyncRequest.startAsync(); assertTrue(this.asyncRequest.isAsyncStarted()); }
@Before public void setup() { this.request = new MockHttpServletRequest(); this.request.setAsyncSupported(true); this.response = new MockHttpServletResponse(); this.asyncRequest = new StandardServletAsyncWebRequest(this.request, this.response); this.asyncRequest.setTimeout(44*1000L); }
/** * In Servlet 3 async processing, the timeout period begins after the * container processing thread has exited. */ @Override public void setTimeout(Long timeout) { Assert.state(!isAsyncStarted(), "Cannot change the timeout with concurrent handling in progress"); this.timeout = timeout; }
@Override public boolean isAsyncStarted() { return (this.asyncContext != null && getRequest().isAsyncStarted()); }
/** * In Servlet 3 async processing, the timeout period begins after the * container processing thread has exited. */ @Override public void setTimeout(Long timeout) { Assert.state(!isAsyncStarted(), "Cannot change the timeout with concurrent handling in progress"); this.timeout = timeout; }
@Override public boolean isAsyncStarted() { return (this.asyncContext != null && getRequest().isAsyncStarted()); }
@Override public void startAsync() { Assert.state(getRequest().isAsyncSupported(), "Async support must be enabled on a servlet and for all filters involved " + "in async request processing. This is done in Java code using the Servlet API " + "or by adding \"<async-supported>true</async-supported>\" to servlet and " + "filter declarations in web.xml."); Assert.state(!isAsyncComplete(), "Async processing has already completed"); if (isAsyncStarted()) { return; } this.asyncContext = getRequest().startAsync(getRequest(), getResponse()); this.asyncContext.addListener(this); if (this.timeout != null) { this.asyncContext.setTimeout(this.timeout); } }
/** * Create an AsyncWebRequest instance. By default, an instance of * {@link StandardServletAsyncWebRequest} gets created. * @param request the current request * @param response the current response * @return an AsyncWebRequest instance (never {@code null}) */ public static AsyncWebRequest createAsyncWebRequest(HttpServletRequest request, HttpServletResponse response) { return new StandardServletAsyncWebRequest(request, response); }
@Test public void onCompletionHandler() throws Exception { Runnable handler = mock(Runnable.class); this.asyncRequest.addCompletionHandler(handler); this.asyncRequest.startAsync(); this.asyncRequest.onComplete(new AsyncEvent(this.request.getAsyncContext())); verify(handler).run(); assertTrue(this.asyncRequest.isAsyncComplete()); }
/** * In Servlet 3 async processing, the timeout period begins after the * container processing thread has exited. */ @Override public void setTimeout(Long timeout) { Assert.state(!isAsyncStarted(), "Cannot change the timeout with concurrent handling in progress"); this.timeout = timeout; }
@Override public boolean isAsyncStarted() { return (this.asyncContext != null && getRequest().isAsyncStarted()); }
@Override public void startAsync() { Assert.state(getRequest().isAsyncSupported(), "Async support must be enabled on a servlet and for all filters involved " + "in async request processing. This is done in Java code using the Servlet API " + "or by adding \"<async-supported>true</async-supported>\" to servlet and " + "filter declarations in web.xml."); Assert.state(!isAsyncComplete(), "Async processing has already completed"); if (isAsyncStarted()) { return; } this.asyncContext = getRequest().startAsync(getRequest(), getResponse()); this.asyncContext.addListener(this); if (this.timeout != null) { this.asyncContext.setTimeout(this.timeout); } }
@Before public void setup() throws Exception { List<HttpMessageConverter<?>> converters = Arrays.asList( new StringHttpMessageConverter(), new MappingJackson2HttpMessageConverter()); this.handler = new ResponseBodyEmitterReturnValueHandler(converters); this.request = new MockHttpServletRequest(); this.response = new MockHttpServletResponse(); this.webRequest = new ServletWebRequest(this.request, this.response); AsyncWebRequest asyncWebRequest = new StandardServletAsyncWebRequest(this.request, this.response); WebAsyncUtils.getAsyncManager(this.webRequest).setAsyncWebRequest(asyncWebRequest); this.request.setAsyncSupported(true); }
/** * In Servlet 3 async processing, the timeout period begins after the * container processing thread has exited. */ @Override public void setTimeout(Long timeout) { Assert.state(!isAsyncStarted(), "Cannot change the timeout with concurrent handling in progress"); this.timeout = timeout; }
@Override public boolean isAsyncStarted() { return (this.asyncContext != null && getRequest().isAsyncStarted()); }
@Override public void startAsync() { Assert.state(getRequest().isAsyncSupported(), "Async support must be enabled on a servlet and for all filters involved " + "in async request processing. This is done in Java code using the Servlet API " + "or by adding \"<async-supported>true</async-supported>\" to servlet and " + "filter declarations in web.xml."); Assert.state(!isAsyncComplete(), "Async processing has already completed"); if (isAsyncStarted()) { return; } this.asyncContext = getRequest().startAsync(getRequest(), getResponse()); this.asyncContext.addListener(this); if (this.timeout != null) { this.asyncContext.setTimeout(this.timeout); } }
private void resetRequest() { this.servletRequest = new MockHttpServletRequest(); this.servletResponse = new MockHttpServletResponse(); this.webRequest = new ServletWebRequest(this.servletRequest, this.servletResponse); AsyncWebRequest webRequest = new StandardServletAsyncWebRequest(this.servletRequest, this.servletResponse); WebAsyncUtils.getAsyncManager(this.webRequest).setAsyncWebRequest(webRequest); this.servletRequest.setAsyncSupported(true); }