if (body == null)
throw new RuntimeException("Invalid SOAP envelope: no body element.");
Element requestData = XmlUtils.getFirstElement(body);
ResourceRouter router = getRouter();
Environment env = router.getEnvironment();
MessageHeaders addressing = null;
try
{
//
// WS-A info provides resource context for this request
//
addressing = new MessageHeaders(header);
env.addAddressingContext(addressing);
}
catch (Throwable error)
{
LoggingUtils.logError(router.getLog(), error);
}
if (!hasFailedToInitialize())
LoggingUtils.logMessage(router.getLog(), request, true);
//
// actually perform the operation with the given parameters
//
Element result = router.invoke(requestData);
//
// the standard response wsa:Action name is Action + "Response"
//
MessageHeaders replyAddressing = null;
//
// send back fault headers on exception
//
if (SoapUtils.isFault(result))
replyAddressing = addressing.createFaultHeaders();
else
replyAddressing = addressing.createReplyHeaders();
//
// DONE - must be sure to remove the request context, or
// we'll have a memory leak
//
env.removeAddressingContext();
//
// import all of the headers into the response envelope...
//
Element replyXML = replyAddressing.toXML();
Element[] children = XmlUtils.getAllElements(replyXML);
Document response = XmlUtils.createDocument();
soap = XmlUtils.createElement(response, SoapConstants.ENVELOPE_QNAME);
response.appendChild(soap);
header = XmlUtils.createElement(response, SoapConstants.HEADER_QNAME);
soap.appendChild(header);
for (int n = 0; n < children.length; ++n)
{
Node next = response.importNode(children[n], true);
header.appendChild(next);
}
//
// add the result (valid or fault) to the SOAP body...
//
body = XmlUtils.createElement(response, SoapConstants.BODY_QNAME);
soap.appendChild(body);
result = (Element)response.importNode(result, true);
body.appendChild(result);
if (!hasFailedToInitialize())
LoggingUtils.logMessage(router.getLog(), response, false);
return response;
}