Search in sources :

Example 16 with SimpleTraceInterceptor

use of org.springframework.aop.interceptor.SimpleTraceInterceptor in project spring-framework by spring-projects.

the class ServletAnnotationControllerHandlerMethodTests method requestMappingInterfaceWithProxy.

@PathPatternsParameterizedTest
void requestMappingInterfaceWithProxy(boolean usePathPatterns) throws Exception {
    initDispatcherServlet(IMyControllerImpl.class, usePathPatterns, wac -> {
        DefaultAdvisorAutoProxyCreator autoProxyCreator = new DefaultAdvisorAutoProxyCreator();
        autoProxyCreator.setBeanFactory(wac.getBeanFactory());
        wac.getBeanFactory().addBeanPostProcessor(autoProxyCreator);
        wac.getBeanFactory().registerSingleton("advisor", new DefaultPointcutAdvisor(new SimpleTraceInterceptor()));
    });
    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/handle");
    MockHttpServletResponse response = new MockHttpServletResponse();
    getServlet().service(request, response);
    assertThat(response.getContentAsString()).isEqualTo("handle null");
    request = new MockHttpServletRequest("GET", "/handle");
    request.addParameter("p", "value");
    response = new MockHttpServletResponse();
    getServlet().service(request, response);
    assertThat(response.getContentAsString()).isEqualTo("handle value");
}
Also used : DefaultAdvisorAutoProxyCreator(org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator) SimpleTraceInterceptor(org.springframework.aop.interceptor.SimpleTraceInterceptor) MockHttpServletRequest(org.springframework.web.testfixture.servlet.MockHttpServletRequest) DefaultPointcutAdvisor(org.springframework.aop.support.DefaultPointcutAdvisor) MockHttpServletResponse(org.springframework.web.testfixture.servlet.MockHttpServletResponse) PathPatternsParameterizedTest(org.springframework.web.servlet.handler.PathPatternsParameterizedTest)

Aggregations

DefaultAdvisorAutoProxyCreator (org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator)16 SimpleTraceInterceptor (org.springframework.aop.interceptor.SimpleTraceInterceptor)16 DefaultPointcutAdvisor (org.springframework.aop.support.DefaultPointcutAdvisor)16 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)14 Test (org.junit.jupiter.api.Test)8 GenericWebApplicationContext (org.springframework.web.context.support.GenericWebApplicationContext)5 Test (org.junit.Test)3 MockHttpServletRequest (org.springframework.mock.web.test.MockHttpServletRequest)3 MockHttpServletResponse (org.springframework.mock.web.test.MockHttpServletResponse)3 PathPatternsParameterizedTest (org.springframework.web.servlet.handler.PathPatternsParameterizedTest)3 MockHttpServletRequest (org.springframework.web.testfixture.servlet.MockHttpServletRequest)3 MockHttpServletResponse (org.springframework.web.testfixture.servlet.MockHttpServletResponse)3 WebApplicationContext (org.springframework.web.context.WebApplicationContext)2 DispatcherServlet (org.springframework.web.servlet.DispatcherServlet)2 MockServletConfig (org.springframework.web.testfixture.servlet.MockServletConfig)2 HttpSession (jakarta.servlet.http.HttpSession)1 Map (java.util.Map)1 HttpSession (javax.servlet.http.HttpSession)1 Pointcut (org.springframework.aop.Pointcut)1 AnnotationMatchingPointcut (org.springframework.aop.support.annotation.AnnotationMatchingPointcut)1