Hi Devs,
The clone mediator is having some issues in the latest trunk (with Axiom
1.2.11 to be precise). We use the following bit of code to clone the SOAP
envelope (in MessageHelper class):
Iterator itr =
envelope.getBody().cloneOMElement().getChildren();
while (itr.hasNext()) {
newEnvelope.getBody().addChild((OMNode) itr.next());
}
Now let's assume the following message:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
>
<soapenv:Body>
<ser:echoString xmlns:ser="http://service.carbon.wso2.org">
<ser:s>Hello</ser:s>
</ser:echoString>
</soapenv:Body>
</soapenv:Envelope>
The child element iterator for this message, returned by the above code will
initially have 3 elements (1 OMElement for the echoString element and 2
OMText objects for the white spaces around it). Once we have attached the
first OMText to the new envelope, subsequent calls to hasNext method on the
iterator will start returning false. So the resulting cloned envelope will
only have a bit of white space in the SOAP body.
I can see that there are some changes in the OMAbstractIterator and
OMChildrenIterator between Axiom 1.2.8 and 1.2.11. I guess that's probably
what's causing this. So any idea how we can fix this? One easy solution is
to change the above code as follows:
Iterator itr =
envelope.getBody().cloneOMElement().getChildren();
while (itr.hasNext()) {
if (itr.next() instanceof OMText) {
continue; // ignore text elements for white spaces
}
newEnvelope.getBody().addChild((OMNode) itr.next());
}
Thanks
--
Hiranya Jayathilaka
Senior Software Engineer;
WSO2 Inc.; http://wso2.org
E-mail: [email protected]; Mobile: +94 77 633 3491
Blog: http://techfeast-hiranya.blogspot.com