use of org.springframework.aop.interceptor.SimpleTraceInterceptor 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.interceptor.SimpleTraceInterceptor 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.interceptor.SimpleTraceInterceptor 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.interceptor.SimpleTraceInterceptor in project spring-framework by spring-projects.
the class ConfigurationClassPostProcessorTests method genericsBasedInjectionWithEarlyGenericsMatchingOnJdkProxy.
@Test
void genericsBasedInjectionWithEarlyGenericsMatchingOnJdkProxy() {
beanFactory.registerBeanDefinition("configClass", new RootBeanDefinition(RepositoryConfiguration.class));
new ConfigurationClassPostProcessor().postProcessBeanFactory(beanFactory);
DefaultAdvisorAutoProxyCreator autoProxyCreator = new DefaultAdvisorAutoProxyCreator();
autoProxyCreator.setBeanFactory(beanFactory);
beanFactory.addBeanPostProcessor(autoProxyCreator);
beanFactory.registerSingleton("traceInterceptor", new DefaultPointcutAdvisor(new SimpleTraceInterceptor()));
String[] beanNames = beanFactory.getBeanNamesForType(RepositoryInterface.class);
assertThat(beanNames).contains("stringRepo");
beanNames = beanFactory.getBeanNamesForType(ResolvableType.forClassWithGenerics(RepositoryInterface.class, String.class));
assertThat(beanNames.length).isEqualTo(1);
assertThat(beanNames[0]).isEqualTo("stringRepo");
beanNames = beanFactory.getBeanNamesForType(ResolvableType.forClassWithGenerics(RepositoryInterface.class, String.class));
assertThat(beanNames.length).isEqualTo(1);
assertThat(beanNames[0]).isEqualTo("stringRepo");
assertThat(AopUtils.isJdkDynamicProxy(beanFactory.getBean("stringRepo"))).isTrue();
}
use of org.springframework.aop.interceptor.SimpleTraceInterceptor in project spring-framework by spring-projects.
the class ConfigurationClassPostProcessorTests method genericsBasedInjectionWithEarlyGenericsMatchingOnCglibProxy.
@Test
void genericsBasedInjectionWithEarlyGenericsMatchingOnCglibProxy() {
beanFactory.registerBeanDefinition("configClass", new RootBeanDefinition(RepositoryConfiguration.class));
new ConfigurationClassPostProcessor().postProcessBeanFactory(beanFactory);
DefaultAdvisorAutoProxyCreator autoProxyCreator = new DefaultAdvisorAutoProxyCreator();
autoProxyCreator.setProxyTargetClass(true);
autoProxyCreator.setBeanFactory(beanFactory);
beanFactory.addBeanPostProcessor(autoProxyCreator);
beanFactory.registerSingleton("traceInterceptor", new DefaultPointcutAdvisor(new SimpleTraceInterceptor()));
String[] beanNames = beanFactory.getBeanNamesForType(Repository.class);
assertThat(beanNames).contains("stringRepo");
beanNames = beanFactory.getBeanNamesForType(ResolvableType.forClassWithGenerics(Repository.class, String.class));
assertThat(beanNames.length).isEqualTo(1);
assertThat(beanNames[0]).isEqualTo("stringRepo");
beanNames = beanFactory.getBeanNamesForType(ResolvableType.forClassWithGenerics(Repository.class, String.class));
assertThat(beanNames.length).isEqualTo(1);
assertThat(beanNames[0]).isEqualTo("stringRepo");
assertThat(AopUtils.isCglibProxy(beanFactory.getBean("stringRepo"))).isTrue();
}
Aggregations