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);
}
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;
}
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());
}
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());
}
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"));
}
Aggregations