Announcement Announcement Module
No announcement yet.
XPathSingleChannelRouter fails to convert DOMSource to Node Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • XPathSingleChannelRouter fails to convert DOMSource to Node


    I am coding a POC for the Spring Integration project.
    I am calling a WS with XML payload (String and Document tried) on my server which is implementing a simpleGateway

    	<ws:inbound-gateway id="simpleGateway"
    Then I am trying to use the simpleRouter to route the messages into channels

    	<si-xml:xpath-router id="aRouter" input-channel="inputChannel" multi-channel="false">
    	    <si-xml:xpath-expression expression="/aRequest/someVal/anotherVal"/>
    this is producing the following error :
    DEBUG: org.springframework.integration.xml.router.XPathSingleChannelRouter - org.[email protected]e2b9e5 received message: [[email protected]][Headers={springintegration_id=8c6c39e8-3ff5-4759-9499-41fee0a9b67d, springintegration_timestamp=1254832382109, springintegration_replyChannel=org.springframework.i[email protected]72edc, springintegration_errorChannel=org.springframework.i[email protected]72edc}]
    DEBUG: - Endpoint invocation resulted in exception - responding with Fault
    org.springframework.integration.core.MessagingException: unsupported payload type [javax.xml.transform.dom.DOMSource]
    	at org.springframework.integration.xml.DefaultXmlPayloadConverter.convertToDocument(
    	at org.springframework.integration.xml.DefaultXmlPayloadConverter.convertToNode(
    	at org.springframework.integration.xml.router.XPathSingleChannelRouter.getChannelIndicatorList(
    	at org.springframework.integration.router.AbstractChannelNameResolvingMessageRouter.determineTargetChannels(
    	at org.springframework.integration.router.AbstractMessageRouter.handleMessageInternal(
    	at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(
    	at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(
    	at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(
    I believe the DOMSource should be used and the getNode() method called to get the Node object. Is this a bug? or am I missing a step.


  • #2
    At the moment Spring Integration doesn't support Source as a payload for the xml support. You can do something yourself quite easily, but from a framework point of view it is not smart to support things that can be linked to an InputStream.

    Of course if you have arguments against this policy we'd be very glad to hear them.


    • #3
      Thanks Iwen, Sounds like a sound reason, however I was just linking up XML
      through a WS,

      I assumed that after bringing the XML into the si world I would then be able to use the XPATH routing.

      I did code a converter to call the DOMSource.getNode(), which seemed to work, although the XPATH query always return a null/empty string, which maybe because the source document was SOAP based??


      • #4
        The XPath routers use the DefaultXmlPayloadConverter which as Iwein says does not support sources however for the case where we are converting to a Node it seems so trivial that we should. I have created INT-835


        • #5
          As to why you are getting nulls, namespaces? Your example Xpath expression assumes everything is in the default namespace. Is that really the case?

          You might want to take a look at the reference docs on how to configure XML namespaces for the XPath support



          • #6
            solution (work-around)

            Just to confirm that the following solution / workaround did work.

            My Null XPATH resposes were because I thought the XML payload root should start with single slash / but there must be some other root in play (from WS)

            	<!-- Expects a channel for each value of order type to exist 
            		second attempt when above causing DOMSource issue, so used my own converter -->
            	<bean id="singleChannelRoutingEndpoint"
            	        <bean class="org.springframework.integration.xml.router.XPathSingleChannelRouter">
            	            <constructor-arg value="//theNs:aXMLRootRequest/theNs:some/theNs:stuff" /> 
            	            <constructor-arg ref="theNamespaceMap" />   
            	            <property name="converter" ref="domHomeMadeConverter"/>
            		<constructor-arg ref="inputChannel" />
            The converter just extends DefaultXmlPayloadConverter and performs the following
            	public Node convertToNode(Object object) {
            		if (object instanceof DOMSource){
            			Node node = ((DOMSource)object).getNode();
            			return node;
            		return super.convertToNode(object);


            • #7
              Glad you worked out the Xpath expression issue.

              This issue with DOMSource is now fixed in head and will be part of 2.0 M1 release.