Search in sources :

Example 21 with DefaultPointcutAdvisor

use of org.springframework.aop.support.DefaultPointcutAdvisor in project spring-framework by spring-projects.

the class GroovyAspectTests method manualGroovyBeanWithStaticPointcut.

@Test
public void manualGroovyBeanWithStaticPointcut() throws Exception {
    TestService target = (TestService) scriptFactory.getScriptedObject(new ResourceScriptSource(new ClassPathResource("GroovyServiceImpl.grv", getClass())));
    AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
    pointcut.setExpression(String.format("execution(* %s.TestService+.*(..))", ClassUtils.getPackageName(getClass())));
    testAdvice(new DefaultPointcutAdvisor(pointcut, logAdvice), logAdvice, target, "GroovyServiceImpl", true);
}
Also used : ResourceScriptSource(org.springframework.scripting.support.ResourceScriptSource) AspectJExpressionPointcut(org.springframework.aop.aspectj.AspectJExpressionPointcut) DefaultPointcutAdvisor(org.springframework.aop.support.DefaultPointcutAdvisor) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.jupiter.api.Test)

Example 22 with DefaultPointcutAdvisor

use of org.springframework.aop.support.DefaultPointcutAdvisor in project springside4 by springside.

the class JavaSimonConfig method monitoringAdvisor.

// 定义AOP, 对标注了@Monitored的方法进行监控
@Bean(name = "monitoringAdvisor")
public DefaultPointcutAdvisor monitoringAdvisor() {
    DefaultPointcutAdvisor monitoringAdvisor = new DefaultPointcutAdvisor();
    monitoringAdvisor.setAdvice(new MonitoringInterceptor());
    monitoringAdvisor.setPointcut(new MonitoredMeasuringPointcut());
    return monitoringAdvisor;
}
Also used : MonitoringInterceptor(org.javasimon.spring.MonitoringInterceptor) MonitoredMeasuringPointcut(org.javasimon.spring.MonitoredMeasuringPointcut) DefaultPointcutAdvisor(org.springframework.aop.support.DefaultPointcutAdvisor) ServletRegistrationBean(org.springframework.boot.context.embedded.ServletRegistrationBean) Bean(org.springframework.context.annotation.Bean)

Example 23 with DefaultPointcutAdvisor

use of org.springframework.aop.support.DefaultPointcutAdvisor in project spring-framework by spring-projects.

the class ServletAnnotationControllerHandlerMethodTests method requestMappingInterfaceWithProxy.

@Test
public void requestMappingInterfaceWithProxy() throws Exception {
    initServlet(new ApplicationContextInitializer<GenericWebApplicationContext>() {

        @Override
        public void initialize(GenericWebApplicationContext wac) {
            DefaultAdvisorAutoProxyCreator autoProxyCreator = new DefaultAdvisorAutoProxyCreator();
            autoProxyCreator.setBeanFactory(wac.getBeanFactory());
            wac.getBeanFactory().addBeanPostProcessor(autoProxyCreator);
            wac.getBeanFactory().registerSingleton("advisor", new DefaultPointcutAdvisor(new SimpleTraceInterceptor()));
        }
    }, IMyControllerImpl.class);
    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/handle");
    MockHttpServletResponse response = new MockHttpServletResponse();
    getServlet().service(request, response);
    assertEquals("handle null", response.getContentAsString());
    request = new MockHttpServletRequest("GET", "/handle");
    request.addParameter("p", "value");
    response = new MockHttpServletResponse();
    getServlet().service(request, response);
    assertEquals("handle value", response.getContentAsString());
}
Also used : DefaultAdvisorAutoProxyCreator(org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator) SimpleTraceInterceptor(org.springframework.aop.interceptor.SimpleTraceInterceptor) MockHttpServletRequest(org.springframework.mock.web.test.MockHttpServletRequest) DefaultPointcutAdvisor(org.springframework.aop.support.DefaultPointcutAdvisor) GenericWebApplicationContext(org.springframework.web.context.support.GenericWebApplicationContext) MockHttpServletResponse(org.springframework.mock.web.test.MockHttpServletResponse) Test(org.junit.Test)

Example 24 with DefaultPointcutAdvisor

use of org.springframework.aop.support.DefaultPointcutAdvisor in project spring-framework by spring-projects.

the class ServletAnnotationControllerHandlerMethodTests method proxiedFormController.

@Test
public void proxiedFormController() throws Exception {
    initServlet(new ApplicationContextInitializer<GenericWebApplicationContext>() {

        @Override
        public void initialize(GenericWebApplicationContext wac) {
            wac.registerBeanDefinition("viewResolver", new RootBeanDefinition(TestViewResolver.class));
            DefaultAdvisorAutoProxyCreator autoProxyCreator = new DefaultAdvisorAutoProxyCreator();
            autoProxyCreator.setBeanFactory(wac.getBeanFactory());
            wac.getBeanFactory().addBeanPostProcessor(autoProxyCreator);
            wac.getBeanFactory().registerSingleton("advisor", new DefaultPointcutAdvisor(new SimpleTraceInterceptor()));
        }
    }, MyFormController.class);
    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/myPath.do");
    request.addParameter("name", "name1");
    request.addParameter("age", "value2");
    MockHttpServletResponse response = new MockHttpServletResponse();
    getServlet().service(request, response);
    assertEquals("myView-name1-typeMismatch-tb1-myValue", response.getContentAsString());
}
Also used : DefaultAdvisorAutoProxyCreator(org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator) SimpleTraceInterceptor(org.springframework.aop.interceptor.SimpleTraceInterceptor) MockHttpServletRequest(org.springframework.mock.web.test.MockHttpServletRequest) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) DefaultPointcutAdvisor(org.springframework.aop.support.DefaultPointcutAdvisor) GenericWebApplicationContext(org.springframework.web.context.support.GenericWebApplicationContext) MockHttpServletResponse(org.springframework.mock.web.test.MockHttpServletResponse) Test(org.junit.Test)

Example 25 with DefaultPointcutAdvisor

use of org.springframework.aop.support.DefaultPointcutAdvisor in project spring-framework by spring-projects.

the class ServletAnnotationControllerHandlerMethodTests method sessionAttributeExposureWithInterface.

@SuppressWarnings("rawtypes")
@Test
public void sessionAttributeExposureWithInterface() throws Exception {
    initServlet(new ApplicationContextInitializer<GenericWebApplicationContext>() {

        @Override
        public void initialize(GenericWebApplicationContext context) {
            context.registerBeanDefinition("viewResolver", new RootBeanDefinition(ModelExposingViewResolver.class));
            DefaultAdvisorAutoProxyCreator autoProxyCreator = new DefaultAdvisorAutoProxyCreator();
            autoProxyCreator.setBeanFactory(context.getBeanFactory());
            context.getBeanFactory().addBeanPostProcessor(autoProxyCreator);
            context.getBeanFactory().registerSingleton("advisor", new DefaultPointcutAdvisor(new SimpleTraceInterceptor()));
        }
    }, MySessionAttributesControllerImpl.class);
    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/myPage");
    MockHttpServletResponse response = new MockHttpServletResponse();
    getServlet().service(request, response);
    assertEquals("page1", request.getAttribute("viewName"));
    HttpSession session = request.getSession();
    assertTrue(session.getAttribute("object1") != null);
    assertTrue(session.getAttribute("object2") != null);
    assertTrue(((Map) session.getAttribute("model")).containsKey("object1"));
    assertTrue(((Map) session.getAttribute("model")).containsKey("object2"));
    request = new MockHttpServletRequest("POST", "/myPage");
    request.setSession(session);
    response = new MockHttpServletResponse();
    getServlet().service(request, response);
    assertEquals("page2", request.getAttribute("viewName"));
    assertTrue(session.getAttribute("object1") != null);
    assertTrue(session.getAttribute("object2") != null);
    assertTrue(((Map) session.getAttribute("model")).containsKey("object1"));
    assertTrue(((Map) session.getAttribute("model")).containsKey("object2"));
}
Also used : DefaultAdvisorAutoProxyCreator(org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator) SimpleTraceInterceptor(org.springframework.aop.interceptor.SimpleTraceInterceptor) MockHttpServletRequest(org.springframework.mock.web.test.MockHttpServletRequest) HttpSession(javax.servlet.http.HttpSession) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) DefaultPointcutAdvisor(org.springframework.aop.support.DefaultPointcutAdvisor) GenericWebApplicationContext(org.springframework.web.context.support.GenericWebApplicationContext) MockHttpServletResponse(org.springframework.mock.web.test.MockHttpServletResponse) Test(org.junit.Test)

Aggregations

DefaultPointcutAdvisor (org.springframework.aop.support.DefaultPointcutAdvisor)45 Test (org.junit.jupiter.api.Test)29 DefaultAdvisorAutoProxyCreator (org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator)16 SimpleTraceInterceptor (org.springframework.aop.interceptor.SimpleTraceInterceptor)16 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)14 ITestBean (org.springframework.beans.testfixture.beans.ITestBean)12 NopInterceptor (org.springframework.aop.testfixture.interceptor.NopInterceptor)11 TestBean (org.springframework.beans.testfixture.beans.TestBean)11 Advisor (org.springframework.aop.Advisor)8 DefaultIntroductionAdvisor (org.springframework.aop.support.DefaultIntroductionAdvisor)7 CountingBeforeAdvice (org.springframework.aop.testfixture.advice.CountingBeforeAdvice)7 SerializableNopInterceptor (org.springframework.aop.testfixture.interceptor.SerializableNopInterceptor)7 AspectJExpressionPointcut (org.springframework.aop.aspectj.AspectJExpressionPointcut)6 GenericWebApplicationContext (org.springframework.web.context.support.GenericWebApplicationContext)5 Pointcut (org.springframework.aop.Pointcut)4 ClassPathResource (org.springframework.core.io.ClassPathResource)4 ResourceScriptSource (org.springframework.scripting.support.ResourceScriptSource)4 Test (org.junit.Test)3 NameMatchMethodPointcut (org.springframework.aop.support.NameMatchMethodPointcut)3 StaticMethodMatcherPointcutAdvisor (org.springframework.aop.support.StaticMethodMatcherPointcutAdvisor)3