Hi All
So long I was using Axis 1.2.1 and Java 1.5, and was able to
successfully add my custom XML document within a SOAPMessage. I create
the XML document using castor-generated java bindings and combining them
into a DOM, and then using the following routine to get a SOAPElement
from the DOM:
public static SOAPElement
convertDOMToSOAPElement(javax.xml.soap.SOAPEnvelope env, Node DOMNode)
throws SOAPException {
//Test that DOMNode is of type org.w3c.dom.Node.ELEMENT_NODE.
if ((DOMNode.getNodeType()) != Node.ELEMENT_NODE)
throw new SOAPException("DOMNode must of type
ELEMENT_NODE");
SOAPFactory elementFactory = SOAPFactory.newInstance();
SOAPElement se =
elementFactory.createElement(DOMNode.getLocalName());
mLog.debug("element class: " + se.getClass().getName());
if (DOMNode.hasAttributes()) {
NamedNodeMap DOMAttributes = DOMNode.getAttributes();
int noOfAttributes = DOMAttributes.getLength();
for (int i = 0; i < noOfAttributes; i++) {
org.w3c.dom.Node attr = DOMAttributes.item(i);
se.addAttribute(env.createName(attr.getLocalName(),
attr.getPrefix(),
attr.getNamespaceURI()),
attr.getNodeValue());
}
}
if (DOMNode.hasChildNodes()) {
NodeList children = DOMNode.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
Node child = children.item(i);
switch (child.getNodeType()) {
case org.w3c.dom.Node.PROCESSING_INSTRUCTION_NODE:
break;
case org.w3c.dom.Node.DOCUMENT_TYPE_NODE:
break;
case org.w3c.dom.Node.CDATA_SECTION_NODE:
case org.w3c.dom.Node.COMMENT_NODE:
case org.w3c.dom.Node.TEXT_NODE: {
se.addTextNode(child.getNodeValue());
break;
}
default:
se.addChildElement(convertDOMToSOAPElement(env,
child));
}
}//end of for
}//end of if
return se;
}
Once the SOAPElement is returned, I used to add it as a child element to
my main SOAPBodyElement:
SOAPEnvelope envelope = new SOAPEnvelope();
//Create the root element
Document outputDocument = XMLUtils.newDocument(new
ByteArrayInputStream(impl.tm.getBytes()));
System.out.println("Document Element: " +
outputDocument.getDocumentElement().getNodeName());
SOAPBody bdy = (SOAPBody) envelope.getBody();
SOAPBodyElement csReq = (SOAPBodyElement)
bdy.addBodyElement(envelope.createName(DynasoarConstants.DYNASOAR_SERVIC
E_REQUEST));
SOAPElement elem1 = convertDOMToSOAPElement(envelope,
outputDocument.getDocumentElement());
csReq.addChildElement(elem1);
Recently I upgraded to Axis 1.4 and Java 1.6, and started getting a
class cas exception about not being able to cast a
com.sun.xml.internal.messaging.saaj.soap.impl.ElementImpl object to
org.apache.axis.message.MessageElement at the
csReq.addChildElement(elem1) statement. But ideally the object returned
from the routing should be javax.xml.SOAPElement. I reverted back to
Java 1.5, and the same code is back working.
Are there any known issues with Axis 1.4 and Java 1.6?
Thanx in advance
Regards
Arijit
Microsoft is not the answer.
Microsoft is the question.
NO (or Linux) is the answer.
-- source unknown