Search in sources :

Example 1 with CallableProcessingInterceptorAdapter

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

the class TestDispatcherServlet method registerAsyncResultInterceptors.

private void registerAsyncResultInterceptors(final HttpServletRequest request) {
    WebAsyncManager asyncManager = WebAsyncUtils.getAsyncManager(request);
    asyncManager.registerCallableInterceptor(KEY, new CallableProcessingInterceptorAdapter() {

        @Override
        public <T> void postProcess(NativeWebRequest r, Callable<T> task, Object value) throws Exception {
            getMvcResult(request).setAsyncResult(value);
        }
    });
    asyncManager.registerDeferredResultInterceptor(KEY, new DeferredResultProcessingInterceptorAdapter() {

        @Override
        public <T> void postProcess(NativeWebRequest r, DeferredResult<T> result, Object value) throws Exception {
            getMvcResult(request).setAsyncResult(value);
        }
    });
}
Also used : WebAsyncManager(org.springframework.web.context.request.async.WebAsyncManager) DeferredResultProcessingInterceptorAdapter(org.springframework.web.context.request.async.DeferredResultProcessingInterceptorAdapter) CallableProcessingInterceptorAdapter(org.springframework.web.context.request.async.CallableProcessingInterceptorAdapter) NativeWebRequest(org.springframework.web.context.request.NativeWebRequest) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Example 2 with CallableProcessingInterceptorAdapter

use of org.springframework.web.context.request.async.CallableProcessingInterceptorAdapter in project spring-security by spring-projects.

the class WebAsyncManagerIntegrationFilterTests method doFilterInternalRegistersSecurityContextCallableProcessor.

@Test
public void doFilterInternalRegistersSecurityContextCallableProcessor() throws Exception {
    SecurityContextHolder.setContext(securityContext);
    asyncManager.registerCallableInterceptors(new CallableProcessingInterceptorAdapter() {

        @Override
        public <T> void postProcess(NativeWebRequest request, Callable<T> task, Object concurrentResult) throws Exception {
            assertThat(SecurityContextHolder.getContext()).isNotSameAs(securityContext);
        }
    });
    filter.doFilterInternal(request, response, filterChain);
    VerifyingCallable verifyingCallable = new VerifyingCallable();
    asyncManager.startCallableProcessing(verifyingCallable);
    threadFactory.join();
    assertThat(asyncManager.getConcurrentResult()).isSameAs(securityContext);
}
Also used : CallableProcessingInterceptorAdapter(org.springframework.web.context.request.async.CallableProcessingInterceptorAdapter) NativeWebRequest(org.springframework.web.context.request.NativeWebRequest) Test(org.junit.Test)

Example 3 with CallableProcessingInterceptorAdapter

use of org.springframework.web.context.request.async.CallableProcessingInterceptorAdapter in project spring-security by spring-projects.

the class WebAsyncManagerIntegrationFilterTests method doFilterInternalRegistersSecurityContextCallableProcessorContextUpdated.

@Test
public void doFilterInternalRegistersSecurityContextCallableProcessorContextUpdated() throws Exception {
    SecurityContextHolder.setContext(SecurityContextHolder.createEmptyContext());
    asyncManager.registerCallableInterceptors(new CallableProcessingInterceptorAdapter() {

        @Override
        public <T> void postProcess(NativeWebRequest request, Callable<T> task, Object concurrentResult) throws Exception {
            assertThat(SecurityContextHolder.getContext()).isNotSameAs(securityContext);
        }
    });
    filter.doFilterInternal(request, response, filterChain);
    SecurityContextHolder.setContext(securityContext);
    VerifyingCallable verifyingCallable = new VerifyingCallable();
    asyncManager.startCallableProcessing(verifyingCallable);
    threadFactory.join();
    assertThat(asyncManager.getConcurrentResult()).isSameAs(securityContext);
}
Also used : CallableProcessingInterceptorAdapter(org.springframework.web.context.request.async.CallableProcessingInterceptorAdapter) NativeWebRequest(org.springframework.web.context.request.NativeWebRequest) Test(org.junit.Test)

Aggregations

NativeWebRequest (org.springframework.web.context.request.NativeWebRequest)3 CallableProcessingInterceptorAdapter (org.springframework.web.context.request.async.CallableProcessingInterceptorAdapter)3 Test (org.junit.Test)2 IOException (java.io.IOException)1 ServletException (javax.servlet.ServletException)1 DeferredResultProcessingInterceptorAdapter (org.springframework.web.context.request.async.DeferredResultProcessingInterceptorAdapter)1 WebAsyncManager (org.springframework.web.context.request.async.WebAsyncManager)1