I started out using the si-xml:xpath-router but I ran into a roadblock. Am I using correct router but wrong implementation? If I'm using the incorrect router, which one should I be using, i.e. default router, payload-type, or maybe a simple SpEL expression?
Use Case:
I need to route a message based on payload content. The request contains an element and the 'action' I need to perform is contained in one if its attributes, see attribute "command" below.
Example inbound request (comes from a web-service).
<Request>
<Records>
<Record>
<data key="name" value="Jack Bauer" />
<data key="command" value="sendSMS" />
</Record>
</Records>
</Request>
The psuedocode was:
- marshall message.
- route based on value, via xpath-router
but I'm getting the error:
unsupported payload type [javax.xml.transform.dom.DOMResult]
In order to resolve this, I have tried:
adding the attribute "result-transformer" to the transformer bean using ResultToDocumentTransformer. error= failed to resolve channel name ''
adding attribute "result-type" to the transformer using StringResult. error = unsupported payload type [org.springframework.xml.transform.StringResult]
adding both of the above. error = failed to resolve channel name ''
adding the attribute "evaluate-as-string" using true. error = unsupported payload type.
Original Configuration file below:
<gateway id="gateway" default-request-channel="requestChannel"
service-interface="foo.SomeClass" />
<beans:bean id="marshaller"
class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
<beans:property name="classesToBeBound">
<beans:list>
<beans:value>com.foo.Request</beans:value>
<beans:value>com.foo.Record</beans:value>
<beans:value>com.foo.Data</beans:value>
</beans:list>
</beans:property>
</beans:bean>
<chain input-channel="requestChannel">
<poller max-messages-per-poll="10" task-executor="executor">
<interval-trigger interval="5000" />
</poller>
<si-xml:marshalling-transformer marshaller="marshaller"/>
<si-xml:xpath-router id="instockRouter" resolution-required="true">
<si-xml:xpath-expression expression="/Request/Records/Record/data[@key='command']"/>
<si-xml:mapping value="sendSMS" channel="SMSChannel"/>
</si-xml:xpath-route开发者_StackOverflow社区r>
</chain>
<task:executor id="executor" pool-size="8"/>
You can use Spring's "=object-to-string-transformer />"
after marshalling.
From what I can see:
- Message comes into gateway which forwards it to the requestChannel
- requestChannel processing is forwarded into chain, which in first step marshall object using
org.springframework.oxm.jaxb.Jaxb2Marshaller
intojavax.xml.transform.dom.DOMResult
- When your payload is of
DOMResult
type you try to use xpath-router.
As far as I know, XPath router works fine if message payload is String type containing plain XML inside. So I would recommend to do not marshall your message before using xpath router, but to use xpath router first.
If you will marshall the object, it will be DOMResult
type and you will have to deal with DOMResult
(sad but true :))
...anyway I think that DOMResult is not what you want to have as a message payload - maybe you did a mistake between marshalling and unmarshalling?
精彩评论