Results 1 to 7 of 7

Thread: XPathSingleChannelRouter fails to convert DOMSource to Node

  1. #1
    Join Date
    May 2007
    Posts
    12

    Default XPathSingleChannelRouter fails to convert DOMSource to Node

    Hello,

    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

    Code:
    	<ws:inbound-gateway id="simpleGateway"
                        request-channel="inputChannel"/>
    Then I am trying to use the simpleRouter to route the messages into channels

    Code:
    	<si-xml:xpath-router id="aRouter" input-channel="inputChannel" multi-channel="false">
    	    <si-xml:xpath-expression expression="/aRequest/someVal/anotherVal"/>
    	</si-xml:xpath-router>
    this is producing the following error :
    Code:
    DEBUG: org.springframework.integration.xml.router.XPathSingleChannelRouter - org.springframework.integration.xml.router.XPathSingleChannelRouter@e2b9e5 received message: [Payload=javax.xml.transform.dom.DOMSource@1386751][Headers={springintegration_id=8c6c39e8-3ff5-4759-9499-41fee0a9b67d, springintegration_timestamp=1254832382109, springintegration_replyChannel=org.springframework.integration.channel.MessageChannelTemplate$TemporaryReplyChannel@72edc, springintegration_errorChannel=org.springframework.integration.channel.MessageChannelTemplate$TemporaryReplyChannel@72edc}]
    DEBUG: org.springframework.ws.soap.server.SoapMessageDispatcher - 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(DefaultXmlPayloadConverter.java:66)
    	at org.springframework.integration.xml.DefaultXmlPayloadConverter.convertToNode(DefaultXmlPayloadConverter.java:73)
    	at org.springframework.integration.xml.router.XPathSingleChannelRouter.getChannelIndicatorList(XPathSingleChannelRouter.java:81)
    	at org.springframework.integration.router.AbstractChannelNameResolvingMessageRouter.determineTargetChannels(AbstractChannelNameResolvingMessageRouter.java:110)
    	at org.springframework.integration.router.AbstractMessageRouter.handleMessageInternal(AbstractMessageRouter.java:72)
    	at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:59)
    	at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:103)
    	at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:90)
    	at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:43)
    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.

    thanks
    Rob

  2. #2
    Join Date
    May 2007
    Location
    Netherlands
    Posts
    614

    Default

    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. #3
    Join Date
    May 2007
    Posts
    12

    Default

    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. #4
    Join Date
    Oct 2007
    Location
    London, England
    Posts
    108

    Default

    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
    Jonas Partner
    OpenCredo

  5. #5
    Join Date
    Oct 2007
    Location
    London, England
    Posts
    108

    Default

    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 http://static.springsource.org/sprin...espace-support.


    Jonas
    Jonas Partner
    OpenCredo

  6. #6
    Join Date
    May 2007
    Posts
    12

    Post 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)

    Code:
    	<!-- 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"
    	      class="org.springframework.integration.endpoint.EventDrivenConsumer">
    	    <constructor-arg>
    	        <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"/>
    	        </bean>
    	    </constructor-arg>
    		<constructor-arg ref="inputChannel" />
    	</bean>
    The converter just extends DefaultXmlPayloadConverter and performs the following
    Code:
    	public Node convertToNode(Object object) {
    		if (object instanceof DOMSource){
    			Node node = ((DOMSource)object).getNode();
    			return node;
    		}
    		return super.convertToNode(object);
    	}

  7. #7
    Join Date
    Oct 2007
    Location
    London, England
    Posts
    108

    Default

    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.

    Jonas
    Jonas Partner
    OpenCredo

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •