Camel-CXF strips all the xml elemets and attributes and send only data with whitespace

classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|

Camel-CXF strips all the xml elemets and attributes and send only data with whitespace

Sachin
Hi ,

While invoking a web service from SOAP UI tool, came across this problem. I am using Camel 2.9.1 with cxf 2.4.2.
I have exposed my CXF web service using WSDL first approach in PAYLOAD mode as a camel route which consumes and message and do the further processing.

Input Request from SOAPUI:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:mus="http://mustservice.summit">
   <soapenv:Header/>
   <soapenv:Body>
      <mus:Accept>
  <mus:MustProduct>
           
            <MustProductName>ss</MustProductName>
           
            <MustProductVersion>dd</MustProductVersion>
         </mus:MustProduct>
         <mus:MustTradeId>
           
            <TradeId>1</TradeId>
         </mus:MustTradeId>
</mus:Accept>
   </soapenv:Body>
</soapenv:Envelope>

Received in camel route :

Exchange[Message:
 
           
            ss
           
            dd
         
         
           
            1
         
]

which cause below code to return "" .
CxfPayload<SOAPBody> requestPayload = inMessage.getBody(CxfPayload.class);
                        List<Element> inElements = requestPayload.getBody();
                        XmlConverter converter = new XmlConverter();
                        String documentString = converter.toString(inElements.get(0).cloneNode(true), exchange);

May be i am something really weird here, but i seems to struck here as i need request xml to pass it further.

Regards
Sachin
Reply | Threaded
Open this post in threaded view
|

Re: Camel-CXF strips all the xml elemets and attributes and send only data with whitespace

Willem.Jiang
Administrator
Hi,

It looks like you can get a right message body from camel from the exchange.
Can you just pass the elements into  converter without use clone, like this ?

 String documentString = converter.toString(inElements.get(0), exchange);

Willem
Reply | Threaded
Open this post in threaded view
|

Re: Camel-CXF strips all the xml elemets and attributes and send only data with whitespace

Sachin
Hi Willem,

I have tried that without clononing the node still i got blank string. I even tried with genric approach like below:
StringWriter buffer = new StringWriter();
TransformerFactory.newInstance().newTransformer().transform(
                            new DOMSource(inElements.get(0)), new StreamResult(buffer)
                        );
documentString = buffer.toString();

Still it doesnt seem to work. Problem here is i am not getting any element and attribute in request xml message.

Regards
Sachin
Reply | Threaded
Open this post in threaded view
|

Re: Camel-CXF strips all the xml elemets and attributes and send only data with whitespace

Willem.Jiang
Administrator
Can I have a look at the route ?

Here is a test[1] of camel-cxf that you can take a look.

[1]https://svn.apache.org/repos/asf/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfConsumerPayloadTest.java 

--
Willem Jiang

Red Hat, Inc.
FuseSource is now part of Red Hat
Web: http://www.fusesource.com | http://www.redhat.com
Blog: http://willemjiang.blogspot.com (http://willemjiang.blogspot.com/) (English)
          http://jnn.javaeye.com (http://jnn.javaeye.com/) (Chinese)
Twitter: willemjiang
Weibo: willemjiang





On Friday, November 2, 2012 at 4:51 PM, Sachin wrote:

> Hi Willem,
>
> I have tried that without clononing the node still i got blank string. I
> even tried with genric approach like below:
> StringWriter buffer = new StringWriter();
> TransformerFactory.newInstance().newTransformer().transform(
> new DOMSource(inElements.get(0)), new StreamResult(buffer)
> );
> documentString = buffer.toString();
>
> Still it doesnt seem to work. Problem here is i am not getting any element
> and attribute in request xml message.
>
> Regards
> Sachin
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Camel-CXF-strips-all-the-xml-elemets-and-attributes-and-send-only-data-with-whitespace-tp5721973p5722011.html
> Sent from the Camel - Users mailing list archive at Nabble.com (http://Nabble.com).



Reply | Threaded
Open this post in threaded view
|

Re: Camel-CXF strips all the xml elemets and attributes and send only data with whitespace

Sachin
Hi, PFB the route code:

from(uri).threads(numberOfThreads).routeId(routeId).
                                // transacted("PROPAGATION_REQUIRED").
                                setProperty("nodeName").simple(nodeName)// node name
                                .process(new CxfMessageToXMLString()).process(new Processor() {
                                        public void process(Exchange exchange) throws Exception {
                                                setCamelMessageHeaders(exchange);
                                        }
                                }).process((Processor) nodeImpl).end();

where uri is :
cxf:///genericdataservice/GenericDataService?wsdlURL=bfr://Systems/MeridianEndPoint/must/GenericDataWS/WsdlFiles/GenericDataService.wsdl&serviceName={http://dataservice.summit/genericdataservice}GenericDataService&portName={http://dataservice.summit/genericdataservice}GenericDataService&dataFormat=PAYLOAD]
Reply | Threaded
Open this post in threaded view
|

Re: Camel-CXF strips all the xml elemets and attributes and send only data with whitespace

Christian Mueller
Administrator
There could be something wrong with your processors. Could you share the
code of these processors? May be this FAQ entry is helpful for you [1].

[1] http://camel.apache.org/using-getin-or-getout-methods-on-exchange.html

Best,
Christian

On Fri, Nov 2, 2012 at 1:47 PM, Sachin <[hidden email]> wrote:

> Hi, PFB the route code:
>
> from(uri).threads(numberOfThreads).routeId(routeId).
>                                 // transacted("PROPAGATION_REQUIRED").
>                                 setProperty("nodeName").simple(nodeName)//
> node name
>                                 .process(new
> CxfMessageToXMLString()).process(new Processor() {
>                                         public void process(Exchange
> exchange) throws Exception {
>
> setCamelMessageHeaders(exchange);
>                                         }
>                                 }).process((Processor) nodeImpl).end();
>
> where uri is :
>
> cxf:///genericdataservice/GenericDataService?wsdlURL=bfr://Systems/MeridianEndPoint/must/GenericDataWS/WsdlFiles/GenericDataService.wsdl&serviceName={
> http://dataservice.summit/genericdataservice}GenericDataService&portName={http://dataservice.summit/genericdataservice}GenericDataService&dataFormat=PAYLOAD
> ]
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Camel-CXF-strips-all-the-xml-elemets-and-attributes-and-send-only-data-with-whitespace-tp5721973p5722029.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



--
Reply | Threaded
Open this post in threaded view
|

Re: Camel-CXF strips all the xml elemets and attributes and send only data with whitespace

Sachin
This is first processsor of my route where i am trying to unmarshall request message.

class CxfMessageToXMLString implements Processor {
                @SuppressWarnings("unchecked")
                @Override
                public void process(Exchange exchange) throws Exception {
                        Message inMessage = exchange.getIn();
                        // bring session for convenience to exchange
                        org.apache.cxf.message.Message cxfMessage = (org.apache.cxf.message.Message) inMessage.getHeader(CxfConstants.CAMEL_CXF_MESSAGE);
                        exchange.setProperty(WebServiceConstants.SESSION, cxfMessage.get(WebServiceConstants.SESSION));
                        CxfPayload<SOAPBody> requestPayload = inMessage.getBody(CxfPayload.class);
                        List<Element> inElements = requestPayload.getBody();
                        XmlConverter converter = new XmlConverter();
                        //String documentString = converter.toString(inElements.get(0).cloneNode(true), exchange);
                        String documentString = converter.toString(inElements.get(0), exchange);
..... ....................................
......................}

Reply | Threaded
Open this post in threaded view
|

Re: Camel-CXF strips all the xml elemets and attributes and send only data with whitespace

Sachin
I have faced this problem for another endpoint also, but this time for response. As clearly i can see exchange contains response message but while converting it with xmlconvertor it returns "".

Simple converting it to string gives me reponse string like :
String response = exchange.getOut().getBody(String.class);

but while doing it with
CxfPayload<SOAPHeader> resPayload = exchange.getOut().getBody(CxfPayload.class);
List<Element> inElements = resPayload.getBody();
XmlConverter converter = new XmlConverter();
String documentString = converter.toString(inElements.get(0), exchange);

returns "".

Are there some interceptors which removes body from the CXFPayload?
Reply | Threaded
Open this post in threaded view
|

Re: Camel-CXF strips all the xml elemets and attributes and send only data with whitespace

Sachin
Strange, jut to let you know guys, it works with toString method of org.apache.cxf.helpers.XMLUtils inspite of org.apache.camel.converter.jaxp.XmlConverter.

FYI:

CxfPayload<SOAPHeader> resPayload = exchange.getOut().getBody(CxfPayload.class);
List<Element> inElements = resPayload.getBody();
String response =XMLUtils.toString(inElements.get(0));

gives you proper unmarshalled xml. Yet to find out the reasons though.
Reply | Threaded
Open this post in threaded view
|

Re: Camel-CXF strips all the xml elemets and attributes and send only data with whitespace

Willem.Jiang
Administrator
Thanks for this hit, it could be helpful for us to dig the issue.

--
Willem Jiang

Red Hat, Inc.
FuseSource is now part of Red Hat
Web: http://www.fusesource.com | http://www.redhat.com
Blog: http://willemjiang.blogspot.com (http://willemjiang.blogspot.com/) (English)
          http://jnn.javaeye.com (http://jnn.javaeye.com/) (Chinese)
Twitter: willemjiang
Weibo: willemjiang





On Sunday, November 4, 2012 at 7:51 PM, Sachin wrote:

> Strange, jut to let you know guys, it works with toString method of
> org.apache.cxf.helpers.XMLUtils inspite of
> org.apache.camel.converter.jaxp.XmlConverter.
>
> FYI:
>
> CxfPayload<SOAPHeader> resPayload =
> exchange.getOut().getBody(CxfPayload.class);
> List<Element> inElements = resPayload.getBody();
> String response =XMLUtils.toString(inElements.get(0));
>
> gives you proper unmarshalled xml. Yet to find out the reasons though.
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Camel-CXF-strips-all-the-xml-elemets-and-attributes-and-send-only-data-with-whitespace-tp5721973p5722100.html
> Sent from the Camel - Users mailing list archive at Nabble.com (http://Nabble.com).



Reply | Threaded
Open this post in threaded view
|

Re: Camel-CXF strips all the xml elemets and attributes and send only data with whitespace

Willem.Jiang
Administrator
In reply to this post by Sachin
With the help of CxfPayLoadConverter, you can leverage the camel type convert with fewer codes like this
String response = exchange.getOut().getBody(String.class);


--
Willem Jiang

Red Hat, Inc.
FuseSource is now part of Red Hat
Web: http://www.fusesource.com | http://www.redhat.com
Blog: http://willemjiang.blogspot.com (http://willemjiang.blogspot.com/) (English)
          http://jnn.javaeye.com (http://jnn.javaeye.com/) (Chinese)
Twitter: willemjiang
Weibo: willemjiang





On Sunday, November 4, 2012 at 7:51 PM, Sachin wrote:

> Strange, jut to let you know guys, it works with toString method of
> org.apache.cxf.helpers.XMLUtils inspite of
> org.apache.camel.converter.jaxp.XmlConverter.
>
> FYI:
>
> CxfPayload<SOAPHeader> resPayload =
> exchange.getOut().getBody(CxfPayload.class);
> List<Element> inElements = resPayload.getBody();
> String response =XMLUtils.toString(inElements.get(0));
>
> gives you proper unmarshalled xml. Yet to find out the reasons though.
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Camel-CXF-strips-all-the-xml-elemets-and-attributes-and-send-only-data-with-whitespace-tp5721973p5722100.html
> Sent from the Camel - Users mailing list archive at Nabble.com (http://Nabble.com).



Reply | Threaded
Open this post in threaded view
|

Re: Camel-CXF strips all the xml elemets and attributes and send only data with whitespace

Sachin
That i have already tried, it just gives you the data without xml elements and attributes. Might need to see the difference between XML utils toString() implementation to that of XMLConvertors' one.
Reply | Threaded
Open this post in threaded view
|

Re: Camel-CXF strips all the xml elemets and attributes and send only data with whitespace

Willem.Jiang
Administrator
I just checked the code of XmlUtils and XmlConvertor toString() method, there is no much difference.
I'm not sure if the out message is consumed more than once.
It could be helpful if you can submit us a same test case to reproduce the error.


--
Willem Jiang

Red Hat, Inc.
FuseSource is now part of Red Hat
Web: http://www.fusesource.com | http://www.redhat.com
Blog: http://willemjiang.blogspot.com (http://willemjiang.blogspot.com/) (English)
          http://jnn.javaeye.com (http://jnn.javaeye.com/) (Chinese)
Twitter: willemjiang
Weibo: willemjiang





On Monday, November 5, 2012 at 2:20 PM, Sachin wrote:

> That i have already tried, it just gives you the data without xml elements
> and attributes. Might need to see the difference between XML utils
> toString() implementation to that of XMLConvertors' one.
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Camel-CXF-strips-all-the-xml-elemets-and-attributes-and-send-only-data-with-whitespace-tp5721973p5722117.html
> Sent from the Camel - Users mailing list archive at Nabble.com (http://Nabble.com).