INT-1200 the <annotation-config> now accepts the 'default-publisher-channel' attribute for the @Publisher support
This commit is contained in:
@@ -19,9 +19,11 @@ package org.springframework.integration.config.xml;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.config.RuntimeBeanReference;
|
||||
import org.springframework.beans.factory.support.RootBeanDefinition;
|
||||
import org.springframework.beans.factory.xml.BeanDefinitionParser;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Parser for the <annotation-config> element of the integration namespace.
|
||||
@@ -42,6 +44,10 @@ public class AnnotationConfigParser implements BeanDefinitionParser {
|
||||
RootBeanDefinition publisherAnnotationPostProcessorDef = new RootBeanDefinition(
|
||||
IntegrationNamespaceUtils.BASE_PACKAGE + ".aop.PublisherAnnotationBeanPostProcessor");
|
||||
publisherAnnotationPostProcessorDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
|
||||
String defaultPublisherChannel = element.getAttribute("default-publisher-channel");
|
||||
if (StringUtils.hasText(defaultPublisherChannel)) {
|
||||
publisherAnnotationPostProcessorDef.getPropertyValues().add("defaultChannel", new RuntimeBeanReference(defaultPublisherChannel));
|
||||
}
|
||||
String publisherAnnotationPostProcessorName = IntegrationNamespaceUtils.BASE_PACKAGE + ".internalPublisherAnnotationBeanPostProcessor";
|
||||
parserContext.getRegistry().registerBeanDefinition(publisherAnnotationPostProcessorName, publisherAnnotationPostProcessorDef);
|
||||
return null;
|
||||
|
||||
@@ -19,6 +19,20 @@
|
||||
Enables annotation support for Message Endpoints.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="default-publisher-channel" type="xsd:string" use="optional">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Default output channel for the @Publisher annotation support.
|
||||
</xsd:documentation>
|
||||
<xsd:appinfo>
|
||||
<tool:annotation kind="ref">
|
||||
<tool:expected-type type="org.springframework.integration.core.MessageChannel"/>
|
||||
</tool:annotation>
|
||||
</xsd:appinfo>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
|
||||
<xsd:element name="application-event-multicaster">
|
||||
|
||||
@@ -13,6 +13,10 @@
|
||||
<si:queue />
|
||||
</si:channel>
|
||||
|
||||
<si:annotation-config/>
|
||||
<si:channel id="defaultChannel">
|
||||
<si:queue />
|
||||
</si:channel>
|
||||
|
||||
<si:annotation-config default-publisher-channel="defaultChannel"/>
|
||||
|
||||
</beans>
|
||||
@@ -39,26 +39,44 @@ public class AnnotationConfigRegistrationTests {
|
||||
private TestBean testBean;
|
||||
|
||||
@Autowired
|
||||
private QueueChannel channel;
|
||||
private QueueChannel testChannel;
|
||||
|
||||
@Autowired
|
||||
private QueueChannel defaultChannel;
|
||||
|
||||
|
||||
@Test // INT-1200
|
||||
public void verifyInterception() {
|
||||
String name = testBean.setName("John", "Doe");
|
||||
Assert.assertNotNull(name);
|
||||
Message<?> message = channel.receive(0);
|
||||
Message<?> message = testChannel.receive(0);
|
||||
Assert.assertNotNull(message);
|
||||
Assert.assertEquals("John Doe", message.getPayload());
|
||||
Assert.assertEquals("John DoeDoe", message.getPayload());
|
||||
Assert.assertEquals("123", message.getHeaders().get("x"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void defaultChannel() {
|
||||
String result = testBean.exclaim("hello");
|
||||
Assert.assertNotNull(result);
|
||||
Assert.assertEquals("HELLO!!!", result);
|
||||
Message<?> message = defaultChannel.receive(0);
|
||||
Assert.assertNotNull(message);
|
||||
Assert.assertEquals("HELLO!!!", message.getPayload());
|
||||
}
|
||||
|
||||
|
||||
public static class TestBean {
|
||||
|
||||
@Publisher(channel="testChannel", payload="#return", headers="x='123'")
|
||||
@Publisher(channel="testChannel", payload="#return + #args.lname", headers="x='123'")
|
||||
public String setName(String fname, String lname){
|
||||
return fname + " " + lname;
|
||||
}
|
||||
|
||||
@Publisher
|
||||
public String exclaim(String s) {
|
||||
return s.toUpperCase() + "!!!";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user