Hello,
I use SAAJ 1.3 and XMLBeans 1.0.3 to develop a web service client. I use SAAJ
for the SOAP part and XMLBeans for the data payload part. My problem is that I
cannot figure out how to get the child element from the SOAP-Body element that
corresponds to my root XMLBeans element. The work-around I use for now is that
I iterate through all SOAP-Body childs until an XMLBeans parse method for a
org.w3c.dom.Node object does not throw an exception. I have tried to use a
javax.xml.soap.Name object that contains the "localname" of my XMLBeans root
element, but that creates an empty iterator. I cannot use the
javax.xml.soap.Name object that in addition contains the namespace prefix and
namespace URL, as the prefix may change.
My work-around works, but it seems to be very, very ugly. Any ideas here?
I have attached the corresponding JAVA code and some logging output so you can
see the XML I try to process.
Thanks in advance,
Hans-Dieter Cordes
------------------------------------------------------------------------
Hans-Dieter Cordes
Software Dev. Spec. in the Network Configuration team
NIBS Development & Support (Network Information & Business Systems)
AT&T LABS EMEA
Lyoner Strasse 24-26
D-60528 Frankfurt
Germany
EMail: [EMAIL PROTECTED]
Phone: +49 69 15306 235
Fax: +49 69 15306 330
------------------------------------------------------------------------
********************************************************************************
This message and any attachments to it contain confidential business information
intended solely for the recipients. If you have received this email in error
please do not forward or distribute it to anyone else, but call
+49/69/15306-235
to report the error, and then delete this message from your system.
********************************************************************************
private OutputData _send(String argBody) throws Exception {
SOAPConnectionFactory scf = SOAPConnectionFactory.newInstance();
SOAPConnection connection = scf.createConnection();
try {
MessageFactory msgFactory = MessageFactory.newInstance();
SOAPMessage msg = msgFactory.createMessage();
SOAPEnvelope envelope = msg.getSOAPPart().getEnvelope();
envelope.addNamespaceDeclaration("xsi",
"http://www.w3.org/2001/XMLSchema-instance");
envelope.addNamespaceDeclaration("soapenc",
"http://schemas.xmlsoap.org/soap/encoding/");
envelope.addNamespaceDeclaration("xsd",
"http://www.w3.org/2001/XMLSchema");
SOAPBody body = envelope.getBody();
DocumentBuilderFactory dbFactory =
DocumentBuilderFactory.newInstance();
dbFactory.setNamespaceAware(true);
DocumentBuilder builder =
dbFactory.newDocumentBuilder();
Document document = builder.parse(new
InputSource(new StringReader(argBody)));
body.addDocument(document);
URL endpoint = new URL(this.strSendAddress);
msg.saveChanges();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("\n---- Request Message (start) ----\n");
ByteArrayOutputStream os = new
ByteArrayOutputStream();
msg.writeTo(os);
LOGGER.debug(os.toString());
LOGGER.debug("\n---- Request Message (end) ----\n");
}
SOAPMessage reply = connection.call(msg, endpoint);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("\n\nReceived reply from: "+endpoint);
LOGGER.debug("\n---- Reply Message (start) ----\n");
ByteArrayOutputStream os = new
ByteArrayOutputStream();
msg.writeTo(os);
LOGGER.debug(os.toString());
LOGGER.debug("\n---- Reply Message (end) ----\n");
}
SOAPEnvelope envReply =
reply.getSOAPPart().getEnvelope();
SOAPBody bodyReply = envReply.getBody();
SOAPFault faultReply = bodyReply.getFault();
// -------------------------------------------------------------
//
// relevant code starts here
//
// -------------------------------------------------------------
Name name = envReply.createName("CreateResponse");
Iterator iter = bodyReply.getChildElements();
// Iterator iter = bodyReply.getChildElements(name);
CreateResponseDocument replyDoc = null;
while (iter.hasNext()) {
org.w3c.dom.Node node = (org.w3c.dom.Node) iter.next();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("node: "+node.toString());
}
try {
replyDoc =
CreateResponseDocument.Factory.parse(node);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("\n\nreplyDoc:\n"+replyDoc.toString() + "\n\n");
}
// we are done: break !!!
break;
} catch (Exception ex) {
}
}
// handle any problems in our reply
// TODO: call method !!!
WSResponseHeader wsRespHdr = null;
ChangeStruct cs = null;
OutputData ret = _buildResultFromWSResponse(wsRespHdr,
cs);
return ret;
} finally {
if (connection != null) {
connection.close();
}
}
}
[2005-06-01 12:53:06,800] 25868 DEBUG
(com.att.dbor.gcs.ant.aots.saaj.AotsWsClientSender) -
---- Reply Message (start) ----
[2005-06-01 12:53:06,820] 25888 DEBUG
(com.att.dbor.gcs.ant.aots.saaj.AotsWsClientSender) - <SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><SOAP-ENV:Header/><SOAP-ENV:Body><CreateRequest
xmlns="http://ant.att.com/CMI" xmlns:v2="http://cio.att.com/CommonHeader/v2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<v2:WSHeader>
<v2:WSCredentials>
<v2:UserName>blanked</v2:UserName>
<v2:Token>blanked</v2:Token>
</v2:WSCredentials>
</v2:WSHeader>
<ChangeStruct>
<ChangeRecord>
<< Irrelevant details go here >>
</ChangeRecord>
<ComponentRecords>
<componentID xsi:nil="true"/>
<componentCustomer xsi:nil="true"/>
<componentDesc xsi:nil="true"/>
<componentLoc xsi:nil="true"/>
</ComponentRecords>
</ChangeStruct>
</CreateRequest></SOAP-ENV:Body></SOAP-ENV:Envelope>
[2005-06-01 12:53:06,820] 25888 DEBUG
(com.att.dbor.gcs.ant.aots.saaj.AotsWsClientSender) -
---- Reply Message (end) ----
[2005-06-01 12:53:06,910] 25978 DEBUG
(com.att.dbor.gcs.ant.aots.saaj.AotsWsClientSender) - node: [#text:
]
[2005-06-01 12:53:06,930] 25998 DEBUG
(com.att.dbor.gcs.ant.aots.saaj.AotsWsClientSender) - node: [ns:CreateResponse:
null]
[2005-06-01 12:53:06,940] 26008 DEBUG
(com.att.dbor.gcs.ant.aots.saaj.AotsWsClientSender) -
replyDoc:
<CreateResponse xmlns:ns="http://ant.att.com/CMI"
xmlns="http://ant.att.com/CMI" xmlns:v2="http://cio.att.com/CommonHeader/v2">
<v2:WSResponseHeader xmlns:ns0="http://cio.att.com/CommonHeader/v2">
<v2:WSCorrelationId/>
</v2:WSResponseHeader>
<ChangeStruct>
<ChangeRecord>
<< Irrelevant details go here >>
</ChangeRecord>
<ComponentRecords/>
</ChangeStruct>
</CreateResponse>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]