Search in sources :

Example 1 with StandardServletAsyncWebRequest

use of org.springframework.web.context.request.async.StandardServletAsyncWebRequest in project spring-framework by spring-projects.

the class ReactiveTypeHandlerTests method resetRequest.

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);
}
Also used : StandardServletAsyncWebRequest(org.springframework.web.context.request.async.StandardServletAsyncWebRequest) MockHttpServletRequest(org.springframework.web.testfixture.servlet.MockHttpServletRequest) AsyncWebRequest(org.springframework.web.context.request.async.AsyncWebRequest) StandardServletAsyncWebRequest(org.springframework.web.context.request.async.StandardServletAsyncWebRequest) ServletWebRequest(org.springframework.web.context.request.ServletWebRequest) MockHttpServletResponse(org.springframework.web.testfixture.servlet.MockHttpServletResponse)

Example 2 with StandardServletAsyncWebRequest

use of org.springframework.web.context.request.async.StandardServletAsyncWebRequest in project spring-framework by spring-projects.

the class ResponseBodyEmitterReturnValueHandlerTests method setup.

@BeforeEach
public void setup() throws Exception {
    List<HttpMessageConverter<?>> converters = Collections.singletonList(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);
}
Also used : StandardServletAsyncWebRequest(org.springframework.web.context.request.async.StandardServletAsyncWebRequest) MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) MockHttpServletRequest(org.springframework.web.testfixture.servlet.MockHttpServletRequest) MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) HttpMessageConverter(org.springframework.http.converter.HttpMessageConverter) AsyncWebRequest(org.springframework.web.context.request.async.AsyncWebRequest) StandardServletAsyncWebRequest(org.springframework.web.context.request.async.StandardServletAsyncWebRequest) ServletWebRequest(org.springframework.web.context.request.ServletWebRequest) MockHttpServletResponse(org.springframework.web.testfixture.servlet.MockHttpServletResponse) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with StandardServletAsyncWebRequest

use of org.springframework.web.context.request.async.StandardServletAsyncWebRequest in project spring-framework by spring-projects.

the class OpenEntityManagerInViewTests method testOpenEntityManagerInViewInterceptorAsyncTimeoutScenario.

@Test
public void testOpenEntityManagerInViewInterceptorAsyncTimeoutScenario() throws Exception {
    // Initial request thread
    OpenEntityManagerInViewInterceptor interceptor = new OpenEntityManagerInViewInterceptor();
    interceptor.setEntityManagerFactory(factory);
    given(this.factory.createEntityManager()).willReturn(this.manager);
    interceptor.preHandle(this.webRequest);
    assertThat(TransactionSynchronizationManager.hasResource(this.factory)).isTrue();
    AsyncWebRequest asyncWebRequest = new StandardServletAsyncWebRequest(this.request, this.response);
    WebAsyncManager asyncManager = WebAsyncUtils.getAsyncManager(this.request);
    asyncManager.setTaskExecutor(this.taskExecutor);
    asyncManager.setAsyncWebRequest(asyncWebRequest);
    asyncManager.startCallableProcessing((Callable<String>) () -> "anything");
    this.taskExecutor.await();
    assertThat(asyncManager.getConcurrentResult()).as("Concurrent result ").isEqualTo("anything");
    interceptor.afterConcurrentHandlingStarted(this.webRequest);
    assertThat(TransactionSynchronizationManager.hasResource(this.factory)).isFalse();
    // Async request timeout
    given(this.manager.isOpen()).willReturn(true);
    MockAsyncContext asyncContext = (MockAsyncContext) this.request.getAsyncContext();
    for (AsyncListener listener : asyncContext.getListeners()) {
        listener.onTimeout(new AsyncEvent(asyncContext));
    }
    for (AsyncListener listener : asyncContext.getListeners()) {
        listener.onComplete(new AsyncEvent(asyncContext));
    }
    verify(this.manager).close();
}
Also used : WebAsyncManager(org.springframework.web.context.request.async.WebAsyncManager) StandardServletAsyncWebRequest(org.springframework.web.context.request.async.StandardServletAsyncWebRequest) AsyncListener(jakarta.servlet.AsyncListener) MockAsyncContext(org.springframework.web.testfixture.servlet.MockAsyncContext) AsyncWebRequest(org.springframework.web.context.request.async.AsyncWebRequest) StandardServletAsyncWebRequest(org.springframework.web.context.request.async.StandardServletAsyncWebRequest) AsyncEvent(jakarta.servlet.AsyncEvent) Test(org.junit.jupiter.api.Test)

Example 4 with StandardServletAsyncWebRequest

use of org.springframework.web.context.request.async.StandardServletAsyncWebRequest in project spring-boot by spring-projects.

the class ErrorPageFilterTests method setUpAsyncDispatch.

private void setUpAsyncDispatch() throws Exception {
    this.request.setAsyncSupported(true);
    this.request.setAsyncStarted(true);
    DeferredResult<String> result = new DeferredResult<>();
    WebAsyncManager asyncManager = WebAsyncUtils.getAsyncManager(this.request);
    asyncManager.setAsyncWebRequest(new StandardServletAsyncWebRequest(this.request, this.response));
    asyncManager.startDeferredResultProcessing(result);
}
Also used : WebAsyncManager(org.springframework.web.context.request.async.WebAsyncManager) StandardServletAsyncWebRequest(org.springframework.web.context.request.async.StandardServletAsyncWebRequest) DeferredResult(org.springframework.web.context.request.async.DeferredResult)

Example 5 with StandardServletAsyncWebRequest

use of org.springframework.web.context.request.async.StandardServletAsyncWebRequest in project spring-framework by spring-projects.

the class DeferredResultReturnValueHandlerTests method setup.

@BeforeEach
public void setup() throws Exception {
    this.handler = new DeferredResultMethodReturnValueHandler();
    this.request = new MockHttpServletRequest();
    MockHttpServletResponse response = new MockHttpServletResponse();
    this.webRequest = new ServletWebRequest(this.request, response);
    AsyncWebRequest asyncWebRequest = new StandardServletAsyncWebRequest(this.request, response);
    WebAsyncUtils.getAsyncManager(this.webRequest).setAsyncWebRequest(asyncWebRequest);
    this.request.setAsyncSupported(true);
}
Also used : StandardServletAsyncWebRequest(org.springframework.web.context.request.async.StandardServletAsyncWebRequest) MockHttpServletRequest(org.springframework.web.testfixture.servlet.MockHttpServletRequest) AsyncWebRequest(org.springframework.web.context.request.async.AsyncWebRequest) StandardServletAsyncWebRequest(org.springframework.web.context.request.async.StandardServletAsyncWebRequest) ServletWebRequest(org.springframework.web.context.request.ServletWebRequest) MockHttpServletResponse(org.springframework.web.testfixture.servlet.MockHttpServletResponse) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

StandardServletAsyncWebRequest (org.springframework.web.context.request.async.StandardServletAsyncWebRequest)8 AsyncWebRequest (org.springframework.web.context.request.async.AsyncWebRequest)7 ServletWebRequest (org.springframework.web.context.request.ServletWebRequest)5 WebAsyncManager (org.springframework.web.context.request.async.WebAsyncManager)4 MockHttpServletRequest (org.springframework.web.testfixture.servlet.MockHttpServletRequest)4 MockHttpServletResponse (org.springframework.web.testfixture.servlet.MockHttpServletResponse)4 BeforeEach (org.junit.jupiter.api.BeforeEach)3 Test (org.junit.jupiter.api.Test)3 AsyncEvent (jakarta.servlet.AsyncEvent)2 AsyncListener (jakarta.servlet.AsyncListener)2 MockAsyncContext (org.springframework.web.testfixture.servlet.MockAsyncContext)2 HttpMessageConverter (org.springframework.http.converter.HttpMessageConverter)1 MappingJackson2HttpMessageConverter (org.springframework.http.converter.json.MappingJackson2HttpMessageConverter)1 DeferredResult (org.springframework.web.context.request.async.DeferredResult)1 ModelAndViewContainer (org.springframework.web.method.support.ModelAndViewContainer)1