Update Router Documentation
* Fixed formatting issues * Updated documentation with latest Router refactoring changes * Rephrased several paragraphs regarding XPath Router for increased clarity
This commit is contained in:
committed by
Mark Fisher
parent
619356c986
commit
cd2b33438e
@@ -57,6 +57,10 @@
|
|||||||
<firstname>David</firstname>
|
<firstname>David</firstname>
|
||||||
<surname>Turanski</surname>
|
<surname>Turanski</surname>
|
||||||
</author>
|
</author>
|
||||||
|
<author>
|
||||||
|
<firstname>Gunnar</firstname>
|
||||||
|
<surname>Hillert</surname>
|
||||||
|
</author>
|
||||||
</authorgroup>
|
</authorgroup>
|
||||||
|
|
||||||
<legalnotice><para>© SpringSource Inc., 2011</para></legalnotice>
|
<legalnotice><para>© SpringSource Inc., 2011</para></legalnotice>
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
xmlns:ns4="http://www.w3.org/1998/Math/MathML"
|
xmlns:ns4="http://www.w3.org/1998/Math/MathML"
|
||||||
xmlns:ns3="http://www.w3.org/2000/svg"
|
xmlns:ns3="http://www.w3.org/2000/svg"
|
||||||
xmlns:ns="http://docbook.org/ns/docbook">
|
xmlns:ns="http://docbook.org/ns/docbook">
|
||||||
<title>JMX Support</title>
|
<title id="jmx.title">JMX Support</title>
|
||||||
|
|
||||||
<para>Spring Integration provides Channel Adapters for receiving and
|
<para>Spring Integration provides Channel Adapters for receiving and
|
||||||
publishing JMX Notifications. There is also an inbound Channel Adapter for
|
publishing JMX Notifications. There is also an inbound Channel Adapter for
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -49,6 +49,8 @@
|
|||||||
and <interfacename>org.w3c.dom.Document</interfacename> payloads are supported. Custom conversion to a
|
and <interfacename>org.w3c.dom.Document</interfacename> payloads are supported. Custom conversion to a
|
||||||
<interfacename>Source</interfacename> is also supported by injecting an implementation of
|
<interfacename>Source</interfacename> is also supported by injecting an implementation of
|
||||||
<interfacename>SourceFactory</interfacename>.
|
<interfacename>SourceFactory</interfacename>.
|
||||||
|
</para>
|
||||||
|
<para>
|
||||||
<programlisting language="xml"><![CDATA[<bean id="unmarshallingTransformer"
|
<programlisting language="xml"><![CDATA[<bean id="unmarshallingTransformer"
|
||||||
class="org.springframework.integration.xml.transformer.UnmarshallingTransformer">
|
class="org.springframework.integration.xml.transformer.UnmarshallingTransformer">
|
||||||
<constructor-arg>
|
<constructor-arg>
|
||||||
@@ -67,18 +69,21 @@
|
|||||||
the payload into an alternative xml format. To achieve this configure a
|
the payload into an alternative xml format. To achieve this configure a
|
||||||
<interfacename>ResultTransformer</interfacename>. Two implementations are provided, one which converts to
|
<interfacename>ResultTransformer</interfacename>. Two implementations are provided, one which converts to
|
||||||
<classname>String</classname> and another which converts to <interfacename>Document</interfacename>.
|
<classname>String</classname> and another which converts to <interfacename>Document</interfacename>.
|
||||||
|
</para>
|
||||||
|
|
||||||
<programlisting language="xml"><![CDATA[<bean id="marshallingTransformer"
|
<programlisting language="xml"><![CDATA[<bean id="marshallingTransformer"
|
||||||
class="org.springframework.integration.xml.transformer.MarshallingTransformer">
|
class="org.springframework.integration.xml.transformer.MarshallingTransformer">
|
||||||
<constructor-arg>
|
<constructor-arg>
|
||||||
<bean class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
|
<bean class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
|
||||||
<property name="contextPath" value="org.example" />
|
<property name="contextPath" value="org.example"/>
|
||||||
</bean>
|
</bean>
|
||||||
</constructor-arg>
|
</constructor-arg>
|
||||||
<constructor-arg>
|
<constructor-arg>
|
||||||
<bean class="org.springframework.integration.xml.transformer.ResultToDocumentTransformer" />
|
<bean
|
||||||
</constructor-arg>
|
class="org.springframework.integration.xml.transformer.ResultToDocumentTransformer"/>
|
||||||
|
</constructor-arg>
|
||||||
</bean>]]></programlisting>
|
</bean>]]></programlisting>
|
||||||
</para>
|
|
||||||
<para>
|
<para>
|
||||||
By default, the <classname>MarshallingTransformer</classname> will pass the payload Object
|
By default, the <classname>MarshallingTransformer</classname> will pass the payload Object
|
||||||
to the <interfacename>Marshaller</interfacename>, but if its boolean <code>extractPayload</code> property
|
to the <interfacename>Marshaller</interfacename>, but if its boolean <code>extractPayload</code> property
|
||||||
@@ -97,14 +102,18 @@
|
|||||||
by default <classname>XsltPayloadTransformer</classname> will create a message with a
|
by default <classname>XsltPayloadTransformer</classname> will create a message with a
|
||||||
<interfacename>Result</interfacename> payload. This can be customised by providing a
|
<interfacename>Result</interfacename> payload. This can be customised by providing a
|
||||||
<interfacename>ResultFactory</interfacename> and/or a <interfacename>ResultTransformer</interfacename>.
|
<interfacename>ResultFactory</interfacename> and/or a <interfacename>ResultTransformer</interfacename>.
|
||||||
<programlisting language="xml"><![CDATA[<bean id="xsltPayloadTransformer"
|
|
||||||
class="org.springframework.integration.xml.transformer.XsltPayloadTransformer">
|
|
||||||
<constructor-arg value="classpath:org/example/xsl/transform.xsl" />
|
|
||||||
<constructor-arg>
|
|
||||||
<bean class="org.springframework.integration.xml.transformer.ResultToDocumentTransformer" />
|
|
||||||
</constructor-arg>
|
|
||||||
</bean>]]></programlisting>
|
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
|
<programlisting language="xml"><![CDATA[
|
||||||
|
<bean id="xsltPayloadTransformer"
|
||||||
|
class="org.springframework.integration.xml.transformer.XsltPayloadTransformer">
|
||||||
|
<constructor-arg value="classpath:org/example/xsl/transform.xsl"/>
|
||||||
|
<constructor-arg>
|
||||||
|
<bean
|
||||||
|
class="org.springframework.integration.xml.transformer.ResultToDocumentTransformer"/>
|
||||||
|
</constructor-arg>
|
||||||
|
</bean>]]></programlisting>
|
||||||
|
|
||||||
</section>
|
</section>
|
||||||
<section id="xml-transformer-namespace">
|
<section id="xml-transformer-namespace">
|
||||||
|
|
||||||
@@ -116,21 +125,24 @@
|
|||||||
according to the type of the provided input channel. The namespace support is designed
|
according to the type of the provided input channel. The namespace support is designed
|
||||||
to reduce the amount of xml configuration by allowing the creation of an endpoint and transformer
|
to reduce the amount of xml configuration by allowing the creation of an endpoint and transformer
|
||||||
using one element.
|
using one element.
|
||||||
<programlisting language="xml"><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
|
</para>
|
||||||
|
<programlisting language="xml"><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xmlns:int="http://www.springframework.org/schema/integration"
|
xmlns:int="http://www.springframework.org/schema/integration"
|
||||||
xmlns:int-xml="http://www.springframework.org/schema/integration/xml"
|
xmlns:int-xml="http://www.springframework.org/schema/integration/xml"
|
||||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||||
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
|
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
|
||||||
http://www.springframework.org/schema/integration
|
http://www.springframework.org/schema/integration
|
||||||
http://www.springframework.org/schema/integration/spring-integration-2.0.xsd
|
http://www.springframework.org/schema/integration/spring-integration-2.0.xsd
|
||||||
http://www.springframework.org/schema/integration/xml
|
http://www.springframework.org/schema/integration/xml
|
||||||
http://www.springframework.org/schema/integration/xml/spring-integration-xml-2.0.xsd">
|
http://www.springframework.org/schema/integration/xml/spring-integration-xml-2.0.xsd">
|
||||||
</beans>]]></programlisting>
|
</beans>]]></programlisting>
|
||||||
|
<para>
|
||||||
The namespace support for <classname>UnmarshallingTransformer</classname> is shown below.
|
The namespace support for <classname>UnmarshallingTransformer</classname> is shown below.
|
||||||
Since the namespace is now creating an endpoint instance rather than a transformer,
|
Since the namespace is now creating an endpoint instance rather than a transformer,
|
||||||
a poller can also be nested within the element to control the polling of the input channel.
|
a poller can also be nested within the element to control the polling of the input channel.
|
||||||
|
</para>
|
||||||
<programlisting language="xml"><![CDATA[<int-xml:unmarshalling-transformer id="defaultUnmarshaller"
|
<programlisting language="xml"><![CDATA[<int-xml:unmarshalling-transformer id="defaultUnmarshaller"
|
||||||
input-channel="input"
|
input-channel="input"
|
||||||
output-channel="output"
|
output-channel="output"
|
||||||
@@ -141,9 +153,7 @@
|
|||||||
output-channel="output"
|
output-channel="output"
|
||||||
unmarshaller="unmarshaller">
|
unmarshaller="unmarshaller">
|
||||||
<int:poller fixed-rate="2000"/>
|
<int:poller fixed-rate="2000"/>
|
||||||
<int-xml:unmarshalling-transformer/>
|
<int-xml:unmarshalling-transformer/>]]></programlisting>
|
||||||
]]></programlisting>
|
|
||||||
</para>
|
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
The namespace support for the marshalling transformer requires an input channel, output channel and a
|
The namespace support for the marshalling transformer requires an input channel, output channel and a
|
||||||
@@ -152,6 +162,8 @@
|
|||||||
reference to a custom implementation of <interfacename>ResultFactory</interfacename> can be provided as an alternative
|
reference to a custom implementation of <interfacename>ResultFactory</interfacename> can be provided as an alternative
|
||||||
to setting the <code>result-type</code> attribute using the <code>result-factory</code> attribute. An optional <code>result-transformer</code> can also be
|
to setting the <code>result-type</code> attribute using the <code>result-factory</code> attribute. An optional <code>result-transformer</code> can also be
|
||||||
specified in order to convert the created <interfacename>Result</interfacename> after marshalling.
|
specified in order to convert the created <interfacename>Result</interfacename> after marshalling.
|
||||||
|
</para>
|
||||||
|
|
||||||
<programlisting language="xml"><![CDATA[<int-xml:marshalling-transformer
|
<programlisting language="xml"><![CDATA[<int-xml:marshalling-transformer
|
||||||
input-channel="marshallingTransformerStringResultFactory"
|
input-channel="marshallingTransformerStringResultFactory"
|
||||||
output-channel="output"
|
output-channel="output"
|
||||||
@@ -166,7 +178,6 @@
|
|||||||
|
|
||||||
<bean id="resultTransformer"
|
<bean id="resultTransformer"
|
||||||
class="org.springframework.integration.xml.transformer.ResultToStringTransformer"/>]]></programlisting>
|
class="org.springframework.integration.xml.transformer.ResultToStringTransformer"/>]]></programlisting>
|
||||||
</para>
|
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
Namespace support for the <classname>XsltPayloadTransformer</classname> allows either a resource to be passed in in order to create the
|
Namespace support for the <classname>XsltPayloadTransformer</classname> allows either a resource to be passed in in order to create the
|
||||||
@@ -175,6 +186,7 @@
|
|||||||
be controlled by specifying either the result-factory or <code>result-type</code> attribute. A <code>result-transfomer</code> attribute can also
|
be controlled by specifying either the result-factory or <code>result-type</code> attribute. A <code>result-transfomer</code> attribute can also
|
||||||
be used to reference an implementation of <interfacename>ResultTransfomer</interfacename> where conversion of the result
|
be used to reference an implementation of <interfacename>ResultTransfomer</interfacename> where conversion of the result
|
||||||
is required before sending.
|
is required before sending.
|
||||||
|
</para>
|
||||||
<programlisting language="xml"><![CDATA[<int-xml:xslt-transformer id="xsltTransformerWithResource"
|
<programlisting language="xml"><![CDATA[<int-xml:xslt-transformer id="xsltTransformerWithResource"
|
||||||
input-channel="withResourceIn"
|
input-channel="withResourceIn"
|
||||||
output-channel="output"
|
output-channel="output"
|
||||||
@@ -184,7 +196,7 @@
|
|||||||
output-channel="output"
|
output-channel="output"
|
||||||
xsl-templates="templates"
|
xsl-templates="templates"
|
||||||
result-transformer="resultTransformer"/>]]></programlisting>
|
result-transformer="resultTransformer"/>]]></programlisting>
|
||||||
</para>
|
|
||||||
<para>
|
<para>
|
||||||
Very often to assist with transformation you may need to have access to Message data (e.g., Message Headers). For example; you may need to get access to certain Message Headers
|
Very often to assist with transformation you may need to have access to Message data (e.g., Message Headers). For example; you may need to get access to certain Message Headers
|
||||||
and pass them on as parameters to a transformer (e.g., transformer.setParameter(..)).
|
and pass them on as parameters to a transformer (e.g., transformer.setParameter(..)).
|
||||||
@@ -222,6 +234,7 @@
|
|||||||
messages. The XPath splitter implements <interfacename>MessageHandler</interfacename> and should
|
messages. The XPath splitter implements <interfacename>MessageHandler</interfacename> and should
|
||||||
therefore be configured in conjunction with an appropriate endpoint (see the namespace support below
|
therefore be configured in conjunction with an appropriate endpoint (see the namespace support below
|
||||||
for a simpler configuration alternative).
|
for a simpler configuration alternative).
|
||||||
|
</para>
|
||||||
<programlisting language="xml"><![CDATA[<bean id="splittingEndpoint"
|
<programlisting language="xml"><![CDATA[<bean id="splittingEndpoint"
|
||||||
class="org.springframework.integration.endpoint.EventDrivenConsumer">
|
class="org.springframework.integration.endpoint.EventDrivenConsumer">
|
||||||
<constructor-arg ref="orderChannel" />
|
<constructor-arg ref="orderChannel" />
|
||||||
@@ -234,41 +247,52 @@
|
|||||||
</constructor-arg>
|
</constructor-arg>
|
||||||
</bean>]]></programlisting>
|
</bean>]]></programlisting>
|
||||||
|
|
||||||
</para>
|
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section id="xpath-routing">
|
<section id="xpath-routing">
|
||||||
<title>Routing xml messages using XPath</title>
|
<title id="xpath-routing.title">Routing XML Messages using XPath</title>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
Similar to SpEL-based routers, Spring Integration provides support for routing messages based on the XPath expressions
|
Similar to SpEL-based routers, Spring Integration provides support for routing messages based on XPath expressions,
|
||||||
allowing you to create a Message Endpoint with an input channel but no output channel
|
allowing you to create a Message Endpoint with an input channel but no output channel. Instead, one or more output
|
||||||
since the output channel(s) is determined dynamically.
|
channels are determined dynamically.
|
||||||
<programlisting language="xml"><![CDATA[
|
|
||||||
<int-xml:xpath-router id="orderTypeRouter" input-channel="orderChannel">
|
|
||||||
<si-xml:xpath-expression expression="/order/type"/>
|
|
||||||
</int-xml:xpath-router>
|
|
||||||
]]></programlisting>
|
|
||||||
</para>
|
</para>
|
||||||
|
<programlisting language="xml"><![CDATA[<int-xml:xpath-router id="orderTypeRouter" input-channel="orderChannel">
|
||||||
|
<si-xml:xpath-expression expression="/order/type"/>
|
||||||
|
</int-xml:xpath-router>]]></programlisting>
|
||||||
|
|
||||||
|
<note>
|
||||||
|
For an overview of attributes that are common among Routers, please see chapter:
|
||||||
|
<emphasis><xref linkend='router-common-parameters' endterm="router-common-parameters.title"/></emphasis>
|
||||||
|
</note>
|
||||||
<para>
|
<para>
|
||||||
Internally XPath expression will be evaluated as <emphasis>NODESET</emphasis> type and converted to a
|
Internally XPath expressions will be evaluated as <emphasis>NODESET</emphasis>
|
||||||
<classname>List<String></classname> representing channel names. Typically such list will contain a single channel name.
|
type and converted to a <classname>List<String></classname> representing
|
||||||
However, based on the result of an XPath Expression XPath router can also take on the characteristics of the <emphasis>Recipient List Router</emphasis>
|
channel names. Typically such a list will contain a single channel name.
|
||||||
if XPath Expression returns more then one value, thus resulting in the <classname>List<String></classname> containing more
|
However, based on the results of an XPath Expression, the XPath router can
|
||||||
then one channel name. In that case Message will be sent to all channels in the list.
|
also take on the characteristics of a <emphasis>Recipient List Router</emphasis>
|
||||||
So assuming that the xml file passed to the router configured below contains many <code>responder</code> sub-elements representing channel names,
|
if the XPath Expression returns more then one value. In that case, the
|
||||||
the message will be sent to all of those channels.
|
<classname>List<String></classname> will contain more then one
|
||||||
|
channel name and consequently Messages will be sent to all channels in the list.
|
||||||
<programlisting language="xml"><![CDATA[<!-- route the order to all responders-->
|
</para>
|
||||||
|
<para>
|
||||||
|
Thus, assuming that the XML file passed to the router configured below
|
||||||
|
contains many <code>responder</code> sub-elements representing channel names,
|
||||||
|
the message will be sent to all of those channels.
|
||||||
|
</para>
|
||||||
|
<programlisting language="xml"><![CDATA[<!-- route the order to all responders-->
|
||||||
<int-xml:xpath-router id="responderRouter" input-channel="orderChannel">
|
<int-xml:xpath-router id="responderRouter" input-channel="orderChannel">
|
||||||
<int-xml:xpath-expression expression="/request/responders"/>
|
<int-xml:xpath-expression expression="/request/responders"/>
|
||||||
</int-xml:xpath-router>
|
</int-xml:xpath-router>
|
||||||
]]></programlisting>
|
]]></programlisting>
|
||||||
|
|
||||||
If the returned values do not represent the channel names additional mapping could be specified. For example if
|
<para>
|
||||||
the <code>/request/responders</code> expression results in two values <code>responderA</code> and <code>responderB</code> but
|
If the returned values do not represent the channel names directly, additional
|
||||||
you don't want to couple the responder names to channel names you may provide additional mapping as such:
|
mapping parameters can be specified, in order to map those returned values to actual
|
||||||
|
channel names. For example if the <code>/request/responders</code> expression
|
||||||
|
results in two values <code>responderA</code> and <code>responderB</code> but
|
||||||
|
you don't want to couple the responder names to channel names, you may provide
|
||||||
|
additional mapping configuration such as the following:
|
||||||
|
</para>
|
||||||
<programlisting language="xml"><![CDATA[<!-- route the order to all responders-->
|
<programlisting language="xml"><![CDATA[<!-- route the order to all responders-->
|
||||||
<int-xml:xpath-router id="responderRouter" input-channel="orderChannel">
|
<int-xml:xpath-router id="responderRouter" input-channel="orderChannel">
|
||||||
<int-xml:xpath-expression expression="/request/responders"/>
|
<int-xml:xpath-expression expression="/request/responders"/>
|
||||||
@@ -276,34 +300,82 @@
|
|||||||
<int-xml:mapping value="responderB" channel="channelB"/>
|
<int-xml:mapping value="responderB" channel="channelB"/>
|
||||||
</int-xml:xpath-router>
|
</int-xml:xpath-router>
|
||||||
]]></programlisting>
|
]]></programlisting>
|
||||||
</para>
|
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
As we already said the default evaluation type for XPath expressions is NODESET which is converted
|
As already mentioned, the default evaluation type for XPath expressions is
|
||||||
to a List<String> of channel names, thus handling single channel scenarios as well as multiple.
|
<emphasis>NODESET</emphasis>, which is converted to a
|
||||||
However certain XPath expressions may evaluate as String type from the very
|
<code>List<String></code> of channel names, therefore handling
|
||||||
beginning (e.g., 'name(./node())' - which will return the name of the root node) thus resulting in
|
single channel scenarios as well as multiple ones.
|
||||||
the exception if default evaluation type (NODESET) is used.
|
</para>
|
||||||
For these scenarious you may use <code>evaluate-as-string</code> attribute which will allow you to manage the
|
<para>
|
||||||
evaluation type. It is FALSE by default, however if set to TRUE, the String evaluation type will be used.
|
Nonetheless, certain XPath expressions may evaluate as String type from the
|
||||||
For example if we want to route based on the name of the root node we can have use the following configuration:
|
very beginning. Take for example the following XPath Expression:
|
||||||
|
</para>
|
||||||
<programlisting language="xml"><![CDATA[<int-xml:xpath-router id="xpathRouterAsString"
|
<programlisting language="xml"><![CDATA[name(./node())]]></programlisting>
|
||||||
input-channel="xpathStringChannel"
|
<para>
|
||||||
evaluate-as-string="true">
|
This expression will return the name of the root node. It will resulting
|
||||||
<int-xml:xpath-expression expression="name(./node())"/>
|
in an exception, if the default evaluation type <emphasis>NODESET</emphasis>
|
||||||
|
is being used.
|
||||||
|
</para>
|
||||||
|
<para>
|
||||||
|
For these scenarious, you may use the <code>evaluate-as-string</code> attribute,
|
||||||
|
which will allow you to manage the evaluation type. It is <code>FALSE</code>
|
||||||
|
by default, however if set to <code>TRUE</code>, the String evaluation
|
||||||
|
type will be used.
|
||||||
|
</para>
|
||||||
|
<note>
|
||||||
|
<para>
|
||||||
|
To provide some background information: XPath 1.0 specifies 4 data types:
|
||||||
|
</para>
|
||||||
|
<itemizedlist>
|
||||||
|
<listitem>Node-sets</listitem>
|
||||||
|
<listitem>Strings</listitem>
|
||||||
|
<listitem>Number</listitem>
|
||||||
|
<listitem>Boolean</listitem>
|
||||||
|
</itemizedlist>
|
||||||
|
<para>
|
||||||
|
When the XPath Router evaluates expressions using the optional
|
||||||
|
<code>evaluate-as-string</code> attribute, the return value is
|
||||||
|
determined per the <code>string()</code> function as defined in the
|
||||||
|
XPath specification. This means that if the expression selects
|
||||||
|
multiple nodes, it will return the string value of the first node.
|
||||||
|
</para>
|
||||||
|
<para>
|
||||||
|
For further information, please see:
|
||||||
|
</para>
|
||||||
|
<itemizedlist>
|
||||||
|
<listitem>Specification: XML Path Language (XPath) Version 1.0: http://www.w3.org/TR/xpath/</listitem>
|
||||||
|
<listitem>XPath specification - string() function: http://www.w3.org/TR/xpath/#function-string</listitem>
|
||||||
|
</itemizedlist>
|
||||||
|
</note>
|
||||||
|
<para>
|
||||||
|
For example if we want to route based on the name of the root node, we
|
||||||
|
can use the following configuration:
|
||||||
|
</para>
|
||||||
|
<programlisting language="xml"><![CDATA[<int-xml:xpath-router id="xpathRouterAsString"
|
||||||
|
input-channel="xpathStringChannel"
|
||||||
|
evaluate-as-string="true">
|
||||||
|
<int-xml:xpath-expression expression="name(./node())"/>
|
||||||
</int-xml:xpath-router>
|
</int-xml:xpath-router>
|
||||||
]]></programlisting>
|
]]></programlisting>
|
||||||
</para>
|
<section id="xpath-routing-converter">
|
||||||
|
<title>XML Payload Converter</title>
|
||||||
<para>The XPath Router does support custom implementations of the XmlPayloadConverter strategy, and when configuring
|
<para>
|
||||||
an 'xpath-router' element in XML, a reference to such an implementation may be provided via the 'converter' attribute.
|
For XPath Routers, you can also specify the Converter to use when converting
|
||||||
However, the DefaultXmlPayloadConverter is used if this reference is not provided, and it
|
payloads prior to XPath evaluation. As such, the XPath Router supports
|
||||||
should be sufficient in most cases since it can convert from Node, Document, Source,
|
custom implementations of the <classname>XmlPayloadConverter</classname> strategy,
|
||||||
File, and String typed payloads. If you need to extend beyond the capabilities of
|
and when configuring an <code>xpath-router</code> element in XML, a reference
|
||||||
that default implementation, then an upstream Transformer is probably a better option
|
to such an implementation may be provided via the <code>converter</code> attribute.
|
||||||
than providing a reference to a custom implementation of this strategy here.</para>
|
</para>
|
||||||
|
<para>
|
||||||
|
If this reference is not explicitly provided, the <classname>DefaultXmlPayloadConverter</classname>
|
||||||
|
is used. It should be sufficient in most cases, since it can convert from
|
||||||
|
Node, Document, Source, File, and String typed payloads. If you need to
|
||||||
|
extend beyond the capabilities of that default implementation, then an
|
||||||
|
upstream Transformer is generally a better option in most cases, rather
|
||||||
|
than providing a reference to a custom implementation of this strategy here.
|
||||||
|
</para>
|
||||||
|
</section>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section id="xpath-selector">
|
<section id="xpath-selector">
|
||||||
@@ -320,23 +392,25 @@
|
|||||||
|
|
||||||
<programlisting language="xml"><![CDATA[<!-- Interceptor which rejects messages that do not have a root element order -->
|
<programlisting language="xml"><![CDATA[<!-- Interceptor which rejects messages that do not have a root element order -->
|
||||||
<bean id="orderSelectingInterceptor"
|
<bean id="orderSelectingInterceptor"
|
||||||
class="org.springframework.integration.channel.interceptor.MessageSelectingInterceptor">
|
class="org.springframework.integration.channel.interceptor.MessageSelectingInterceptor">
|
||||||
<constructor-arg>
|
<constructor-arg>
|
||||||
<bean class="org.springframework.integration.xml.selector.BooleanTestXPathMessageSelector">
|
<bean
|
||||||
<constructor-arg value="boolean(/order)" />
|
class="org.springframework.integration.xml.selector.BooleanTestXPathMessageSelector">
|
||||||
</bean>
|
<constructor-arg value="boolean(/order)" />
|
||||||
</constructor-arg>
|
</bean>
|
||||||
|
</constructor-arg>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<!-- Interceptor which rejects messages that are not version one orders -->
|
<!-- Interceptor which rejects messages that are not version one orders -->
|
||||||
<bean id="versionOneOrderSelectingInterceptor"
|
<bean id="versionOneOrderSelectingInterceptor"
|
||||||
class="org.springframework.integration.channel.interceptor.MessageSelectingInterceptor">
|
class="org.springframework.integration.channel.interceptor.MessageSelectingInterceptor">
|
||||||
<constructor-arg>
|
<constructor-arg>
|
||||||
<bean class="org.springframework.integration.xml.selector.StringValueTestXPathMessageSelector">
|
<bean
|
||||||
<constructor-arg value="/order/@version" index="0"/>
|
class="org.springframework.integration.xml.selector.StringValueTestXPathMessageSelector">
|
||||||
<constructor-arg value="1" index="1"/>
|
<constructor-arg value="/order/@version" index="0"/>
|
||||||
</bean>
|
<constructor-arg value="1" index="1"/>
|
||||||
</constructor-arg>
|
</bean>
|
||||||
|
</constructor-arg>
|
||||||
</bean>]]></programlisting>
|
</bean>]]></programlisting>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
@@ -351,12 +425,15 @@
|
|||||||
</para>
|
</para>
|
||||||
<para>
|
<para>
|
||||||
Let's look at the following transformer configuration:
|
Let's look at the following transformer configuration:
|
||||||
|
</para>
|
||||||
<programlisting language="xml"><![CDATA[<int-xml:xpath-transformer input-channel="inputChannel" output-channel="outputChannel"
|
<programlisting language="xml"><![CDATA[<int-xml:xpath-transformer input-channel="inputChannel" output-channel="outputChannel"
|
||||||
xpath-expression="/person/@name" />]]></programlisting>
|
xpath-expression="/person/@name" />]]></programlisting>
|
||||||
|
<para>
|
||||||
. . . and Message
|
. . . and Message
|
||||||
|
</para>
|
||||||
<programlisting language="java"><![CDATA[Message<?> message =
|
<programlisting language="java"><![CDATA[Message<?> message =
|
||||||
MessageBuilder.withPayload("<person name='John Doe' age='42' married='true'/>").build();]]></programlisting>
|
MessageBuilder.withPayload("<person name='John Doe' age='42' married='true'/>").build();]]></programlisting>
|
||||||
|
<para>
|
||||||
After sending this message to the 'inputChannel' the XPath transformer configured above will transform
|
After sending this message to the 'inputChannel' the XPath transformer configured above will transform
|
||||||
this XML Message to a simple Message with payload of 'John Doe' all based on
|
this XML Message to a simple Message with payload of 'John Doe' all based on
|
||||||
the simple XPath Expression specified in the <code>xpath-expression</code> attribute.
|
the simple XPath Expression specified in the <code>xpath-expression</code> attribute.
|
||||||
@@ -372,13 +449,15 @@
|
|||||||
<para>
|
<para>
|
||||||
You can configure the desired type by simply using <code>evaluation-type</code>
|
You can configure the desired type by simply using <code>evaluation-type</code>
|
||||||
attribute of the <xpath-transformer/> element.
|
attribute of the <xpath-transformer/> element.
|
||||||
<programlisting language="xml"><![CDATA[<int-xml:xpath-transformer input-channel="numberInput" xpath-expression="/person/@age"
|
|
||||||
evaluation-type="NUMBER_RESULT" output-channel="output"/>
|
|
||||||
|
|
||||||
<int-xml:xpath-transformer input-channel="booleanInput" xpath-expression="/person/@married = 'true'"
|
|
||||||
evaluation-type="BOOLEAN_RESULT" output-channel="output"/>
|
|
||||||
]]></programlisting>
|
|
||||||
</para>
|
</para>
|
||||||
|
<programlisting language="xml"><![CDATA[<int-xml:xpath-transformer input-channel="numberInput" xpath-expression="/person/@age"
|
||||||
|
evaluation-type="NUMBER_RESULT" output-channel="output"/>
|
||||||
|
|
||||||
|
<int-xml:xpath-transformer input-channel="booleanInput"
|
||||||
|
xpath-expression="/person/@married = 'true'"
|
||||||
|
evaluation-type="BOOLEAN_RESULT" output-channel="output"/>
|
||||||
|
]]></programlisting>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
<emphasis>Node Mappers</emphasis>
|
<emphasis>Node Mappers</emphasis>
|
||||||
</para>
|
</para>
|
||||||
@@ -387,26 +466,33 @@
|
|||||||
implementation of the <classname>org.springframework.xml.xpath.NodeMapper</classname> - an interface used by
|
implementation of the <classname>org.springframework.xml.xpath.NodeMapper</classname> - an interface used by
|
||||||
<classname>XPathOperations</classname> implementations for mapping Node objects on a per-node basis. To provide a
|
<classname>XPathOperations</classname> implementations for mapping Node objects on a per-node basis. To provide a
|
||||||
reference to a <classname>NodeMapper</classname> simply use <code>node-mapper</code> attribute:
|
reference to a <classname>NodeMapper</classname> simply use <code>node-mapper</code> attribute:
|
||||||
|
</para>
|
||||||
<programlisting language="xml"><![CDATA[<int-xml:xpath-transformer input-channel="nodeMapperInput" xpath-expression="/person/@age"
|
<programlisting language="xml"><![CDATA[<int-xml:xpath-transformer input-channel="nodeMapperInput" xpath-expression="/person/@age"
|
||||||
node-mapper="testNodeMapper" output-channel="output"/>
|
node-mapper="testNodeMapper" output-channel="output"/>]]></programlisting>
|
||||||
]]></programlisting>
|
<para>
|
||||||
. . . and Sample NodeMapper implementation:
|
. . . and Sample NodeMapper implementation:
|
||||||
|
</para>
|
||||||
<programlisting language="java"><![CDATA[class TestNodeMapper implements NodeMapper {
|
<programlisting language="java"><![CDATA[class TestNodeMapper implements NodeMapper {
|
||||||
public Object mapNode(Node node, int nodeNum) throws DOMException {
|
public Object mapNode(Node node, int nodeNum) throws DOMException {
|
||||||
return node.getTextContent() + "-mapped";
|
return node.getTextContent() + "-mapped";
|
||||||
}
|
}
|
||||||
}]]></programlisting>
|
}]]></programlisting>
|
||||||
</para>
|
|
||||||
<para>
|
<para>
|
||||||
<emphasis>XML Payload Converter</emphasis>
|
<emphasis>XML Payload Converter</emphasis>
|
||||||
</para>
|
</para>
|
||||||
<para>
|
<para>
|
||||||
You can also use an implementation of the <classname>org.springframework.integration.xml.XmlPayloadConverter</classname> to
|
You can also use an implementation of the <classname>org.springframework.integration.xml.XmlPayloadConverter</classname> to
|
||||||
provide more granular transformation:
|
provide more granular transformation:
|
||||||
<programlisting language="xml"><![CDATA[<int-xml:xpath-transformer input-channel="customConverterInput" xpath-expression="/test/@type"
|
</para>
|
||||||
converter="testXmlPayloadConverter" output-channel="output"/>
|
<programlisting language="xml"><![CDATA[<int-xml:xpath-transformer input-channel="customConverterInput"
|
||||||
|
output-channel="output" xpath-expression="/test/@type"
|
||||||
|
converter="testXmlPayloadConverter" />
|
||||||
]]></programlisting>
|
]]></programlisting>
|
||||||
|
|
||||||
|
<para>
|
||||||
. . . and Sample XmlPayloadConverter implementation:
|
. . . and Sample XmlPayloadConverter implementation:
|
||||||
|
</para>
|
||||||
<programlisting language="java"><![CDATA[class TestXmlPayloadConverter implements XmlPayloadConverter {
|
<programlisting language="java"><![CDATA[class TestXmlPayloadConverter implements XmlPayloadConverter {
|
||||||
public Source convertToSource(Object object) {
|
public Source convertToSource(Object object) {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
@@ -426,12 +512,12 @@
|
|||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
}]]></programlisting>
|
}]]></programlisting>
|
||||||
</para>
|
|
||||||
<para>The DefaultXmlPayloadConverter is used if this reference is not provided, and it
|
<para>The DefaultXmlPayloadConverter is used if this reference is not provided, and it
|
||||||
should be sufficient in most cases since it can convert from Node, Document, Source,
|
should be sufficient in most cases since it can convert from Node, Document, Source,
|
||||||
File, and String typed payloads. If you need to extend beyond the capabilities of
|
File, and String typed payloads. If you need to extend beyond the capabilities of
|
||||||
that default implementation, then an upstream Transformer is probably a better option
|
that default implementation, then an upstream Transformer is probably a better option
|
||||||
than providing a reference to a custom implementation of this strategy here.</para>
|
than providing a reference to a custom implementation of this strategy here.</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
<emphasis>Combination of SpEL and XPath expressions</emphasis>
|
<emphasis>Combination of SpEL and XPath expressions</emphasis>
|
||||||
@@ -439,7 +525,9 @@
|
|||||||
<para>
|
<para>
|
||||||
You can also combine Spring Expression Language (SpEL) expressions with XPath expression and configure
|
You can also combine Spring Expression Language (SpEL) expressions with XPath expression and configure
|
||||||
them using <code>expression</code> attribute:
|
them using <code>expression</code> attribute:
|
||||||
<programlisting language="xml"><![CDATA[int-xml:xpath-expression id="testExpression" expression="/person/@age * 2"/>]]></programlisting>
|
</para>
|
||||||
|
<programlisting language="xml"><![CDATA[<int-xml:xpath-expression id="testExpression" expression="/person/@age * 2"/>]]></programlisting>
|
||||||
|
<para>
|
||||||
In the above case the overall result of the expression will be the result of the XPath expression multiplied by 2.
|
In the above case the overall result of the expression will be the result of the XPath expression multiplied by 2.
|
||||||
</para>
|
</para>
|
||||||
</section>
|
</section>
|
||||||
@@ -453,6 +541,7 @@
|
|||||||
<xpath-expression/> element. So the following configurations of an xpath-selector are all valid and represent the general
|
<xpath-expression/> element. So the following configurations of an xpath-selector are all valid and represent the general
|
||||||
form of XPath namespace support. All forms of XPath expression result in the creation of an
|
form of XPath namespace support. All forms of XPath expression result in the creation of an
|
||||||
<interfacename>XPathExpression</interfacename> using the Spring <classname>XPathExpressionFactory</classname>
|
<interfacename>XPathExpression</interfacename> using the Spring <classname>XPathExpressionFactory</classname>
|
||||||
|
</para>
|
||||||
<programlisting language="xml"><![CDATA[<int-xml:xpath-selector id="xpathRefSelector"
|
<programlisting language="xml"><![CDATA[<int-xml:xpath-selector id="xpathRefSelector"
|
||||||
xpath-expression="refToXpathExpression"
|
xpath-expression="refToXpathExpression"
|
||||||
evaluation-result-type="boolean" />
|
evaluation-result-type="boolean" />
|
||||||
@@ -484,10 +573,11 @@
|
|||||||
<util:entry key="ns1" value="www.example.org/one" />
|
<util:entry key="ns1" value="www.example.org/one" />
|
||||||
<util:entry key="ns2" value="www.example.org/two" />
|
<util:entry key="ns2" value="www.example.org/two" />
|
||||||
</util:map>]]></programlisting>
|
</util:map>]]></programlisting>
|
||||||
</para>
|
|
||||||
<para>
|
<para>
|
||||||
XPath splitter namespace support allows the creation of a Message Endpoint with an input channel and output channel.
|
XPath splitter namespace support allows the creation of a Message Endpoint with an input channel and output channel.
|
||||||
<programlisting language="xml"><![CDATA[<!-- Split the order into items creating a new message for each item node -->
|
</para>
|
||||||
|
<programlisting language="xml"><![CDATA[<!-- Split the order into items creating a new message for each item node -->
|
||||||
<int-xml:xpath-splitter id="orderItemSplitter"
|
<int-xml:xpath-splitter id="orderItemSplitter"
|
||||||
input-channel="orderChannel"
|
input-channel="orderChannel"
|
||||||
output-channel="orderItemsChannel">
|
output-channel="orderItemsChannel">
|
||||||
@@ -502,7 +592,7 @@
|
|||||||
<int-xml:xpath-expression expression="/order/items"/>
|
<int-xml:xpath-expression expression="/order/items"/>
|
||||||
<int:poller fixed-rate="2000"/>
|
<int:poller fixed-rate="2000"/>
|
||||||
</int-xml:xpath-splitter>]]></programlisting>
|
</int-xml:xpath-splitter>]]></programlisting>
|
||||||
</para>
|
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
</chapter>
|
</chapter>
|
||||||
|
|||||||
BIN
docs/src/reference/resources/images/tickmark.png
Normal file
BIN
docs/src/reference/resources/images/tickmark.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.0 KiB |
@@ -51,8 +51,8 @@
|
|||||||
<xsd:annotation>
|
<xsd:annotation>
|
||||||
<xsd:documentation><![CDATA[
|
<xsd:documentation><![CDATA[
|
||||||
Provides reference to bean that implements org.springframework.core.task.TaskExecutor to use when dispatching Messages
|
Provides reference to bean that implements org.springframework.core.task.TaskExecutor to use when dispatching Messages
|
||||||
to this channel's subscribers. Also, when using a TaskExecutor.
|
to this channel's subscribers. Also, when using a TaskExecutor,
|
||||||
Keep in mind that any transaction active for the sender will NOT propagate to the handler invocation since the
|
keep in mind that any transaction active for the sender will NOT propagate to the handler invocation since the
|
||||||
TaskExecutor dispatches to the handler on a separate Thread.
|
TaskExecutor dispatches to the handler on a separate Thread.
|
||||||
Usually configured using 'task' namespace support provided by Spring (e.g., <task:executor/>)
|
Usually configured using 'task' namespace support provided by Spring (e.g., <task:executor/>)
|
||||||
]]></xsd:documentation>
|
]]></xsd:documentation>
|
||||||
@@ -282,8 +282,8 @@
|
|||||||
<xsd:annotation>
|
<xsd:annotation>
|
||||||
<xsd:documentation><![CDATA[
|
<xsd:documentation><![CDATA[
|
||||||
Provides reference to bean that implements org.springframework.core.task.TaskExecutor to use when dispatching Messages
|
Provides reference to bean that implements org.springframework.core.task.TaskExecutor to use when dispatching Messages
|
||||||
to this channel's subscribers. Also, when using a TaskExecutor.
|
to this channel's subscribers. Also, when using a TaskExecutor,
|
||||||
Keep in mind that any transaction active for the sender will NOT propagate to the handler invocation since the
|
keep in mind that any transaction active for the sender will NOT propagate to the handler invocation since the
|
||||||
TaskExecutor dispatches to the handler on a separate Thread.
|
TaskExecutor dispatches to the handler on a separate Thread.
|
||||||
Usually configured using 'task' namespace support provided by Spring (e.g., <task:executor/>)
|
Usually configured using 'task' namespace support provided by Spring (e.g., <task:executor/>)
|
||||||
]]></xsd:documentation>
|
]]></xsd:documentation>
|
||||||
@@ -327,8 +327,8 @@
|
|||||||
<xsd:documentation>
|
<xsd:documentation>
|
||||||
<![CDATA[
|
<![CDATA[
|
||||||
Provides reference to bean that implements org.springframework.core.task.TaskExecutor to use when dispatching Messages
|
Provides reference to bean that implements org.springframework.core.task.TaskExecutor to use when dispatching Messages
|
||||||
to this channel's subscribers. Also, when using a TaskExecutor.
|
to this channel's subscribers. Also, when using a TaskExecutor,
|
||||||
Keep in mind that any transaction active for the sender will NOT propagate to the handler invocation since the
|
keep in mind that any transaction active for the sender will NOT propagate to the handler invocation since the
|
||||||
TaskExecutor dispatches to the handler on a separate Thread.
|
TaskExecutor dispatches to the handler on a separate Thread.
|
||||||
Usually configured using 'task' namespace support provided by Spring (e.g., <task:executor/>)
|
Usually configured using 'task' namespace support provided by Spring (e.g., <task:executor/>)
|
||||||
]]>
|
]]>
|
||||||
@@ -485,7 +485,7 @@
|
|||||||
<xsd:annotation>
|
<xsd:annotation>
|
||||||
<xsd:documentation>
|
<xsd:documentation>
|
||||||
<![CDATA[
|
<![CDATA[
|
||||||
Identifies channel this gateway will subscribe to to recieve reply Message.
|
Identifies channel this gateway will subscribe to to receive reply Message.
|
||||||
The reply Message which will then be converted to the return type of the method signature.
|
The reply Message which will then be converted to the return type of the method signature.
|
||||||
]]>
|
]]>
|
||||||
</xsd:documentation>
|
</xsd:documentation>
|
||||||
@@ -550,7 +550,7 @@
|
|||||||
<xsd:annotation>
|
<xsd:annotation>
|
||||||
<xsd:documentation>
|
<xsd:documentation>
|
||||||
<![CDATA[
|
<![CDATA[
|
||||||
Identifies default channel this gateway will subscribe to to recieve reply Messages, which will then be
|
Identifies default channel this gateway will subscribe to to receive reply Messages, which will then be
|
||||||
converted to the return type of the method signature.
|
converted to the return type of the method signature.
|
||||||
]]>
|
]]>
|
||||||
</xsd:documentation>
|
</xsd:documentation>
|
||||||
@@ -2500,7 +2500,10 @@ endpoint itself is a Polling Consumer for a channel with a queue.
|
|||||||
<xsd:attribute name="id" type="xsd:string">
|
<xsd:attribute name="id" type="xsd:string">
|
||||||
<xsd:annotation>
|
<xsd:annotation>
|
||||||
<xsd:documentation><![CDATA[Identifies the underlying Spring bean
|
<xsd:documentation><![CDATA[Identifies the underlying Spring bean
|
||||||
definition (EventDrivenConsumer).
|
definition which in case of Routers is an instance of
|
||||||
|
EventDrivenConsumer or PollingConsumer depending on whether
|
||||||
|
the Router's "input-channel" is a "SubscribableChannel" or
|
||||||
|
"PollableChannel", respectively. This is an "optional" attribute.
|
||||||
]]></xsd:documentation>
|
]]></xsd:documentation>
|
||||||
</xsd:annotation>
|
</xsd:annotation>
|
||||||
</xsd:attribute>
|
</xsd:attribute>
|
||||||
|
|||||||
Reference in New Issue
Block a user