Search in sources :

Example 6 with SOAPFaultRole

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;
}
Also used : SOAPFaultCode(org.apache.axiom.soap.SOAPFaultCode) SOAPFaultRole(org.apache.axiom.soap.SOAPFaultRole) SOAPFaultReason(org.apache.axiom.soap.SOAPFaultReason) SOAPFaultValue(org.apache.axiom.soap.SOAPFaultValue) SOAPFaultDetail(org.apache.axiom.soap.SOAPFaultDetail) OMElement(org.apache.axiom.om.OMElement) SOAPFaultText(org.apache.axiom.soap.SOAPFaultText) SOAPFactory(org.apache.axiom.soap.SOAPFactory) SynapseMediationFlowPoint(org.apache.synapse.debug.constructs.SynapseMediationFlowPoint) Iterator(java.util.Iterator) SOAPFault(org.apache.axiom.soap.SOAPFault) SOAPFaultNode(org.apache.axiom.soap.SOAPFaultNode)

Aggregations

SOAPFaultRole (org.apache.axiom.soap.SOAPFaultRole)6 OMElement (org.apache.axiom.om.OMElement)4 SOAPFault (org.apache.axiom.soap.SOAPFault)4 SOAPFaultCode (org.apache.axiom.soap.SOAPFaultCode)4 SOAPFaultDetail (org.apache.axiom.soap.SOAPFaultDetail)4 SOAPFaultReason (org.apache.axiom.soap.SOAPFaultReason)4 SOAPBody (org.apache.axiom.soap.SOAPBody)3 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)3 SOAPFaultNode (org.apache.axiom.soap.SOAPFaultNode)3 SOAPFaultText (org.apache.axiom.soap.SOAPFaultText)3 SOAPFaultValue (org.apache.axiom.soap.SOAPFaultValue)3 StringReader (java.io.StringReader)2 QName (javax.xml.namespace.QName)2 OMAttribute (org.apache.axiom.om.OMAttribute)2 OMNode (org.apache.axiom.om.OMNode)2 OMXMLParserWrapper (org.apache.axiom.om.OMXMLParserWrapper)2 SOAPFactory (org.apache.axiom.soap.SOAPFactory)2 SOAPFaultSubCode (org.apache.axiom.soap.SOAPFaultSubCode)2 SOAPHeader (org.apache.axiom.soap.SOAPHeader)2 SOAPHeaderBlock (org.apache.axiom.soap.SOAPHeaderBlock)2