📄 axissoapfaultwriter.java
字号:
/*
* JBoss, Home of Professional Open Source
* Copyright 2005, JBoss Inc., and individual contributors as indicated
* by the @authors tag.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the JBPM BPEL PUBLIC LICENSE AGREEMENT as
* published by JBoss Inc.; either version 1.0 of the License, or
* (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
package org.jbpm.bpel.integration.server;
import java.util.Iterator;
import java.util.Map;
import javax.xml.namespace.QName;
import javax.xml.rpc.soap.SOAPFaultException;
import javax.xml.soap.SOAPBody;
import javax.xml.soap.SOAPConstants;
import javax.xml.soap.SOAPElement;
import javax.xml.soap.SOAPEnvelope;
import javax.xml.soap.SOAPException;
import org.w3c.dom.Element;
import org.jbpm.bpel.xml.util.XmlUtil;
/**
* @author Alejandro Guizar
* @version $Revision: 1.1 $ $Date: 2007/01/18 12:58:28 $
*/
public class AxisSoapFaultWriter implements SoapFaultWriter {
public void writeFault(SOAPEnvelope envelope, SOAPFaultException exception,
Map parts) throws SOAPException {
// remove existing body, since it is immutable
SOAPBody body = envelope.getBody();
body.detachNode();
// re-create body
body = envelope.addBody();
// add a soapenv:Fault element
SOAPElement fault = body.addChildElement("Fault", XmlUtil.getPrefix(
SOAPConstants.URI_NS_SOAP_ENVELOPE, body),
SOAPConstants.URI_NS_SOAP_ENVELOPE);
writeFaultCode(fault, exception.getFaultCode());
writeFaultString(fault, exception.getFaultString());
if (parts != null)
writeDetail(fault, parts);
}
private static void writeFaultCode(SOAPElement fault, QName faultCode)
throws SOAPException {
SOAPElement faultcodeElem = XmlUtil.addChildElement(fault, "faultcode");
XmlUtil.setQNameValue(faultcodeElem, faultCode);
}
private static void writeFaultString(SOAPElement fault, String faultString)
throws SOAPException {
SOAPElement faultstringElem = XmlUtil.addChildElement(fault, "faultstring");
faultstringElem.setValue(faultString);
}
private static void writeDetail(SOAPElement fault, Map faultParts)
throws SOAPException {
// create detail element
SOAPElement detail = XmlUtil.addChildElement(fault, "detail");
// iterate through the fault message parts
Iterator faultPartIt = faultParts.values().iterator();
while (faultPartIt.hasNext()) {
Element faultPart = (Element) faultPartIt.next();
XmlUtil.copyChildElement(detail, faultPart);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -