You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by balkishore <ba...@gmail.com> on 2012/09/26 10:03:20 UTC

Getting a node from an XML using camel-cxf

Hi,
I wanted to extract a term from my soap message, I tried using Xpath but, no
matter what I try i always use to get an error: Invalid xpath expression. So
i decided to take help of CXF.

I came up with something like this:

CxfPayload<SoapHeader> payload = exchange.getIn().getBody(CxfPayload.class);
List<SoapHeader> headers = payload.getHeaders();

how how can i get the required element from the header? As now I have my
header stored in a list headers.
I tried to use 

headers.get(), but it's asking me to specify the index as argument.

What is an index and how would i determine the index of my term?

my SOAP message is as follow:

<?xml version="1.0" encoding="http://schemas.xmlsoap.org/soap/envelope/"
standalone="no"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">
<wsa:ReplyTo>
<wsa:Address>http://www.w3.org/2005/08/addressing/none</wsa:Address>
<wsa:ReferenceParameters>
<axis2:ServiceGroupId
xmlns:axis2="http://ws.apache.org/namespaces/axis2">urn:uuid:2BC5F552AF3179755C1348038695049</axis2:ServiceGroupId>
</wsa:ReferenceParameters>
</wsa:ReplyTo>
<wsa:MessageID>urn:uuid:2BC5F552AF3179755C1348038695050</wsa:MessageID>
<wsa:Action>some action to perform</wsa:Action>
<wsa:RelatesTo>urn:uuid:599362E68F35A38AFA1348038694466</wsa:RelatesTo>
</soapenv:Header>
<soapenv:Body>
<ns1:TCAQSR_BAS_ServerGetOsVariableOutput
xmlns:ns1="http://www.transcat-plm.com/TCAQSRBase/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:type="ns1:TCAQSR_BAS_ServerGetOsVariableOutputType">
<ns1:TCAQSR_BAS_BaseOutputServiceReturnCode>0</ns1:TCAQSR_BAS_BaseOutputServiceReturnCode>
<ns1:TCAQSR_BAS_BaseOutputServiceTxtMessage>TCAQSRBaseService
2.2.1</ns1:TCAQSR_BAS_BaseOutputServiceTxtMessage>
<ns1:TCAQSR_BAS_BaseServerGetOutputVal>PCSW13</ns1:TCAQSR_BAS_BaseServerGetOutputVal>
</ns1:TCAQSR_BAS_ServerGetOsVariableOutput>
</soapenv:Body>
</soapenv:Envelope>

I would like to extract urn:uuid:2BC5F552AF3179755C1348038695049 from the
serviceGroupID node. what index should i specify in this case?



--
View this message in context: http://camel.465427.n5.nabble.com/Getting-a-node-from-an-XML-using-camel-cxf-tp5720008.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Getting a node from an XML using camel-cxf

Posted by Claus Ibsen <cl...@gmail.com>.
On Wed, Oct 3, 2012 at 9:33 PM, Christian Müller
<ch...@gmail.com> wrote:
> E.g. convert the body into a dom, sax or stax source and do whatever you
> need to do.
>

Yes or use some XPath API to grab whatever you need. In fact you can
use the @XPath bean parameter binding if you want Camel to do that for
you.

Or just grab the XPathBuilder API and use that. Or use the vanilla
XPath API from the JDK.


> Best,
> Christian
>
> Sent from a mobile device
> Am 02.10.2012 23:46 schrieb "suralk" <su...@yahoo.com>:
>
>> Hi Christian,
>> I am using the Camel CXF component with the MESSAGE dataFormat (using
>> PAYLOAD throws an exception, so have to stick with MESSAGE format with
>> respect to this particular web service).
>>
>> Similar to balkishore, I do not want to set any header based on the
>> extracted soap element. Rather, I want to extract out these soap elements
>> and use them for some other processing work. However, as I understand,
>> XPath
>> or XQuery do not support this. They can only be used to set headers, or as
>> filter conditions.
>> In this context, what options do we have to extract out elements in the
>> soap
>> response in MESSAGE mode?
>> I currently convert the response explicitly to an xml file, but this is not
>> very elegant.
>>
>>
>>
>>
>> --
>> View this message in context:
>> http://camel.465427.n5.nabble.com/Getting-a-node-from-an-XML-using-camel-cxf-tp5720008p5720401.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: Getting a node from an XML using camel-cxf

Posted by Christian Müller <ch...@gmail.com>.
E.g. convert the body into a dom, sax or stax source and do whatever you
need to do.

Best,
Christian

Sent from a mobile device
Am 02.10.2012 23:46 schrieb "suralk" <su...@yahoo.com>:

> Hi Christian,
> I am using the Camel CXF component with the MESSAGE dataFormat (using
> PAYLOAD throws an exception, so have to stick with MESSAGE format with
> respect to this particular web service).
>
> Similar to balkishore, I do not want to set any header based on the
> extracted soap element. Rather, I want to extract out these soap elements
> and use them for some other processing work. However, as I understand,
> XPath
> or XQuery do not support this. They can only be used to set headers, or as
> filter conditions.
> In this context, what options do we have to extract out elements in the
> soap
> response in MESSAGE mode?
> I currently convert the response explicitly to an xml file, but this is not
> very elegant.
>
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Getting-a-node-from-an-XML-using-camel-cxf-tp5720008p5720401.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Re: Getting a node from an XML using camel-cxf

Posted by suralk <su...@yahoo.com>.
Hi Christian,
I am using the Camel CXF component with the MESSAGE dataFormat (using
PAYLOAD throws an exception, so have to stick with MESSAGE format with
respect to this particular web service). 

Similar to balkishore, I do not want to set any header based on the
extracted soap element. Rather, I want to extract out these soap elements
and use them for some other processing work. However, as I understand, XPath
or XQuery do not support this. They can only be used to set headers, or as
filter conditions.
In this context, what options do we have to extract out elements in the soap
response in MESSAGE mode?
I currently convert the response explicitly to an xml file, but this is not
very elegant. 




--
View this message in context: http://camel.465427.n5.nabble.com/Getting-a-node-from-an-XML-using-camel-cxf-tp5720008p5720401.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Getting a node from an XML using camel-cxf

Posted by Raul Kripalani <ra...@evosent.com>.
Hi Sura,

The description of the ticket was a bit too generic, so I had to close it.
In a Camel processor, you can already give whatever treatment you wish to
the SOAP Payload, as it's standard Java code.

I opened another ticket CAMEL-5680 (Create a set/assign DSL where the
target is determined by an expression) [1], to track the idea.

[1] https://issues.apache.org/jira/browse/CAMEL-5680

Regards,
Raúl.

On Tue, Oct 2, 2012 at 11:33 PM, Sura Monday <su...@yahoo.com> wrote:

> I have created a feature request now:
> https://issues.apache.org/jira/browse/CAMEL-5679
>
>
>
>
> ________________________________
>  From: Raul Kripalani <ra...@evosent.com>
> To: users@camel.apache.org
> Sent: Wednesday, October 3, 2012 11:06 AM
> Subject: Re: Getting a node from an XML using camel-cxf
>
> I can't think of a Camel functionality that will allow you to store the
> result in a HashMap entry out-of-the-box. You'll have to handle this inside
> a bean or script for now.
>
> Feel free to open a ticket in our JIRA to request this feature [1]. Maybe
> we could create a new type of "setXYZ" DSL that allows you to pick the
> destination based on an expression. Just an idea...
>
> [1] https://issues.apache.org/jira/browse/CAMEL
>
> Regards,
>
> --
> *Raúl Kripalani*
> Apache Camel Committer
> Enterprise Architect, Program Manager, Open Source Integration specialist
> http://about.me/raulkripalani | http://www.linkedin.com/in/raulkripalani
> http://blog.raulkr.net | twitter: @raulvk <http://twitter.com/raulvk>
>
> On Thu, Sep 27, 2012 at 12:00 PM, balkishore <balkishore.pandey@gmail.com
> >wrote:
>
> > Hi Raul,
> > Thanks for replying.
> > But for saving the extracted element, I use a Hashmap.
> > I just want to extract the element and store it in the Hashmap and not in
> > the header itself.
> >
> >
> >
> >
> > --
> > View this message in context:
> >
> http://camel.465427.n5.nabble.com/Getting-a-node-from-an-XML-using-camel-cxf-tp5720008p5720115.html
> > Sent from the Camel - Users mailing list archive at Nabble.com.
> >
>



-- 
*Raúl Kripalani*
Apache Camel Committer
Enterprise Architect, Program Manager, Open Source Integration specialist
mobile: +34 679 52 41 75
http://about.me/raulkripalani | http://www.linkedin.com/in/raulkripalani
http://blog.raulkr.net | twitter: @raulvk <http://twitter.com/raulvk>

Re: Getting a node from an XML using camel-cxf

Posted by Sura Monday <su...@yahoo.com>.
I have created a feature request now:
https://issues.apache.org/jira/browse/CAMEL-5679




________________________________
 From: Raul Kripalani <ra...@evosent.com>
To: users@camel.apache.org 
Sent: Wednesday, October 3, 2012 11:06 AM
Subject: Re: Getting a node from an XML using camel-cxf
 
I can't think of a Camel functionality that will allow you to store the
result in a HashMap entry out-of-the-box. You'll have to handle this inside
a bean or script for now.

Feel free to open a ticket in our JIRA to request this feature [1]. Maybe
we could create a new type of "setXYZ" DSL that allows you to pick the
destination based on an expression. Just an idea...

[1] https://issues.apache.org/jira/browse/CAMEL

Regards,

-- 
*Raúl Kripalani*
Apache Camel Committer
Enterprise Architect, Program Manager, Open Source Integration specialist
http://about.me/raulkripalani | http://www.linkedin.com/in/raulkripalani
http://blog.raulkr.net | twitter: @raulvk <http://twitter.com/raulvk>

On Thu, Sep 27, 2012 at 12:00 PM, balkishore <ba...@gmail.com>wrote:

> Hi Raul,
> Thanks for replying.
> But for saving the extracted element, I use a Hashmap.
> I just want to extract the element and store it in the Hashmap and not in
> the header itself.
>
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Getting-a-node-from-an-XML-using-camel-cxf-tp5720008p5720115.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Re: Getting a node from an XML using camel-cxf

Posted by Raul Kripalani <ra...@evosent.com>.
I can't think of a Camel functionality that will allow you to store the
result in a HashMap entry out-of-the-box. You'll have to handle this inside
a bean or script for now.

Feel free to open a ticket in our JIRA to request this feature [1]. Maybe
we could create a new type of "setXYZ" DSL that allows you to pick the
destination based on an expression. Just an idea...

[1] https://issues.apache.org/jira/browse/CAMEL

Regards,

-- 
*Raúl Kripalani*
Apache Camel Committer
Enterprise Architect, Program Manager, Open Source Integration specialist
http://about.me/raulkripalani | http://www.linkedin.com/in/raulkripalani
http://blog.raulkr.net | twitter: @raulvk <http://twitter.com/raulvk>

On Thu, Sep 27, 2012 at 12:00 PM, balkishore <ba...@gmail.com>wrote:

> Hi Raul,
> Thanks for replying.
> But for saving the extracted element, I use a Hashmap.
> I just want to extract the element and store it in the Hashmap and not in
> the header itself.
>
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Getting-a-node-from-an-XML-using-camel-cxf-tp5720008p5720115.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Re: Getting a node from an XML using camel-cxf

Posted by balkishore <ba...@gmail.com>.
Hi Raul,
Thanks for replying. 
But for saving the extracted element, I use a Hashmap.
I just want to extract the element and store it in the Hashmap and not in
the header itself.
 



--
View this message in context: http://camel.465427.n5.nabble.com/Getting-a-node-from-an-XML-using-camel-cxf-tp5720008p5720115.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Getting a node from an XML using camel-cxf

Posted by Raul Kripalani <ra...@evosent.com>.
When you extract the SOAP header, you surely want to store it somewhere.

Camel lets you store it in a message header, a property or you can
overwrite the body with the result of the expression. Use setHeader,
setProperty or setBody (or transform) accordingly.

I think if you use the CXF POJO or PAYLOAD dataFormats, you can access
relay the headers using the appropriate config in the HeaderFilterStrategy.
But that's a different story altogether.

Regards,
Raúl.

Sent from a mobile device
On Sep 27, 2012 9:18 AM, "balkishore" <ba...@gmail.com> wrote:

> Hi Lars,
> I would like to get that element, and not to set my header. If i am not
> wrong, i cannot use, xpath along with getHeader() expression.
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Getting-a-node-from-an-XML-using-camel-cxf-tp5720008p5720085.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Re: Getting a node from an XML using camel-cxf

Posted by balkishore <ba...@gmail.com>.
Hi Lars,
I would like to get that element, and not to set my header. If i am not
wrong, i cannot use, xpath along with getHeader() expression.



--
View this message in context: http://camel.465427.n5.nabble.com/Getting-a-node-from-an-XML-using-camel-cxf-tp5720008p5720085.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Getting a node from an XML using camel-cxf

Posted by Lars Lipinski <de...@lipinski.it>.
if you had errors in your XPath expression, maybe you didn't take care of the
namespaces?
Here's an example in Java DSL how to extract text content of a node into a
header:

.setHeader( "ExtractedServiceGroupId",
xpath("//axis2:ServiceGroupId/text()").namespace("axis2",
"http://ws.apache.org/namespaces/axis2").stringResult() )


I have to admit, that I needed a while to figure out the use of the method
"stringResult()".
After reading some examples of xpath expression for Java DSL I expected to
be allowed to put an additional argument "String.class" for the result type,
but it's not offered in the API here.

regards.
Lars




--
View this message in context: http://camel.465427.n5.nabble.com/Getting-a-node-from-an-XML-using-camel-cxf-tp5720008p5720077.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Getting a node from an XML using camel-cxf

Posted by Christian Müller <ch...@gmail.com>.
Use the Apache Camel CXF component [1] with the MESSAGE dataFormat to
receive the request. Afterwards you can use the XPath [2] or XQuery
component to retrieve the needed data. Something like

    <route>
        <from uri="cxf:bean:cbrProxy" />
        <setHeader headerName="theHeaderName">
            <xpath
resultType="java.lang.String">/soapenv:Envelope/soapenv:Header/wsa:MessageID</xpath>
        </setHeader>
    </route>

[1] http://camel.apache.org/cxf.html
[2] http://camel.apache.org/xpath.html
[3] http://camel.apache.org/xquery.html

Best,
Christian

On Wed, Sep 26, 2012 at 10:03 AM, balkishore <ba...@gmail.com>wrote:

> Hi,
> I wanted to extract a term from my soap message, I tried using Xpath but,
> no
> matter what I try i always use to get an error: Invalid xpath expression.
> So
> i decided to take help of CXF.
>
> I came up with something like this:
>
> CxfPayload<SoapHeader> payload =
> exchange.getIn().getBody(CxfPayload.class);
> List<SoapHeader> headers = payload.getHeaders();
>
> how how can i get the required element from the header? As now I have my
> header stored in a list headers.
> I tried to use
>
> headers.get(), but it's asking me to specify the index as argument.
>
> What is an index and how would i determine the index of my term?
>
> my SOAP message is as follow:
>
> <?xml version="1.0" encoding="http://schemas.xmlsoap.org/soap/envelope/"
> standalone="no"?>
> <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/
> ">
> <soapenv:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">
> <wsa:ReplyTo>
> <wsa:Address>http://www.w3.org/2005/08/addressing/none</wsa:Address>
> <wsa:ReferenceParameters>
> <axis2:ServiceGroupId
> xmlns:axis2="http://ws.apache.org/namespaces/axis2
> ">urn:uuid:2BC5F552AF3179755C1348038695049</axis2:ServiceGroupId>
> </wsa:ReferenceParameters>
> </wsa:ReplyTo>
> <wsa:MessageID>urn:uuid:2BC5F552AF3179755C1348038695050</wsa:MessageID>
> <wsa:Action>some action to perform</wsa:Action>
> <wsa:RelatesTo>urn:uuid:599362E68F35A38AFA1348038694466</wsa:RelatesTo>
> </soapenv:Header>
> <soapenv:Body>
> <ns1:TCAQSR_BAS_ServerGetOsVariableOutput
> xmlns:ns1="http://www.transcat-plm.com/TCAQSRBase/"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:type="ns1:TCAQSR_BAS_ServerGetOsVariableOutputType">
>
> <ns1:TCAQSR_BAS_BaseOutputServiceReturnCode>0</ns1:TCAQSR_BAS_BaseOutputServiceReturnCode>
> <ns1:TCAQSR_BAS_BaseOutputServiceTxtMessage>TCAQSRBaseService
> 2.2.1</ns1:TCAQSR_BAS_BaseOutputServiceTxtMessage>
>
> <ns1:TCAQSR_BAS_BaseServerGetOutputVal>PCSW13</ns1:TCAQSR_BAS_BaseServerGetOutputVal>
> </ns1:TCAQSR_BAS_ServerGetOsVariableOutput>
> </soapenv:Body>
> </soapenv:Envelope>
>
> I would like to extract urn:uuid:2BC5F552AF3179755C1348038695049 from the
> serviceGroupID node. what index should i specify in this case?
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Getting-a-node-from-an-XML-using-camel-cxf-tp5720008.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



--