use of org.springframework.web.servlet.HandlerExecutionChain in project gocd by gocd.
the class InterceptorInjectorTest method testShouldMergeInterceptors.
public void testShouldMergeInterceptors() throws Throwable {
HandlerInterceptor interceptorOfFramework = new HandlerInterceptorSub();
HandlerInterceptor interceptorOfTab = new HandlerInterceptorSub();
HandlerInterceptor[] interceptorsOfFramework = new HandlerInterceptor[] { interceptorOfFramework };
HandlerInterceptor[] interceptorsOfTab = new HandlerInterceptor[] { interceptorOfTab };
Mock proceedingJoinPoint = mock(ProceedingJoinPoint.class);
proceedingJoinPoint.expects(once()).method("proceed").will(returnValue(new HandlerExecutionChain(null, interceptorsOfTab)));
InterceptorInjector injector = new InterceptorInjector();
injector.setInterceptors(interceptorsOfFramework);
HandlerExecutionChain handlers = injector.mergeInterceptorsToTabs((ProceedingJoinPoint) proceedingJoinPoint.proxy());
assertEquals(2, handlers.getInterceptors().length);
assertSame(interceptorOfFramework, handlers.getInterceptors()[0]);
assertSame(interceptorOfTab, handlers.getInterceptors()[1]);
}
use of org.springframework.web.servlet.HandlerExecutionChain in project gocd by gocd.
the class InterceptorInjectorTest method testShouldJustReturnInterceptorsOfFrameworkIfNoTabInterceptors.
public void testShouldJustReturnInterceptorsOfFrameworkIfNoTabInterceptors() throws Throwable {
HandlerInterceptor interceptorOfFramework = new HandlerInterceptorSub();
HandlerInterceptor[] interceptorsOfFramework = new HandlerInterceptor[] { interceptorOfFramework };
Mock proceedingJoinPoint = mock(ProceedingJoinPoint.class);
proceedingJoinPoint.expects(once()).method("proceed").will(returnValue(new HandlerExecutionChain(null, null)));
InterceptorInjector injector = new InterceptorInjector();
injector.setInterceptors(interceptorsOfFramework);
HandlerExecutionChain handlers = injector.mergeInterceptorsToTabs((ProceedingJoinPoint) proceedingJoinPoint.proxy());
assertEquals(1, handlers.getInterceptors().length);
assertSame(interceptorOfFramework, handlers.getInterceptors()[0]);
}
use of org.springframework.web.servlet.HandlerExecutionChain in project gocd by gocd.
the class InterceptorInjectorTest method testShouldNotChangeHandler.
public void testShouldNotChangeHandler() throws Throwable {
SimpleUrlHandlerMapping handler = new SimpleUrlHandlerMapping();
Mock proceedingJoinPoint = mock(ProceedingJoinPoint.class);
proceedingJoinPoint.expects(once()).method("proceed").will(returnValue(new HandlerExecutionChain(handler, null)));
InterceptorInjector injector = new InterceptorInjector();
HandlerExecutionChain handlers = injector.mergeInterceptorsToTabs((ProceedingJoinPoint) proceedingJoinPoint.proxy());
assertSame(handler, handlers.getHandler());
}
use of org.springframework.web.servlet.HandlerExecutionChain in project gocd by gocd.
the class InterceptorInjectorTest method testShouldReturnNullWhenNoHandlerFound.
public void testShouldReturnNullWhenNoHandlerFound() throws Throwable {
Mock proceedingJoinPoint = mock(ProceedingJoinPoint.class);
proceedingJoinPoint.expects(once()).method("proceed").will(returnValue(null));
InterceptorInjector injector = new InterceptorInjector();
HandlerExecutionChain handlers = injector.mergeInterceptorsToTabs((ProceedingJoinPoint) proceedingJoinPoint.proxy());
assertNull(handlers);
}
use of org.springframework.web.servlet.HandlerExecutionChain in project spring-framework by spring-projects.
the class AbstractHandlerMapping method getCorsHandlerExecutionChain.
/**
* Update the HandlerExecutionChain for CORS-related handling.
* <p>For pre-flight requests, the default implementation replaces the selected
* handler with a simple HttpRequestHandler that invokes the configured
* {@link #setCorsProcessor}.
* <p>For actual requests, the default implementation inserts a
* HandlerInterceptor that makes CORS-related checks and adds CORS headers.
* @param request the current request
* @param chain the handler chain
* @param config the applicable CORS configuration, possibly {@code null}
* @since 4.2
*/
protected HandlerExecutionChain getCorsHandlerExecutionChain(HttpServletRequest request, HandlerExecutionChain chain, CorsConfiguration config) {
if (CorsUtils.isPreFlightRequest(request)) {
HandlerInterceptor[] interceptors = chain.getInterceptors();
chain = new HandlerExecutionChain(new PreFlightHandler(config), interceptors);
} else {
chain.addInterceptor(new CorsInterceptor(config));
}
return chain;
}
Aggregations