You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by siddhesh <si...@persistent.co.in> on 2015/06/19 20:36:13 UTC

Difficulty in extracting data from CxfPayload

Hi 

I have created soap webservice using CXFendpoint. I am trying to Mock
ParlayX getLoaction functionality. I have wsdl and have generated required
objects. My dataformat is payload. I am sending my input body as follows.

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:loc="http://www.csapi.org/schema/parlayx/terminal_location/v2_3/local">
   <soapenv:Header/>
   <soapenv:Body>
      <loc:getLocation>
         <loc:address>tel:+919420161556</loc:address>
         <loc:requestedAccuracy>100</loc:requestedAccuracy>
      </loc:getLocation>
   </soapenv:Body>
</soapenv:Envelope>

Inside my operation method, i get this body as CxfPayload. I am having hard
time to retrieve data like address, requestedAccuracy in my method. I tried
to use methods from CxfPayloadConverter but could not find anyway to extract
data from DOMSource or Element.  I tried manually un-marshaling xml that i
get from exchange.getIn().getBody(String.class) but no luck.

Any inputs on how i can extract data from payload ? 





--
View this message in context: http://camel.465427.n5.nabble.com/Difficulty-in-extracting-data-from-CxfPayload-tp5768422.html
Sent from the Camel - Users mailing list archive at Nabble.com.

RE: Difficulty in extracting data from CxfPayload

Posted by siddhesh <si...@persistent.co.in>.
Guys, I got it working. Cheers. 



--
View this message in context: http://camel.465427.n5.nabble.com/Difficulty-in-extracting-data-from-CxfPayload-tp5768422p5768508.html
Sent from the Camel - Users mailing list archive at Nabble.com.

RE: Difficulty in extracting data from CxfPayload

Posted by siddhesh <si...@persistent.co.in>.
Hi Stephen
When I use Document document = exchange.getIn().getBody(Document.class);  i
see document object content as follows
[#document: null]
any additional changes that will fix this ? 



--
View this message in context: http://camel.465427.n5.nabble.com/Difficulty-in-extracting-data-from-CxfPayload-tp5768422p5768475.html
Sent from the Camel - Users mailing list archive at Nabble.com.

RE: Difficulty in extracting data from CxfPayload

Posted by "Siano, Stephan" <st...@sap.com>.
Hi,
The error message indictes that you haven't passed a definition of the loc namespace prefix to the XPath.
Aside from that your code is rather inefficient. You are first mashalling your parsed XML document into a String, then instantiate a DOM parser to parse it as a DOM and finally apply an XPath expression on it.

You can avoid the former by doing a 
Document document = exchange.getIn().getBody(Document.class); instead of the first five lines of your code.

In your place I would do the XPath evaluation also as part of the Camel pipeline (e.g. store these values in some camel headers. See
http://camel.apache.org/xpath.html for details).

Best regards
Stephan

-----Original Message-----
From: siddhesh [mailto:siddhesh_deodhar@persistent.co.in] 
Sent: Montag, 22. Juni 2015 09:30
To: users@camel.apache.org
Subject: RE: Difficulty in extracting data from CxfPayload

Hi Siano, Thanks 

I tried this code 

String bodyStr = exchange.getIn().getBody(String.class);
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder;
builder = factory.newDocumentBuilder();
Document document = builder.parse(new InputSource(new
StringReader(bodyStr)));
XPath xPath = XPathFactory.newInstance().newXPath(); 

String address1 = xPath.evaluate("//loc:address/text()", document);
String address2 = xPath.evaluate("/loc:getLocation/loc:address", document);

but i get error when i try to access address in both ways using xpath
net.sf.saxon.trans.XPathException: Prefix loc has not been declared

Anything I am missing ? 



--
View this message in context: http://camel.465427.n5.nabble.com/Difficulty-in-extracting-data-from-CxfPayload-tp5768422p5768458.html
Sent from the Camel - Users mailing list archive at Nabble.com.

RE: Difficulty in extracting data from CxfPayload

Posted by siddhesh <si...@persistent.co.in>.
Hi Siano, Thanks 

I tried this code 

String bodyStr = exchange.getIn().getBody(String.class);
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder;
builder = factory.newDocumentBuilder();
Document document = builder.parse(new InputSource(new
StringReader(bodyStr)));
XPath xPath = XPathFactory.newInstance().newXPath(); 

String address1 = xPath.evaluate("//loc:address/text()", document);
String address2 = xPath.evaluate("/loc:getLocation/loc:address", document);

but i get error when i try to access address in both ways using xpath
net.sf.saxon.trans.XPathException: Prefix loc has not been declared

Anything I am missing ? 



--
View this message in context: http://camel.465427.n5.nabble.com/Difficulty-in-extracting-data-from-CxfPayload-tp5768422p5768458.html
Sent from the Camel - Users mailing list archive at Nabble.com.

RE: Difficulty in extracting data from CxfPayload

Posted by "Siano, Stephan" <st...@sap.com>.
Hi,

Well, if you want to process your payload as a DOM Document (e.g. in some processor), why don't you just do a exchange.getIn().getBody(Document.class) ?
There are type converters from CxfPayload to Document...

If you want to access the address directly (e.g. as part of the camel route), you could also do an XPath to "/loc:getLocation/loc:address" to navigate to the node itself.

Best regards
Stephan

-----Original Message-----
From: siddhesh [mailto:siddhesh_deodhar@persistent.co.in] 
Sent: Freitag, 19. Juni 2015 20:36
To: users@camel.apache.org
Subject: Difficulty in extracting data from CxfPayload

Hi 

I have created soap webservice using CXFendpoint. I am trying to Mock
ParlayX getLoaction functionality. I have wsdl and have generated required
objects. My dataformat is payload. I am sending my input body as follows.

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:loc="http://www.csapi.org/schema/parlayx/terminal_location/v2_3/local">
   <soapenv:Header/>
   <soapenv:Body>
      <loc:getLocation>
         <loc:address>tel:+919420161556</loc:address>
         <loc:requestedAccuracy>100</loc:requestedAccuracy>
      </loc:getLocation>
   </soapenv:Body>
</soapenv:Envelope>

Inside my operation method, i get this body as CxfPayload. I am having hard
time to retrieve data like address, requestedAccuracy in my method. I tried
to use methods from CxfPayloadConverter but could not find anyway to extract
data from DOMSource or Element.  I tried manually un-marshaling xml that i
get from exchange.getIn().getBody(String.class) but no luck.

Any inputs on how i can extract data from payload ? 





--
View this message in context: http://camel.465427.n5.nabble.com/Difficulty-in-extracting-data-from-CxfPayload-tp5768422.html
Sent from the Camel - Users mailing list archive at Nabble.com.