Search in sources :

Example 1 with CallableProcessingInterceptor

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

the class WebAsyncManagerTimeoutTests method startCallableProcessingTimeoutAndResumeThroughInterceptor.

@Test
public void startCallableProcessingTimeoutAndResumeThroughInterceptor() throws Exception {
    StubCallable callable = new StubCallable();
    CallableProcessingInterceptor interceptor = mock(CallableProcessingInterceptor.class);
    given(interceptor.handleTimeout(this.asyncWebRequest, callable)).willReturn(22);
    this.asyncManager.registerCallableInterceptor("timeoutInterceptor", interceptor);
    this.asyncManager.startCallableProcessing(callable);
    this.asyncWebRequest.onTimeout(ASYNC_EVENT);
    assertTrue(this.asyncManager.hasConcurrentResult());
    assertEquals(22, this.asyncManager.getConcurrentResult());
    assertEquals("/test", ((MockAsyncContext) this.servletRequest.getAsyncContext()).getDispatchedPath());
    verify(interceptor).beforeConcurrentHandling(this.asyncWebRequest, callable);
}
Also used : CallableProcessingInterceptor(org.springframework.web.context.request.async.CallableProcessingInterceptor) Test(org.junit.Test)

Example 2 with CallableProcessingInterceptor

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

the class WebAsyncManagerTimeoutTests method startCallableProcessingAfterTimeoutException.

@Test
public void startCallableProcessingAfterTimeoutException() throws Exception {
    StubCallable callable = new StubCallable();
    Exception exception = new Exception();
    CallableProcessingInterceptor interceptor = mock(CallableProcessingInterceptor.class);
    given(interceptor.handleTimeout(this.asyncWebRequest, callable)).willThrow(exception);
    this.asyncManager.registerCallableInterceptor("timeoutInterceptor", interceptor);
    this.asyncManager.startCallableProcessing(callable);
    this.asyncWebRequest.onTimeout(ASYNC_EVENT);
    assertTrue(this.asyncManager.hasConcurrentResult());
    assertEquals(exception, this.asyncManager.getConcurrentResult());
    assertEquals("/test", ((MockAsyncContext) this.servletRequest.getAsyncContext()).getDispatchedPath());
    verify(interceptor).beforeConcurrentHandling(this.asyncWebRequest, callable);
}
Also used : CallableProcessingInterceptor(org.springframework.web.context.request.async.CallableProcessingInterceptor) Test(org.junit.Test)

Example 3 with CallableProcessingInterceptor

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

the class MvcNamespaceTests method testAsyncSupportOptions.

@Test
public void testAsyncSupportOptions() throws Exception {
    loadBeanDefinitions("mvc-config-async-support.xml", 15);
    RequestMappingHandlerAdapter adapter = appContext.getBean(RequestMappingHandlerAdapter.class);
    assertNotNull(adapter);
    DirectFieldAccessor fieldAccessor = new DirectFieldAccessor(adapter);
    assertEquals(ConcurrentTaskExecutor.class, fieldAccessor.getPropertyValue("taskExecutor").getClass());
    assertEquals(2500L, fieldAccessor.getPropertyValue("asyncRequestTimeout"));
    CallableProcessingInterceptor[] callableInterceptors = (CallableProcessingInterceptor[]) fieldAccessor.getPropertyValue("callableInterceptors");
    assertEquals(1, callableInterceptors.length);
    DeferredResultProcessingInterceptor[] deferredResultInterceptors = (DeferredResultProcessingInterceptor[]) fieldAccessor.getPropertyValue("deferredResultInterceptors");
    assertEquals(1, deferredResultInterceptors.length);
}
Also used : DeferredResultProcessingInterceptor(org.springframework.web.context.request.async.DeferredResultProcessingInterceptor) CallableProcessingInterceptor(org.springframework.web.context.request.async.CallableProcessingInterceptor) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) RequestMappingHandlerAdapter(org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter) Test(org.junit.Test)

Example 4 with CallableProcessingInterceptor

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

the class WebAsyncManagerTimeoutTests method startCallableProcessingTimeoutAndComplete.

@Test
public void startCallableProcessingTimeoutAndComplete() throws Exception {
    StubCallable callable = new StubCallable();
    CallableProcessingInterceptor interceptor = mock(CallableProcessingInterceptor.class);
    given(interceptor.handleTimeout(this.asyncWebRequest, callable)).willReturn(RESULT_NONE);
    this.asyncManager.registerCallableInterceptor("interceptor", interceptor);
    this.asyncManager.startCallableProcessing(callable);
    this.asyncWebRequest.onTimeout(ASYNC_EVENT);
    this.asyncWebRequest.onComplete(ASYNC_EVENT);
    assertTrue(this.asyncManager.hasConcurrentResult());
    assertEquals(AsyncRequestTimeoutException.class, this.asyncManager.getConcurrentResult().getClass());
    verify(interceptor).beforeConcurrentHandling(this.asyncWebRequest, callable);
    verify(interceptor).afterCompletion(this.asyncWebRequest, callable);
}
Also used : CallableProcessingInterceptor(org.springframework.web.context.request.async.CallableProcessingInterceptor) Test(org.junit.Test)

Example 5 with CallableProcessingInterceptor

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

the class WebMvcConfigurationSupportExtensionTests method requestMappingHandlerAdapter.

@SuppressWarnings("unchecked")
@Test
public void requestMappingHandlerAdapter() throws Exception {
    RequestMappingHandlerAdapter adapter = this.config.requestMappingHandlerAdapter();
    // ConversionService
    String actual = this.config.mvcConversionService().convert(new TestBean(), String.class);
    assertEquals("converted", actual);
    // Message converters
    List<HttpMessageConverter<?>> converters = adapter.getMessageConverters();
    assertEquals(2, converters.size());
    assertEquals(StringHttpMessageConverter.class, converters.get(0).getClass());
    assertEquals(MappingJackson2HttpMessageConverter.class, converters.get(1).getClass());
    ObjectMapper objectMapper = ((MappingJackson2HttpMessageConverter) converters.get(1)).getObjectMapper();
    assertFalse(objectMapper.getDeserializationConfig().isEnabled(DEFAULT_VIEW_INCLUSION));
    assertFalse(objectMapper.getSerializationConfig().isEnabled(DEFAULT_VIEW_INCLUSION));
    assertFalse(objectMapper.getDeserializationConfig().isEnabled(FAIL_ON_UNKNOWN_PROPERTIES));
    DirectFieldAccessor fieldAccessor = new DirectFieldAccessor(adapter);
    // Custom argument resolvers and return value handlers
    List<HandlerMethodArgumentResolver> argResolvers = (List<HandlerMethodArgumentResolver>) fieldAccessor.getPropertyValue("customArgumentResolvers");
    assertEquals(1, argResolvers.size());
    List<HandlerMethodReturnValueHandler> handlers = (List<HandlerMethodReturnValueHandler>) fieldAccessor.getPropertyValue("customReturnValueHandlers");
    assertEquals(1, handlers.size());
    // Async support options
    assertEquals(ConcurrentTaskExecutor.class, fieldAccessor.getPropertyValue("taskExecutor").getClass());
    assertEquals(2500L, fieldAccessor.getPropertyValue("asyncRequestTimeout"));
    CallableProcessingInterceptor[] callableInterceptors = (CallableProcessingInterceptor[]) fieldAccessor.getPropertyValue("callableInterceptors");
    assertEquals(1, callableInterceptors.length);
    DeferredResultProcessingInterceptor[] deferredResultInterceptors = (DeferredResultProcessingInterceptor[]) fieldAccessor.getPropertyValue("deferredResultInterceptors");
    assertEquals(1, deferredResultInterceptors.length);
    assertEquals(false, fieldAccessor.getPropertyValue("ignoreDefaultModelOnRedirect"));
}
Also used : HandlerMethodReturnValueHandler(org.springframework.web.method.support.HandlerMethodReturnValueHandler) MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) DeferredResultProcessingInterceptor(org.springframework.web.context.request.async.DeferredResultProcessingInterceptor) HandlerMethodArgumentResolver(org.springframework.web.method.support.HandlerMethodArgumentResolver) TestBean(org.springframework.tests.sample.beans.TestBean) CallableProcessingInterceptor(org.springframework.web.context.request.async.CallableProcessingInterceptor) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) StringHttpMessageConverter(org.springframework.http.converter.StringHttpMessageConverter) HttpMessageConverter(org.springframework.http.converter.HttpMessageConverter) MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) List(java.util.List) RequestMappingHandlerAdapter(org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)5 CallableProcessingInterceptor (org.springframework.web.context.request.async.CallableProcessingInterceptor)5 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)2 DeferredResultProcessingInterceptor (org.springframework.web.context.request.async.DeferredResultProcessingInterceptor)2 RequestMappingHandlerAdapter (org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 List (java.util.List)1 HttpMessageConverter (org.springframework.http.converter.HttpMessageConverter)1 StringHttpMessageConverter (org.springframework.http.converter.StringHttpMessageConverter)1 MappingJackson2HttpMessageConverter (org.springframework.http.converter.json.MappingJackson2HttpMessageConverter)1 TestBean (org.springframework.tests.sample.beans.TestBean)1 HandlerMethodArgumentResolver (org.springframework.web.method.support.HandlerMethodArgumentResolver)1 HandlerMethodReturnValueHandler (org.springframework.web.method.support.HandlerMethodReturnValueHandler)1