use of org.apache.axiom.soap.SOAPFaultRole in project wso2-synapse by wso2.
the class MessageHelper method cloneSOAPFault.
/**
* Clones the SOAPFault, fault cloning is not the same as cloning the OMElement because if the
* Fault is accessed through the SOAPEnvelope.getBody().getFault() method it will lead to a
* class cast because the cloned element is just an OMElement but not a Fault.
*
* @param fault that needs to be cloned
* @return the cloned fault
*/
public static SOAPFault cloneSOAPFault(SOAPFault fault) {
SOAPFactory fac;
int soapVersion;
final int SOAP_11 = 1;
final int SOAP_12 = 2;
if (SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(fault.getNamespace().getNamespaceURI())) {
fac = OMAbstractFactory.getSOAP11Factory();
soapVersion = SOAP_11;
} else {
fac = OMAbstractFactory.getSOAP12Factory();
soapVersion = SOAP_12;
}
SOAPFault newFault = fac.createSOAPFault();
SOAPFaultCode code = fac.createSOAPFaultCode();
SOAPFaultReason reason = fac.createSOAPFaultReason();
switch(soapVersion) {
case SOAP_11:
code.setText(fault.getCode().getTextAsQName());
reason.setText(fault.getReason().getText());
break;
case SOAP_12:
SOAPFaultValue value = fac.createSOAPFaultValue(code);
value.setText(fault.getCode().getTextAsQName());
for (Object obj : fault.getReason().getAllSoapTexts()) {
SOAPFaultText text = fac.createSOAPFaultText();
text.setText(((SOAPFaultText) obj).getText());
reason.addSOAPText(text);
}
break;
}
newFault.setCode(code);
newFault.setReason(reason);
if (fault.getNode() != null) {
SOAPFaultNode soapfaultNode = fac.createSOAPFaultNode();
soapfaultNode.setNodeValue(fault.getNode().getNodeValue());
newFault.setNode(soapfaultNode);
}
if (fault.getRole() != null) {
SOAPFaultRole soapFaultRole = fac.createSOAPFaultRole();
soapFaultRole.setRoleValue(fault.getRole().getRoleValue());
newFault.setRole(soapFaultRole);
}
if (fault.getDetail() != null) {
SOAPFaultDetail soapFaultDetail = fac.createSOAPFaultDetail();
for (Iterator itr = fault.getDetail().getAllDetailEntries(); itr.hasNext(); ) {
Object element = itr.next();
if (element instanceof OMElement) {
soapFaultDetail.addDetailEntry(((OMElement) element).cloneOMElement());
}
}
newFault.setDetail(soapFaultDetail);
}
return newFault;
}
Aggregations