0

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-router>
</chain>

<task:executor id="executor" pool-size="8"/>
4

2 回答 2

2

"=object-to-string-transformer />"编组后可以使用 Spring 的。

于 2011-10-18T04:35:44.813 回答
0

据我所知:

  1. 消息进入网关,网关将其转发到 requestChannel
  2. requestChannel 处理被转发到链中,在第一步中将对象编组org.springframework.oxm.jaxb.Jaxb2Marshallerjavax.xml.transform.dom.DOMResult
  3. 当您的有效负载是DOMResult类型时,您尝试使用 xpath-router。

据我所知,如果消息有效负载是内部包含纯 XML 的字符串类型,则 XPath 路由器可以正常工作。所以我建议不要在使用 xpath 路由器之前整理您的消息,而是先使用 xpath 路由器。

如果您要编组对象,它将是DOMResult类型,您将不得不处理DOMResult(可悲但真实:))

...无论如何,我认为 DOMResult 不是您想要的消息负载 - 也许您在编组和解组之间犯了错误?

于 2011-08-04T15:49:33.973 回答