public static void convertSOAP12toSOAP11()

in modules/core/src/main/java/org/apache/synapse/core/axis2/SOAPUtils.java [244:374]


    public static void convertSOAP12toSOAP11(
        org.apache.axis2.context.MessageContext axisOutMsgCtx) throws AxisFault {

        if (log.isDebugEnabled()) {
            log.debug("convert SOAP12 to SOAP11");
        }

        SOAPEnvelope clonedOldEnv = MessageHelper.cloneSOAPEnvelope(axisOutMsgCtx.getEnvelope());

        SOAPFactory soap11Factory = OMAbstractFactory.getSOAP11Factory();
        SOAPEnvelope newEnvelope  = soap11Factory.getDefaultEnvelope();
        if (clonedOldEnv.getHeader() != null) {
            Iterator itr = clonedOldEnv.getHeader().getChildren();
            while (itr.hasNext()) {
                OMNode omNode = (OMNode) itr.next();

                if (omNode instanceof SOAPHeaderBlock) {
                    SOAPHeaderBlock soapHeaderBlock = (SOAPHeaderBlock) omNode;
                    SOAPHeaderBlock newSOAPHeader = soap11Factory.createSOAPHeaderBlock(
                        soapHeaderBlock.getLocalName(), soapHeaderBlock.getNamespace());

                    Iterator allAttributes = soapHeaderBlock.getAllAttributes();

                    while(allAttributes.hasNext()) {
                        OMAttribute attr = (OMAttribute) allAttributes.next();
                        if (attr.getNamespace() != null
                            && SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(
                            attr.getNamespace().getNamespaceURI())) {
                            String attrName = attr.getLocalName();

                            if (SOAP_ATR_ROLE.equals(attrName)) {
                                OMAttribute newAtr = omNode.getOMFactory().createOMAttribute(
                                    SOAP_ATR_ACTOR, newEnvelope.getNamespace(),
                                    attr.getAttributeValue());
                                newSOAPHeader.addAttribute(newAtr);

                            } else if(SOAP_ATR_MUST_UNDERSTAND.equals(attrName)) {
                                boolean isMustUnderstand = soapHeaderBlock.getMustUnderstand();
                                newSOAPHeader.setMustUnderstand(isMustUnderstand);

                            } else {
                                log.warn("removed unsupported attribute from SOAP 1.2 " +
                                    "namespace when converting to SOAP 1.1:" + attrName);
                            }

                        } else {
                            newSOAPHeader.addAttribute(attr);
                        }
                    }

                    Iterator itrChildren = soapHeaderBlock.getChildren();
                    while (itrChildren.hasNext()) {
                        OMNode node = (OMNode) itrChildren.next();
                        itrChildren.remove();
                        newSOAPHeader.addChild(node);
                    }

                    newEnvelope.getHeader().addChild(newSOAPHeader);

                } else {
                    itr.remove();
                    newEnvelope.getHeader().addChild(omNode);
                }
            }
        }

        if (clonedOldEnv.getBody() != null) {
            if (clonedOldEnv.hasFault()) {
                SOAPFault soapFault = clonedOldEnv.getBody().getFault();
                SOAPFault newSOAPFault = soap11Factory.createSOAPFault();
                newEnvelope.getBody().addChild(newSOAPFault);

                SOAPFaultCode code = soapFault.getCode();
                if(code != null) {
                    SOAPFaultCode newSOAPFaultCode
                            = soap11Factory.createSOAPFaultCode(newSOAPFault);

                    SOAPFaultValue value = code.getValue();
                    if(value != null) {
                        // get the corresponding SOAP12 fault code
                        // for the provided SOAP11 fault code
                        soap11Factory.createSOAPFaultValue(newSOAPFaultCode);
                        if(value.getTextAsQName() != null) {
                            newSOAPFaultCode.setText(
                                    getMappingSOAP11Code(value.getTextAsQName()));
                        }
                    }
                }

                SOAPFaultReason reason = soapFault.getReason();
                if(reason != null) {
                    SOAPFaultReason newSOAPFaultReason
                            = soap11Factory.createSOAPFaultReason(newSOAPFault);

                    List allSoapTexts = reason.getAllSoapTexts();
                    Iterator iterAllSoapTexts = allSoapTexts.iterator();
                    if (iterAllSoapTexts.hasNext()) {
                        SOAPFaultText soapFaultText = (SOAPFaultText) iterAllSoapTexts.next();
                        iterAllSoapTexts.remove();
                        newSOAPFaultReason.setText(soapFaultText.getText());
                    }
                }

                SOAPFaultDetail detail = soapFault.getDetail();
                if(detail != null) {
                    SOAPFaultDetail newSOAPFaultDetail
                            = soap11Factory.createSOAPFaultDetail(newSOAPFault);
                    Iterator<OMElement> iter = detail.getAllDetailEntries();
                    while (iter.hasNext()) {
                        OMElement detailEntry = iter.next();
                        iter.remove();
                        newSOAPFaultDetail.addDetailEntry(detailEntry);
                    }
                    newSOAPFault.setDetail(newSOAPFaultDetail);
                }

            } else {
                Iterator itr = clonedOldEnv.getBody().getChildren();
                while (itr.hasNext()) {
                    OMNode omNode = (OMNode) itr.next();
                    if (omNode != null) {
                        itr.remove();
                        newEnvelope.getBody().addChild(omNode);
                    }
                }
            }

        }
        
        axisOutMsgCtx.setEnvelope(newEnvelope);
    }