From 40b26b6be783d686871619810ac33d832651e7bd Mon Sep 17 00:00:00 2001 From: Oleg Zhurakousky Date: Wed, 28 Oct 2009 23:39:54 +0000 Subject: [PATCH] INT-809, Cleaned uo some code and updated the docs to reflect the new 'publisher' namespace --- .../config/xml/PublisherParser.java | 3 - .../src/message-publishing.xml | 110 +++++++++--------- 2 files changed, 54 insertions(+), 59 deletions(-) diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/PublisherParser.java b/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/PublisherParser.java index 1a66fe1564..b11826ac02 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/PublisherParser.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/PublisherParser.java @@ -27,10 +27,8 @@ import org.springframework.beans.factory.support.ManagedMap; import org.springframework.beans.factory.xml.AbstractBeanDefinitionParser; import org.springframework.beans.factory.xml.ParserContext; import org.springframework.integration.aop.MethodNameMappingExpressionSource; -import org.springframework.integration.channel.ChannelResolver; import org.springframework.integration.channel.MapBasedChannelResolver; import org.springframework.integration.context.IntegrationContextUtils; -import org.springframework.integration.core.MessageChannel; import org.springframework.util.StringUtils; import org.springframework.util.xml.DomUtils; import org.w3c.dom.Element; @@ -51,7 +49,6 @@ public class PublisherParser extends AbstractBeanDefinitionParser { BeanDefinitionBuilder spelSourceBilder = BeanDefinitionBuilder.genericBeanDefinition(MethodNameMappingExpressionSource.class.getName()); Map> mappings = this.getMappings(element, element.getAttribute("default-channel")); spelSourceBilder.addConstructorArgValue(mappings.get("payload")); - MethodNameMappingExpressionSource m = null; if (mappings.get("headers") != null){ spelSourceBilder.addPropertyValue("headerExpressionMap", mappings.get("headers")); } diff --git a/spring-integration-reference/src/message-publishing.xml b/spring-integration-reference/src/message-publishing.xml index 26889fc3bc..c0edf65fdd 100644 --- a/spring-integration-reference/src/message-publishing.xml +++ b/spring-integration-reference/src/message-publishing.xml @@ -66,17 +66,20 @@ public String setName(String fname, String lname){
- XML-based approach via MessagePublishingInterceptor + XML-based approach via <publisher> element - XML-based approach allows you to configure Message Publishing via AOP-based configuration and although - configuration itself is a bit more extensive it has certain benefits over annotation based approach since it - allows you to use pointcut expressions, thus possibly intercepting multiple methods at once. + XML-based approach allows you to configure Message Publishing via AOP-based configuration and + simple namespace-based configuration of MessagePublishingInterceptor. + It certainly has certain benefits over annotation based approach since it + allows you to use AOP pointcut expressions, thus possibly intercepting multiple methods at once or + intercepting and publishing methods to which you don't have a source code. - To configure Message Publishing via XML you need to provide two things: + To configure Message Publishing via XML all you need is the following two things: - Register MessagePublishingInterceptor + Provide configuration for MessagePublishingInterceptor + via <publisher> XML element Provide AOP configuration to apply MessagePublishingInterceptor @@ -84,70 +87,65 @@ public String setName(String fname, String lname){ -<bean id="testBean" - class="org.springframework.integration.aop.MessagePublishingInterceptorUsageTest$TestBean" /> - - <si:channel id="testChannel"> - <si:queue /> - </si:channel> - - <aop:config> - <aop:advisor advice-ref="publishingInterceptor" pointcut="bean(testBean)" /> - </aop:config> - - <bean id="publishingInterceptor" - class="org.springframework.integration.aop.MessagePublishingInterceptor"> - <constructor-arg> - <bean - class="org.springframework.integration.aop.MethodNameMappingExpressionSource"> - <constructor-arg> - <map> - <entry key="*" value="#return" /> - </map> - </constructor-arg> - <property name="headerExpressionMap"> - <map> - <entry key="*" value="foo='bar'" /> - </map> - </property> - <property name="channelMap"> - <map> - <entry key="setName" value="channel" /> - </map> - </property> - </bean> - </constructor-arg> - <property name="channelResolver"> - <bean - class="org.springframework.integration.channel.MapBasedChannelResolver"> - <property name="channelMap"> - <map> - <entry key="channel" value-ref="testChannel" /> - </map> - </property> - </bean> - </property> - </bean> + +<beans:bean id="testBean" class="org.foo.bar.TestBean" /> +<aop:config> + <aop:advisor advice-ref="interceptor" pointcut="bean(testBean)" /> +</aop:config> + +<publisher id="interceptor" default-channel="defaultChannel"> + <method pattern="echo" payload="'Echoing: ' + #return" headers="foo='bar'" channel="echoChannel"/> + <method pattern="echoDef*" payload="#return"/> + <method pattern="foo*"/> +</publisher> + - As you can see MessagePublishingInterceptor defines and binds the same variables as + As you can see <publisher> uses the same variables as PublisherAnnotationAdvisor to utilize the power of Spring 3.0 Expression Langage. - In this example after execution of any public method of a testBean a Message - will be constructed with the following structure: + In the above example the execution of echo method of a testBean will + rander the Message with the following structure: - Message payload - will be of type and value returned by an executed method. + Message payload - will be of type String and value of "Echoing: [value]" where value is the value + returned by an executed method. Message headers will be 'foo' with value of "bar". + + + Message will be sent to echoChannel. -In future versions namespace support will be available to simplify XML-based configuration. - + In the second method mapping the execution of any method that begins with echoDef of testBean will result in the + Message with the following structure. + + + Message payload - will be the value + returned by an executed method. + + + Since channel attriute is not provided, the Message will be sent to the + defaultChannel defined by the publisher. + + + + + The third mapping is almost identical to the previous (with the exceptipon of method pattern), + since the return value will be mapped to the Message paylad by default if nothing else is specifued. + + + For a simple maping rules you can rely on publisher defaults. For example: + +<publisher id="anotherInterceptor"/> + + This will map the return value of every method that matches the pointcut expression to a payload and will be sent to a default-channel. + If the defaultChannelis not specified (as above) the messages will be sent to nullChannel +
\ No newline at end of file