public static void convertSOAP11toSOAP12()

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


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

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

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

        SOAPFactory soap12Factory = OMAbstractFactory.getSOAP12Factory();
        SOAPEnvelope newEnvelope  = soap12Factory.getDefaultEnvelope();

        if (clonedOldEnv.getHeader() != null) {
            Iterator itr = clonedOldEnv.getHeader().getChildren();
            while (itr.hasNext()) {
                OMNode omNode = (OMNode) itr.next();

                if (omNode instanceof SOAPHeaderBlock) {
                    SOAPHeaderBlock soapHeader = (SOAPHeaderBlock) omNode;
                    SOAPHeaderBlock newSOAPHeader = soap12Factory.createSOAPHeaderBlock(
                        soapHeader.getLocalName(), soapHeader.getNamespace());
                    Iterator allAttributes = soapHeader.getAllAttributes();

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

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

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

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

                        } else {
                            newSOAPHeader.addAttribute(attr);
                        }
                    } // while(allAttributes.hasNext())

                    Iterator itrChildren = soapHeader.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);
                }

            } // while (itr.hasNext())

        } // if (clonedOldEnv.getHeader() != null)

        if (clonedOldEnv.getBody() != null) {

            Iterator itrBodyChildren = clonedOldEnv.getBody().getChildren();
            while (itrBodyChildren.hasNext()) {
                OMNode omNode = (OMNode) itrBodyChildren.next();

                if (omNode != null && omNode instanceof SOAPFault) {

                    SOAPFault soapFault = (SOAPFault) omNode;
                    SOAPFault newSOAPFault = soap12Factory.createSOAPFault();
                    newEnvelope.getBody().addChild(newSOAPFault);
                    // get the existing envelope
                    SOAPFaultCode code = soapFault.getCode();
                    if(code != null) {
                        SOAPFaultCode newSOAPFaultCode = soap12Factory.createSOAPFaultCode();
                        newSOAPFault.setCode(newSOAPFaultCode);

                        QName s11Code = code.getTextAsQName();
                        if (s11Code != null) {
                            // get the corresponding SOAP12 fault code
                            // for the provided SOAP11 fault code
                            SOAPFaultValue newSOAPFaultValue
                                    = soap12Factory.createSOAPFaultValue(newSOAPFaultCode);
                            newSOAPFaultValue.setText(getMappingSOAP12Code(s11Code));
                        }

                    }

                    SOAPFaultReason reason = soapFault.getReason();
                    if(reason != null) {
                        SOAPFaultReason newSOAPFaultReason
                                = soap12Factory.createSOAPFaultReason(newSOAPFault);
                        String reasonText = reason.getText();
                        if(reasonText != null) {
                            SOAPFaultText newSOAPFaultText
                                    = soap12Factory.createSOAPFaultText(newSOAPFaultReason);
                            newSOAPFaultText.setLang("en"); // hard coded
                            newSOAPFaultText.setText(reasonText);
                        }
                        newSOAPFault.setReason(newSOAPFaultReason);
                    }

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

                } else {
                    itrBodyChildren.remove();
                    newEnvelope.getBody().addChild(omNode);

                } // if (omNode instanceof SOAPFault)

            } // while (itrBodyChildren.hasNext())

        } //if (clonedOldEnv.getBody() != null)

        axisOutMsgCtx.setEnvelope(newEnvelope);
    }