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

The following examples show how to use org.springframework.web.context.request.async.CallableProcessingInterceptor. 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 File: MvcNamespaceTests.java    From spring4-understanding with 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 #2
Source File: MvcNamespaceTests.java    From java-technology-stack with 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 File: MvcNamespaceTests.java    From spring-analysis-note with 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 #4
Source File: OpenEntityManagerInViewFilter.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private boolean applyEntityManagerBindingInterceptor(WebAsyncManager asyncManager, String key) {
	CallableProcessingInterceptor cpi = asyncManager.getCallableInterceptor(key);
	if (cpi == null) {
		return false;
	}
	((AsyncRequestInterceptor) cpi).bindEntityManager();
	return true;
}
 
Example #5
Source File: OpenSessionInViewFilter.java    From java-technology-stack with 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 #6
Source File: OpenSessionInViewInterceptor.java    From java-technology-stack with 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 #7
Source File: OpenEntityManagerInViewFilter.java    From java-technology-stack with MIT License 5 votes vote down vote up
private boolean applyEntityManagerBindingInterceptor(WebAsyncManager asyncManager, String key) {
	CallableProcessingInterceptor cpi = asyncManager.getCallableInterceptor(key);
	if (cpi == null) {
		return false;
	}
	((AsyncRequestInterceptor) cpi).bindEntityManager();
	return true;
}
 
Example #8
Source File: OpenEntityManagerInViewInterceptor.java    From java-technology-stack with MIT License 5 votes vote down vote up
private boolean applyEntityManagerBindingInterceptor(WebAsyncManager asyncManager, String key) {
	CallableProcessingInterceptor cpi = asyncManager.getCallableInterceptor(key);
	if (cpi == null) {
		return false;
	}
	((AsyncRequestInterceptor) cpi).bindEntityManager();
	return true;
}
 
Example #9
Source File: AsyncConfiguration.java    From download-using-streaming-response-body with MIT License 5 votes vote down vote up
@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 #10
Source File: AsyncConfiguration.java    From download-using-streaming-response-body with MIT License 5 votes vote down vote up
/** 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 #11
Source File: WebMvcConfigurationSupportExtensionTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public void configureAsyncSupport(AsyncSupportConfigurer configurer) {
	configurer.setDefaultTimeout(2500).setTaskExecutor(new ConcurrentTaskExecutor())
			.registerCallableInterceptors(new CallableProcessingInterceptor() {
			})
			.registerDeferredResultInterceptors(new DeferredResultProcessingInterceptor() {
			});
}
 
Example #12
Source File: OpenEntityManagerInViewInterceptor.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private boolean applyEntityManagerBindingInterceptor(WebAsyncManager asyncManager, String key) {
	CallableProcessingInterceptor cpi = asyncManager.getCallableInterceptor(key);
	if (cpi == null) {
		return false;
	}
	((AsyncRequestInterceptor) cpi).bindEntityManager();
	return true;
}
 
Example #13
Source File: OpenSessionInViewFilter.java    From spring-analysis-note with 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 #14
Source File: OpenSessionInViewInterceptor.java    From spring-analysis-note with 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 File: AsyncControllerJavaConfigTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Bean
public CallableProcessingInterceptor callableInterceptor() {
	return Mockito.mock(CallableProcessingInterceptor.class);
}
 
Example #16
Source File: AsyncControllerJavaConfigTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Bean
public CallableProcessingInterceptor callableInterceptor() {
	return Mockito.mock(CallableProcessingInterceptor.class);
}
 
Example #17
Source File: WebMvcConfigurationSupportExtensionTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@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 #18
Source File: AsyncSupportConfigurer.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
protected List<CallableProcessingInterceptor> getCallableInterceptors() {
	return this.callableInterceptors;
}
 
Example #19
Source File: RequestMappingHandlerAdapter.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
/**
 * 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 #20
Source File: AsyncSupportConfigurer.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
protected List<CallableProcessingInterceptor> getCallableInterceptors() {
	return this.callableInterceptors;
}
 
Example #21
Source File: RequestMappingHandlerAdapter.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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 #22
Source File: AsyncControllerJavaConfigTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Bean
public CallableProcessingInterceptor callableInterceptor() {
	return Mockito.mock(CallableProcessingInterceptor.class);
}
 
Example #23
Source File: WebMvcConfigurationSupportExtensionTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
public void configureAsyncSupport(AsyncSupportConfigurer configurer) {
	configurer.setDefaultTimeout(2500).setTaskExecutor(new ConcurrentTaskExecutor())
		.registerCallableInterceptors(new CallableProcessingInterceptor() { })
		.registerDeferredResultInterceptors(new DeferredResultProcessingInterceptor() {});
}
 
Example #24
Source File: WebMvcConfigurationSupportExtensionTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
@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 #25
Source File: AsyncSupportConfigurer.java    From java-technology-stack with MIT License 4 votes vote down vote up
protected List<CallableProcessingInterceptor> getCallableInterceptors() {
	return this.callableInterceptors;
}
 
Example #26
Source File: AsyncSupportConfigurer.java    From spring-analysis-note with MIT License 4 votes vote down vote up
protected List<CallableProcessingInterceptor> getCallableInterceptors() {
	return this.callableInterceptors;
}
 
Example #27
Source File: WebMvcConfigurationSupportExtensionTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@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 #28
Source File: AsyncSupportConfigurer.java    From lams with GNU General Public License v2.0 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 #29
Source File: AsyncSupportConfigurer.java    From java-technology-stack with 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
Source File: RequestMappingHandlerAdapter.java    From java-technology-stack with MIT License 2 votes vote down vote up
/**
 * 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]);
}