I use Axis 1.4 and I want to insert an additional level within in the XML of a SOAP body within the client. There is a server response, which I can get with a subclass of javax.xml.rpc.handler.GenericHandler in the client:
Now I try to recognize the right message type with
SOAPMessageContext smc = (SOAPMessageContext) context;
SOAPMessage message = smc.getMessage();
SOAPBody sb = message.getSOAPBody();
NodeList nl = sb.getElementsByTagName("projectDataReturn");
if (nl.getLength() == 0) {
return true; // wrong message
}
log.info("we have a projectDataReturn structure");
NodeList cl = sb.getElementsByTagName("centres");
if (cl.getLength() == 0) {
return true; // no centres
}
log.info("we have centres tags");
At this point I need a new tag, which holds all existing <centres>
tags. The list of all <centres>
tags I have stored in cl
already, but how I can add new nodes to the <projectDataReturn>
tag? And how I can move the existing <centre>
tags to the new tag?. I have tried it with
Document doc = cl.item(0).getOwnerDocument();
Element array = doc.createElement("centres");
array.setAttribute("xmlns:ns5", "http://beans.eo.xyz.de");
array.setAttribute("soapenc:arrayType", "ns5:CentreBean[" + cl.getLength() + "]");
array.setAttribute("xsi:type", "soapenc:Array");
array.setAttribute("xmlns:soapenc", "http://schemas.xmlsoap.org/soap/encoding/");
nl.item(0).appendChild(array);
// move existing <centre> tags here
return true;
But it produces a SOAPException
javax.xml.rpc.JAXRPCException: javax.xml.soap.SOAPException: Could not get document from SOAPEnvelope
What's wrong?