You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by contactreji <co...@gmail.com> on 2014/03/26 06:03:02 UTC
Issue with SetHeader / Xpath
Hi
Would be nice if you guys can help me with the proper way os using Xpath in
Spring DSL
I am trying to extract a value from incomign XML file using Xpath and trying
to set it to header. The route is as follows
*
<route id="b2mml_ftp_pickup">
<from
uri="ftp://{{ftpUser}}@{{ftpHost}}{{path}}?password={{ftpPassword}}&move=/in/b2mml/arc"
/>
<log message="Received file ${file:name} from MES" />
<convertBodyTo type="java.lang.String">
<description><from uri="file://D:/input"/></description>
</convertBodyTo>
<setHeader headerName="ID">
<xpath
resultType="java.lang.String">//ProductionResponse/ProductionRequestID/text()</xpath>
</setHeader>
<log message="The ID extracted is ${in.header.ID}" />
<to uri="activemq:processXML" />
</route>*
Unfortunately the output doesn't contain the extracted value. The output is
as follows.
2014-03-26 06:59:30,141 [0sreao/in/b2mml] INFO b2mml_ftp_pickup
- Received file ProductionPerformance1 (1).xml from MES
2014-03-26 06:59:30,152 [0sreao/in/b2mml] INFO XPathBuilder
- Created default XPathFactory
com.sun.org.apache.xpath.internal.jaxp.XPathFactoryImpl@1c3820e3
2014-03-26 06:59:30,200 [0sreao/in/b2mml] INFO b2mml_ftp_pickup
- *The ID extracted is *
2014-03-26 06:59:30,799 [mer[processXML]] INFO b2mml_FileBody_JavaObject
- Converting following XML into Java Object for mapping <?xml version="1.0"
encoding="UTF-8" standalone="yes"?>
The incoming XML is
<?xml version="1.0" encoding="utf-8"?><ProductionPerformance
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:Extended="http://www.wbf.org/xml/B2MML-V0401-AllExtensions"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.wbf.org/xml/B2MML-V0401"><ID>PERFORMANCE_1</ID><PublishedDate>2014-03-19T07:18:19.2099611Z</PublishedDate><ProductionResponse><ID
/><ProductionRequestID>2.38</ProductionRequestID><StartTime>2013-07-15T10:39:49.69</StartTime><EndTime>2013-07-15T10:00:00</EndTime></ProductionResponse><ProductionResponse><ID
/><ProductionRequestID>2.38</ProductionRequestID><StartTime>2013-07-15T10:39:49.69</StartTime><EndTime>2013-07-15T10:00:00</EndTime></ProductionResponse><ProductionResponse><ID
/><ProductionRequestID>2.38</ProductionRequestID><StartTime>2013-07-15T10:39:49.69</StartTime><EndTime>2013-07-15T10:00:00</EndTime></ProductionResponse></ProductionPerformance>
--
View this message in context: http://camel.465427.n5.nabble.com/Issue-with-SetHeader-Xpath-tp5749368.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Issue with SetHeader / Xpath
Posted by Christian Müller <ch...@gmail.com>.
I suggest adding the camel-saxon dependency and use:
<xpath saxon="true">...</xpath>
Best,
Christian
-----------------
Software Integration Specialist
Apache Member
V.P. Apache Camel | Apache Camel PMC Member | Apache Camel committer
Apache Incubator PMC Member
https://www.linkedin.com/pub/christian-mueller/11/551/642
On Fri, Aug 7, 2015 at 7:01 PM, anish.somadevan <ne...@gmail.com> wrote:
> I have a similar issue
>
>
>
> My XML is
>
> <CamelData>
> <Provider>ProviderValue</Provider>
> </CamelData>
>
> And am trying to set header value like this,
>
> <SetHeader headerName = "Provider">
> <xpath>/CamelData/Provider/text()</xpath>
> </setHeader>
>
> But i get this error.
>
> Exhausted after delivery attempt: 1 caught: java.lang.ClassCastException:
> org.apache.xml.dtm.ref.DTMManagerDefault cannot be cast to
> org.apache.xml.dtm.DTMManager: java.lang.ClassCastException:
> org.apache.xml.dtm.ref.DTMManagerDefault cannot be cast to
> org.apache.xml.dtm.DTMManager
> at org.apache.xml.dtm.DTMManager.newInstance(DTMManager.java:137)
> [xalan.jar:]
> at org.apache.xpath.XPathContext.<init>(XPathContext.java:102)
> [xalan.jar:]
> at org.apache.xpath.XPathContext.<init>(XPathContext.java:349)
> [xalan.jar:]
> at
>
> org.apache.xpath.jaxp.XPathExpressionImpl.eval(XPathExpressionImpl.java:113)
> at
> org.apache.xpath.jaxp.XPathExpressionImpl.eval(XPathExpressionImpl.java:99)
>
> Is there something that am missing?
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Issue-with-SetHeader-Xpath-tp5749368p5770441.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
Re: Issue with SetHeader / Xpath
Posted by "anish.somadevan" <ne...@gmail.com>.
I have a similar issue
My XML is
<CamelData>
<Provider>ProviderValue</Provider>
</CamelData>
And am trying to set header value like this,
<SetHeader headerName = "Provider">
<xpath>/CamelData/Provider/text()</xpath>
</setHeader>
But i get this error.
Exhausted after delivery attempt: 1 caught: java.lang.ClassCastException:
org.apache.xml.dtm.ref.DTMManagerDefault cannot be cast to
org.apache.xml.dtm.DTMManager: java.lang.ClassCastException:
org.apache.xml.dtm.ref.DTMManagerDefault cannot be cast to
org.apache.xml.dtm.DTMManager
at org.apache.xml.dtm.DTMManager.newInstance(DTMManager.java:137)
[xalan.jar:]
at org.apache.xpath.XPathContext.<init>(XPathContext.java:102)
[xalan.jar:]
at org.apache.xpath.XPathContext.<init>(XPathContext.java:349)
[xalan.jar:]
at
org.apache.xpath.jaxp.XPathExpressionImpl.eval(XPathExpressionImpl.java:113)
at
org.apache.xpath.jaxp.XPathExpressionImpl.eval(XPathExpressionImpl.java:99)
Is there something that am missing?
--
View this message in context: http://camel.465427.n5.nabble.com/Issue-with-SetHeader-Xpath-tp5749368p5770441.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Issue with SetHeader / Xpath
Posted by contactreji <co...@gmail.com>.
Thanks Claus :-) It worked!!
--
View this message in context: http://camel.465427.n5.nabble.com/Issue-with-SetHeader-Xpath-tp5749368p5750178.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Issue with SetHeader / Xpath
Posted by Claus Ibsen <cl...@gmail.com>.
Hi
You need to use namespace for your xpath expression. eg your namespace
is: http://www.wbf.org/xml/B2MML-V0401
See the "foo" namespace example at
http://camel.apache.org/xpath
On Wed, Mar 26, 2014 at 6:03 AM, contactreji <co...@gmail.com> wrote:
> Hi
>
> Would be nice if you guys can help me with the proper way os using Xpath in
> Spring DSL
>
> I am trying to extract a value from incomign XML file using Xpath and trying
> to set it to header. The route is as follows
> *
> <route id="b2mml_ftp_pickup">
> <from
>
> uri="ftp://{{ftpUser}}@{{ftpHost}}{{path}}?password={{ftpPassword}}&move=/in/b2mml/arc"
> />
> <log message="Received file ${file:name} from MES" />
> <convertBodyTo type="java.lang.String">
> <description><from uri="file://D:/input"/></description>
> </convertBodyTo>
>
> <setHeader headerName="ID">
> <xpath
> resultType="java.lang.String">//ProductionResponse/ProductionRequestID/text()</xpath>
> </setHeader>
> <log message="The ID extracted is ${in.header.ID}" />
> <to uri="activemq:processXML" />
> </route>*
>
>
> Unfortunately the output doesn't contain the extracted value. The output is
> as follows.
>
> 2014-03-26 06:59:30,141 [0sreao/in/b2mml] INFO b2mml_ftp_pickup
> - Received file ProductionPerformance1 (1).xml from MES
> 2014-03-26 06:59:30,152 [0sreao/in/b2mml] INFO XPathBuilder
> - Created default XPathFactory
> com.sun.org.apache.xpath.internal.jaxp.XPathFactoryImpl@1c3820e3
> 2014-03-26 06:59:30,200 [0sreao/in/b2mml] INFO b2mml_ftp_pickup
> - *The ID extracted is *
>
>
> 2014-03-26 06:59:30,799 [mer[processXML]] INFO b2mml_FileBody_JavaObject
> - Converting following XML into Java Object for mapping <?xml version="1.0"
> encoding="UTF-8" standalone="yes"?>
>
>
>
> The incoming XML is
>
>
> <?xml version="1.0" encoding="utf-8"?><ProductionPerformance
> xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> xmlns:Extended="http://www.wbf.org/xml/B2MML-V0401-AllExtensions"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns="http://www.wbf.org/xml/B2MML-V0401"><ID>PERFORMANCE_1</ID><PublishedDate>2014-03-19T07:18:19.2099611Z</PublishedDate><ProductionResponse><ID
> /><ProductionRequestID>2.38</ProductionRequestID><StartTime>2013-07-15T10:39:49.69</StartTime><EndTime>2013-07-15T10:00:00</EndTime></ProductionResponse><ProductionResponse><ID
> /><ProductionRequestID>2.38</ProductionRequestID><StartTime>2013-07-15T10:39:49.69</StartTime><EndTime>2013-07-15T10:00:00</EndTime></ProductionResponse><ProductionResponse><ID
> /><ProductionRequestID>2.38</ProductionRequestID><StartTime>2013-07-15T10:39:49.69</StartTime><EndTime>2013-07-15T10:00:00</EndTime></ProductionResponse></ProductionPerformance>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Issue-with-SetHeader-Xpath-tp5749368.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
--
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
Make your Camel applications look hawt, try: http://hawt.io