use of org.springframework.aop.Advisor in project spring-integration by spring-projects.
the class PollingTransactionTests method transactionWithCommitAndAdvices.
@Test
@SuppressWarnings("unchecked")
public void transactionWithCommitAndAdvices() throws InterruptedException {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("transactionTests.xml", this.getClass());
PollingConsumer advicedPoller = context.getBean("advicedSa", PollingConsumer.class);
List<Advice> adviceChain = TestUtils.getPropertyValue(advicedPoller, "adviceChain", List.class);
assertEquals(4, adviceChain.size());
Runnable poller = TestUtils.getPropertyValue(advicedPoller, "poller", Runnable.class);
Callable<?> pollingTask = TestUtils.getPropertyValue(poller, "pollingTask", Callable.class);
assertTrue("Poller is not Advised", pollingTask instanceof Advised);
Advisor[] advisors = ((Advised) pollingTask).getAdvisors();
assertEquals(4, advisors.length);
assertThat("First advisor is not TX", advisors[0].getAdvice(), instanceOf(TransactionInterceptor.class));
TestTransactionManager txManager = (TestTransactionManager) context.getBean("txManager");
MessageChannel input = (MessageChannel) context.getBean("goodInputWithAdvice");
PollableChannel output = (PollableChannel) context.getBean("output");
assertEquals(0, txManager.getCommitCount());
assertEquals(0, txManager.getRollbackCount());
input.send(new GenericMessage<>("test"));
txManager.waitForCompletion(10000);
Message<?> message = output.receive(0);
assertNotNull(message);
assertEquals(0, txManager.getRollbackCount());
context.close();
}
use of org.springframework.aop.Advisor in project spring-integration by spring-projects.
the class IdempotentReceiverAutoProxyCreator method getAdvicesAndAdvisorsForBean.
@Override
protected Object[] getAdvicesAndAdvisorsForBean(Class<?> beanClass, String beanName, TargetSource customTargetSource) throws BeansException {
initIdempotentEndpointsIfNecessary();
if (MessageHandler.class.isAssignableFrom(beanClass)) {
List<Advisor> interceptors = new ArrayList<Advisor>();
for (Map.Entry<String, List<String>> entry : this.idempotentEndpoints.entrySet()) {
List<String> mappedNames = entry.getValue();
for (String mappedName : mappedNames) {
if (isMatch(mappedName, beanName)) {
DefaultBeanFactoryPointcutAdvisor idempotentReceiverInterceptor = new DefaultBeanFactoryPointcutAdvisor();
idempotentReceiverInterceptor.setAdviceBeanName(entry.getKey());
NameMatchMethodPointcut pointcut = new NameMatchMethodPointcut();
pointcut.setMappedName("handleMessage");
idempotentReceiverInterceptor.setPointcut(pointcut);
idempotentReceiverInterceptor.setBeanFactory(getBeanFactory());
interceptors.add(idempotentReceiverInterceptor);
}
}
}
if (!interceptors.isEmpty()) {
return interceptors.toArray();
}
}
return DO_NOT_PROXY;
}
use of org.springframework.aop.Advisor in project spring-integration by spring-projects.
the class ChannelSecurityInterceptorBeanPostProcessor method getAdvicesAndAdvisorsForBean.
@Override
protected Object[] getAdvicesAndAdvisorsForBean(Class<?> beanClass, String beanName, TargetSource customTargetSource) throws BeansException {
if (MessageChannel.class.isAssignableFrom(beanClass)) {
List<Advisor> interceptors = new ArrayList<Advisor>();
for (Map.Entry<String, Set<Pattern>> entry : this.securityInterceptorMappings.entrySet()) {
if (isMatch(beanName, entry.getValue())) {
DefaultBeanFactoryPointcutAdvisor channelSecurityInterceptor = new DefaultBeanFactoryPointcutAdvisor();
channelSecurityInterceptor.setAdviceBeanName(entry.getKey());
channelSecurityInterceptor.setBeanFactory(getBeanFactory());
interceptors.add(channelSecurityInterceptor);
}
}
if (!interceptors.isEmpty()) {
return interceptors.toArray();
}
}
return DO_NOT_PROXY;
}
use of org.springframework.aop.Advisor in project spring-integration by spring-projects.
the class SecuredChannelsParserTests method testAdminOrUserRequiredForReceive.
@Test
public void testAdminOrUserRequiredForReceive() {
String beanName = "adminOrUserRequiredForReceive";
messageChannel.setBeanName(beanName);
MessageChannel proxy = (MessageChannel) applicationContext.getAutowireCapableBeanFactory().applyBeanPostProcessorsAfterInitialization(messageChannel, beanName);
assertTrue("Channel was not proxied", AopUtils.isAopProxy(proxy));
Advisor[] advisors = ((Advised) proxy).getAdvisors();
assertEquals("Wrong number of interceptors", 1, advisors.length);
ChannelSecurityInterceptor interceptor = (ChannelSecurityInterceptor) advisors[0].getAdvice();
ChannelAccessPolicy policy = this.retrievePolicyForPatternString(beanName, interceptor);
assertNotNull("Pattern '" + beanName + "' is not included in mappings", policy);
Collection<ConfigAttribute> sendDefinition = policy.getConfigAttributesForSend();
Collection<ConfigAttribute> receiveDefinition = policy.getConfigAttributesForReceive();
Collection<String> receiveRoles = this.getRolesFromDefintion(receiveDefinition);
assertTrue("ROLE_ADMIN not found as receive attribute", receiveRoles.contains("ROLE_ADMIN"));
assertTrue("ROLE_USER not found as receive attribute", receiveRoles.contains("ROLE_USER"));
assertTrue("Policy applies to receive", sendDefinition.size() == 0);
}
use of org.springframework.aop.Advisor in project spring-integration by spring-projects.
the class SecuredChannelsParserTests method testAdminRequiredForReceive.
@Test
public void testAdminRequiredForReceive() {
String beanName = "adminRequiredForReceive";
messageChannel.setBeanName(beanName);
MessageChannel proxy = (MessageChannel) applicationContext.getAutowireCapableBeanFactory().applyBeanPostProcessorsAfterInitialization(messageChannel, beanName);
assertTrue("Channel was not proxied", AopUtils.isAopProxy(proxy));
Advisor[] advisors = ((Advised) proxy).getAdvisors();
assertEquals("Wrong number of interceptors", 1, advisors.length);
ChannelSecurityInterceptor interceptor = (ChannelSecurityInterceptor) advisors[0].getAdvice();
ChannelAccessPolicy policy = this.retrievePolicyForPatternString(beanName, interceptor);
assertNotNull("Pattern '" + beanName + "' is not included in mappings", policy);
Collection<ConfigAttribute> sendDefinition = policy.getConfigAttributesForSend();
Collection<ConfigAttribute> receiveDefinition = policy.getConfigAttributesForReceive();
Collection<String> receiveRoles = this.getRolesFromDefintion(receiveDefinition);
assertTrue("ROLE_ADMIN not found as receive attribute", receiveRoles.contains("ROLE_ADMIN"));
assertTrue("Policy applies to receive", sendDefinition.size() == 0);
}
Aggregations