public void throwSOAPFaultException(String faultString,
SOAPMessage soapMessage)
throws SOAPFaultException {
SOAPFaultException sfe = null;
try {
SOAPPart sp = soapMessage.getSOAPPart();
SOAPEnvelope se = sp.getEnvelope();
// Consume the request
SOAPBody sb = se.getBody();
// Access the child elements of body
Iterator iter = sb.getChildElements();
// Response should only include the fault, so remove
// any request body nodes.
if (iter.hasNext()) {
SOAPBodyElement requestBody = (SOAPBodyElement)iter.next();
// detach this node from the tree
requestBody.detachNode();
}
SOAPFault soapFault = sb.addFault();
se.setEncodingStyle(SOAPConstants.URI_ENCODING);
String faultActor = "http://schemas.xmlsoap.org/soap/actor/next";
QName faultCode = SOAPConstants.FAULT_CODE_SERVER;
soapFault.setFaultCode("env:" + faultCode.getLocalPart());
soapFault.setFaultString(faultString);
soapFault.setFaultActor(faultActor);
sfe = new SOAPFaultException(faultCode, faultActor, faultString,
null);
} catch(SOAPException se) {
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE, LogUtils.EXCEPTION_THROWN, se);
}