Java Code Examples for org.springframework.web.context.request.async.CallableProcessingInterceptor

The following examples show how to use org.springframework.web.context.request.async.CallableProcessingInterceptor. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: spring-analysis-note   Source File: MvcNamespaceTests.java    License: MIT License 6 votes vote down vote up
@Test
public void testAsyncSupportOptions() throws Exception {
	loadBeanDefinitions("mvc-config-async-support.xml");

	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);
}
 
Example 2
Source Project: java-technology-stack   Source File: MvcNamespaceTests.java    License: MIT License 6 votes vote down vote up
@Test
public void testAsyncSupportOptions() throws Exception {
	loadBeanDefinitions("mvc-config-async-support.xml");

	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);
}
 
Example 3
Source Project: spring4-understanding   Source File: MvcNamespaceTests.java    License: Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example 4
private boolean applyEntityManagerBindingInterceptor(WebAsyncManager asyncManager, String key) {
	CallableProcessingInterceptor cpi = asyncManager.getCallableInterceptor(key);
	if (cpi == null) {
		return false;
	}
	((AsyncRequestInterceptor) cpi).bindEntityManager();
	return true;
}
 
Example 5
private boolean applyEntityManagerBindingInterceptor(WebAsyncManager asyncManager, String key) {
	CallableProcessingInterceptor cpi = asyncManager.getCallableInterceptor(key);
	if (cpi == null) {
		return false;
	}
	((AsyncRequestInterceptor) cpi).bindEntityManager();
	return true;
}
 
Example 6
private boolean applySessionBindingInterceptor(WebAsyncManager asyncManager, String key) {
	CallableProcessingInterceptor cpi = asyncManager.getCallableInterceptor(key);
	if (cpi == null) {
		return false;
	}
	((AsyncRequestInterceptor) cpi).bindSession();
	return true;
}
 
Example 7
Source Project: spring-analysis-note   Source File: OpenSessionInViewFilter.java    License: MIT License 5 votes vote down vote up
private boolean applySessionBindingInterceptor(WebAsyncManager asyncManager, String key) {
	CallableProcessingInterceptor cpi = asyncManager.getCallableInterceptor(key);
	if (cpi == null) {
		return false;
	}
	((AsyncRequestInterceptor) cpi).bindSession();
	return true;
}
 
Example 8
@Override
public void configureAsyncSupport(AsyncSupportConfigurer configurer) {
	configurer.setDefaultTimeout(2500).setTaskExecutor(new ConcurrentTaskExecutor())
			.registerCallableInterceptors(new CallableProcessingInterceptor() {
			})
			.registerDeferredResultInterceptors(new DeferredResultProcessingInterceptor() {
			});
}
 
Example 9
/** Configure async support for Spring MVC. */
@Bean
public WebMvcConfigurer webMvcConfigurerConfigurer(AsyncTaskExecutor taskExecutor, CallableProcessingInterceptor callableProcessingInterceptor) {
    return new WebMvcConfigurer() {
        @Override
        public void configureAsyncSupport(AsyncSupportConfigurer configurer) {
            configurer.setDefaultTimeout(360000).setTaskExecutor(taskExecutor);
            configurer.registerCallableInterceptors(callableProcessingInterceptor);
            WebMvcConfigurer.super.configureAsyncSupport(configurer);
        }
    };
}
 
Example 10
@Bean
public CallableProcessingInterceptor callableProcessingInterceptor() {
    return new TimeoutCallableProcessingInterceptor() {
        @Override
        public <T> Object handleTimeout(NativeWebRequest request, Callable<T> task) throws Exception {
            log.error("timeout!");
            return super.handleTimeout(request, task);
        }
    };
}
 
Example 11
private boolean applyEntityManagerBindingInterceptor(WebAsyncManager asyncManager, String key) {
	CallableProcessingInterceptor cpi = asyncManager.getCallableInterceptor(key);
	if (cpi == null) {
		return false;
	}
	((AsyncRequestInterceptor) cpi).bindEntityManager();
	return true;
}
 
Example 12
private boolean applyEntityManagerBindingInterceptor(WebAsyncManager asyncManager, String key) {
	CallableProcessingInterceptor cpi = asyncManager.getCallableInterceptor(key);
	if (cpi == null) {
		return false;
	}
	((AsyncRequestInterceptor) cpi).bindEntityManager();
	return true;
}
 
Example 13
private boolean applySessionBindingInterceptor(WebAsyncManager asyncManager, String key) {
	CallableProcessingInterceptor cpi = asyncManager.getCallableInterceptor(key);
	if (cpi == null) {
		return false;
	}
	((AsyncRequestInterceptor) cpi).bindSession();
	return true;
}
 
Example 14
Source Project: java-technology-stack   Source File: OpenSessionInViewFilter.java    License: MIT License 5 votes vote down vote up
private boolean applySessionBindingInterceptor(WebAsyncManager asyncManager, String key) {
	CallableProcessingInterceptor cpi = asyncManager.getCallableInterceptor(key);
	if (cpi == null) {
		return false;
	}
	((AsyncRequestInterceptor) cpi).bindSession();
	return true;
}
 
Example 15
Source Project: spring-analysis-note   Source File: AsyncSupportConfigurer.java    License: MIT License 4 votes vote down vote up
protected List<CallableProcessingInterceptor> getCallableInterceptors() {
	return this.callableInterceptors;
}
 
Example 16
@SuppressWarnings("unchecked")
@Test
public void requestMappingHandlerAdapter() throws Exception {
	RequestMappingHandlerAdapter adapter = this.config.requestMappingHandlerAdapter(
			this.config.mvcContentNegotiationManager(), this.config.mvcConversionService(),
			this.config.mvcValidator());

	// 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"));
}
 
Example 17
@Bean
public CallableProcessingInterceptor callableInterceptor() {
	return Mockito.mock(CallableProcessingInterceptor.class);
}
 
Example 18
Source Project: java-technology-stack   Source File: AsyncSupportConfigurer.java    License: MIT License 4 votes vote down vote up
protected List<CallableProcessingInterceptor> getCallableInterceptors() {
	return this.callableInterceptors;
}
 
Example 19
@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"));
}
 
Example 20
@Override
public void configureAsyncSupport(AsyncSupportConfigurer configurer) {
	configurer.setDefaultTimeout(2500).setTaskExecutor(new ConcurrentTaskExecutor())
		.registerCallableInterceptors(new CallableProcessingInterceptor() { })
		.registerDeferredResultInterceptors(new DeferredResultProcessingInterceptor() {});
}
 
Example 21
@Bean
public CallableProcessingInterceptor callableInterceptor() {
	return Mockito.mock(CallableProcessingInterceptor.class);
}
 
Example 22
/**
 * Configure {@code CallableProcessingInterceptor}'s to register on async requests.
 * @param interceptors the interceptors to register
 */
public void setCallableInterceptors(List<CallableProcessingInterceptor> interceptors) {
	Assert.notNull(interceptors, "CallableProcessingInterceptor List must not be null");
	this.callableInterceptors = interceptors.toArray(new CallableProcessingInterceptor[interceptors.size()]);
}
 
Example 23
Source Project: lams   Source File: AsyncSupportConfigurer.java    License: GNU General Public License v2.0 4 votes vote down vote up
protected List<CallableProcessingInterceptor> getCallableInterceptors() {
	return this.callableInterceptors;
}
 
Example 24
/**
 * Configure {@code CallableProcessingInterceptor}'s to register on async requests.
 * @param interceptors the interceptors to register
 */
public void setCallableInterceptors(List<CallableProcessingInterceptor> interceptors) {
	Assert.notNull(interceptors);
	this.callableInterceptors = interceptors.toArray(new CallableProcessingInterceptor[interceptors.size()]);
}
 
Example 25
protected List<CallableProcessingInterceptor> getCallableInterceptors() {
	return this.callableInterceptors;
}
 
Example 26
@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
	assertEquals(2, adapter.getMessageConverters().size());
	assertEquals(StringHttpMessageConverter.class, adapter.getMessageConverters().get(0).getClass());
	assertEquals(MappingJackson2HttpMessageConverter.class, adapter.getMessageConverters().get(1).getClass());
	ObjectMapper objectMapper = ((MappingJackson2HttpMessageConverter)adapter.getMessageConverters().get(1)).getObjectMapper();
	assertFalse(objectMapper.getDeserializationConfig().isEnabled(MapperFeature.DEFAULT_VIEW_INCLUSION));
	assertFalse(objectMapper.getSerializationConfig().isEnabled(MapperFeature.DEFAULT_VIEW_INCLUSION));
	assertFalse(objectMapper.getDeserializationConfig().isEnabled(DeserializationFeature.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"));
}
 
Example 27
@Bean
public CallableProcessingInterceptor callableInterceptor() {
	return Mockito.mock(CallableProcessingInterceptor.class);
}
 
Example 28
/**
 * Configure {@code CallableProcessingInterceptor}'s to register on async requests.
 * @param interceptors the interceptors to register
 */
public void setCallableInterceptors(List<CallableProcessingInterceptor> interceptors) {
	this.callableInterceptors = interceptors.toArray(new CallableProcessingInterceptor[0]);
}
 
Example 29
Source Project: spring-analysis-note   Source File: AsyncSupportConfigurer.java    License: MIT License 2 votes vote down vote up
/**
 * Configure lifecycle interceptors with callbacks around concurrent request
 * execution that starts when a controller returns a
 * {@link java.util.concurrent.Callable}.
 * @param interceptors the interceptors to register
 */
public AsyncSupportConfigurer registerCallableInterceptors(CallableProcessingInterceptor... interceptors) {
	this.callableInterceptors.addAll(Arrays.asList(interceptors));
	return this;
}
 
Example 30
/**
 * Configure {@code CallableProcessingInterceptor}'s to register on async requests.
 * @param interceptors the interceptors to register
 */
public void setCallableInterceptors(List<CallableProcessingInterceptor> interceptors) {
	this.callableInterceptors = interceptors.toArray(new CallableProcessingInterceptor[0]);
}