use of org.springframework.aop.support.DefaultPointcutAdvisor in project spring-framework by spring-projects.
the class ServletAnnotationControllerHandlerMethodTests method sessionAttributeExposureWithInterface.
@SuppressWarnings("rawtypes")
@PathPatternsParameterizedTest
void sessionAttributeExposureWithInterface(boolean usePathPatterns) throws Exception {
initDispatcherServlet(MySessionAttributesControllerImpl.class, usePathPatterns, wac -> {
wac.registerBeanDefinition("viewResolver", new RootBeanDefinition(ModelExposingViewResolver.class));
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", "/myPage");
MockHttpServletResponse response = new MockHttpServletResponse();
getServlet().service(request, response);
assertThat(request.getAttribute("viewName")).isEqualTo("page1");
HttpSession session = request.getSession();
assertThat(session).isNotNull();
assertThat(session.getAttribute("object1") != null).isTrue();
assertThat(session.getAttribute("object2") != null).isTrue();
assertThat(((Map) session.getAttribute("model")).containsKey("object1")).isTrue();
assertThat(((Map) session.getAttribute("model")).containsKey("object2")).isTrue();
request = new MockHttpServletRequest("POST", "/myPage");
request.setSession(session);
response = new MockHttpServletResponse();
getServlet().service(request, response);
assertThat(request.getAttribute("viewName")).isEqualTo("page2");
assertThat(session.getAttribute("object1") != null).isTrue();
assertThat(session.getAttribute("object2") != null).isTrue();
assertThat(((Map) session.getAttribute("model")).containsKey("object1")).isTrue();
assertThat(((Map) session.getAttribute("model")).containsKey("object2")).isTrue();
}
use of org.springframework.aop.support.DefaultPointcutAdvisor in project spring-framework by spring-projects.
the class CglibProxyControllerTests method initServlet.
@SuppressWarnings("serial")
private void initServlet(final Class<?> controllerClass) throws ServletException {
servlet = new DispatcherServlet() {
@Override
protected WebApplicationContext createWebApplicationContext(@Nullable WebApplicationContext parent) {
GenericWebApplicationContext wac = new GenericWebApplicationContext();
wac.registerBeanDefinition("controller", new RootBeanDefinition(controllerClass));
DefaultAdvisorAutoProxyCreator autoProxyCreator = new DefaultAdvisorAutoProxyCreator();
autoProxyCreator.setProxyTargetClass(true);
autoProxyCreator.setBeanFactory(wac.getBeanFactory());
wac.getBeanFactory().addBeanPostProcessor(autoProxyCreator);
Pointcut pointcut = new AnnotationMatchingPointcut(Controller.class);
DefaultPointcutAdvisor advisor = new DefaultPointcutAdvisor(pointcut, new SimpleTraceInterceptor(true));
wac.getBeanFactory().registerSingleton("advisor", advisor);
wac.refresh();
return wac;
}
};
servlet.init(new MockServletConfig());
}
use of org.springframework.aop.support.DefaultPointcutAdvisor in project spring-framework by spring-projects.
the class JdkProxyControllerTests method initServlet.
@SuppressWarnings("serial")
private void initServlet(final Class<?> controllerclass) throws ServletException {
servlet = new DispatcherServlet() {
@Override
protected WebApplicationContext createWebApplicationContext(@Nullable WebApplicationContext parent) {
GenericWebApplicationContext wac = new GenericWebApplicationContext();
wac.registerBeanDefinition("controller", new RootBeanDefinition(controllerclass));
DefaultAdvisorAutoProxyCreator autoProxyCreator = new DefaultAdvisorAutoProxyCreator();
autoProxyCreator.setBeanFactory(wac.getBeanFactory());
wac.getBeanFactory().addBeanPostProcessor(autoProxyCreator);
wac.getBeanFactory().registerSingleton("advisor", new DefaultPointcutAdvisor(new SimpleTraceInterceptor(true)));
wac.refresh();
return wac;
}
};
servlet.init(new MockServletConfig());
}
use of org.springframework.aop.support.DefaultPointcutAdvisor in project spring-framework by spring-projects.
the class TrickyAspectJPointcutExpressionTests method testManualProxyJavaWithDynamicPointcut.
@Test
public void testManualProxyJavaWithDynamicPointcut() throws Exception {
TestService target = new TestServiceImpl();
LogUserAdvice logAdvice = new LogUserAdvice();
AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
pointcut.setExpression(String.format("@within(%s.Log)", getClass().getName()));
testAdvice(new DefaultPointcutAdvisor(pointcut, logAdvice), logAdvice, target, "TestServiceImpl");
}
use of org.springframework.aop.support.DefaultPointcutAdvisor in project spring-framework by spring-projects.
the class TrickyAspectJPointcutExpressionTests method testManualProxyJavaWithStaticPointcutAndTwoClassLoaders.
@Test
public void testManualProxyJavaWithStaticPointcutAndTwoClassLoaders() throws Exception {
LogUserAdvice logAdvice = new LogUserAdvice();
AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
pointcut.setExpression(String.format("execution(* %s.TestService.*(..))", getClass().getName()));
// Test with default class loader first...
testAdvice(new DefaultPointcutAdvisor(pointcut, logAdvice), logAdvice, new TestServiceImpl(), "TestServiceImpl");
// Then try again with a different class loader on the target...
SimpleThrowawayClassLoader loader = new SimpleThrowawayClassLoader(TestServiceImpl.class.getClassLoader());
// Make sure the interface is loaded from the parent class loader
loader.excludeClass(TestService.class.getName());
loader.excludeClass(TestException.class.getName());
TestService other = (TestService) loader.loadClass(TestServiceImpl.class.getName()).getDeclaredConstructor().newInstance();
testAdvice(new DefaultPointcutAdvisor(pointcut, logAdvice), logAdvice, other, "TestServiceImpl");
}
Aggregations