You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@synapse.apache.org by ru...@apache.org on 2007/10/15 12:59:22 UTC

svn commit: r584729 - in /webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2: Axis2FlexibleMEPClient.java SOAPUtils.java SynapseCallbackReceiver.java

Author: ruwan
Date: Mon Oct 15 03:59:21 2007
New Revision: 584729

URL: http://svn.apache.org/viewvc?rev=584729&view=rev
Log:
applying Upul's second patch on SYNAPSE-91

Modified:
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2FlexibleMEPClient.java
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/SOAPUtils.java
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/SynapseCallbackReceiver.java

Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2FlexibleMEPClient.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2FlexibleMEPClient.java?rev=584729&r1=584728&r2=584729&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2FlexibleMEPClient.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2FlexibleMEPClient.java Mon Oct 15 03:59:21 2007
@@ -130,7 +130,7 @@
                     axisOutMsgCtx.setSoapAction(axisOutMsgCtx.getWSAAction());
                 }
                 if(axisOutMsgCtx.isSOAP11() != true) {
-                    SOAPUtils.convertSoapVersion(axisOutMsgCtx, org.apache.axis2.namespace.Constants.URI_SOAP11_ENV);
+                    SOAPUtils.convertSOAP12toSOAP11(axisOutMsgCtx);
                 }
                 
             } else if (SynapseConstants.FORMAT_SOAP12.equals(endpoint.getFormat())) {
@@ -139,7 +139,7 @@
                     axisOutMsgCtx.setSoapAction(axisOutMsgCtx.getWSAAction());
                 }
                 if(axisOutMsgCtx.isSOAP11() == true) {
-                    SOAPUtils.convertSoapVersion(axisOutMsgCtx, org.apache.axis2.namespace.Constants.URI_SOAP12_ENV);
+                    SOAPUtils.convertSOAP11toSOAP12(axisOutMsgCtx);
                 }                
                 
             }

Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/SOAPUtils.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/SOAPUtils.java?rev=584729&r1=584728&r2=584729&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/SOAPUtils.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/SOAPUtils.java Mon Oct 15 03:59:21 2007
@@ -21,14 +21,20 @@
 
 import org.apache.axiom.om.OMAbstractFactory;
 import org.apache.axiom.om.OMNode;
-import org.apache.axiom.soap.SOAPEnvelope;
-import org.apache.axiom.soap.SOAPFactory;
+import org.apache.axiom.om.OMAttribute;
+import org.apache.axiom.soap.*;
 import org.apache.axis2.AxisFault;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.synapse.SynapseException;
 
 import java.util.Iterator;
+import java.util.List;
 
 public class SOAPUtils {
 
+    private static final Log log = LogFactory.getLog(SOAPUtils.class);
+
     /**
      * Converts the SOAP version of the message context.  Creates a new envelope of the given SOAP
      * version, copy headers and bodies from the old envelope and sets the new envelope to the same
@@ -42,37 +48,293 @@
     public static void convertSoapVersion(org.apache.axis2.context.MessageContext axisOutMsgCtx,
         String soapVersionURI) throws AxisFault {
 
-        // create a new envelope of the given version
-        SOAPFactory soapFactory = null;
         if (org.apache.axis2.namespace.Constants.URI_SOAP12_ENV.equals(soapVersionURI)) {
-            soapFactory = OMAbstractFactory.getSOAP12Factory();
+            convertSOAP11toSOAP12(axisOutMsgCtx);
         } else if (org.apache.axis2.namespace.Constants.URI_SOAP11_ENV.equals(soapVersionURI)) {
-            soapFactory = OMAbstractFactory.getSOAP11Factory();
+            convertSOAP12toSOAP11(axisOutMsgCtx);
         } else {
-            throw new RuntimeException("Invalid soapVersionURI");
+            throw new SynapseException("Invalid soapVersionURI:" + soapVersionURI);
         }
-        SOAPEnvelope newEnvelope = soapFactory.getDefaultEnvelope();
+    }
+
+    private static String SOAP_ATR_ACTOR = "actor";
+    private static String SOAP_ATR_ROLE = "role";
+    private static String SOAP_ATR_MUST_UNDERSTAND = "mustUnderstand";
 
-        // get the existing envelope
+    /**
+     * Converts the version of the the message context to 1.2.
+     * <br />
+     * <b>Message Changes:</b>
+     * <ol>
+     *     <li>Convert envelope, header elements</li>
+     *     <li>For each header block convert attribute actor to role</li>
+     *     <li>For each header block convert mustUnderstand value type</li>
+     *     <li>For each header block remove 1.1 namespaced other attributes</li>
+     * </ol>
+     *
+     * <b>Fault Changes:</b>
+     * <ol>
+     *     <li>Convert fault element</li>
+     *     <li>faultcode to Fault/Code</li>
+     *     <li>faultstring to First Fault/Reason/Text with lang=en</li>
+     * </ol>
+     *
+     * @param axisOutMsgCtx
+     * @throws AxisFault
+     */
+    public static void convertSOAP11toSOAP12(
+        org.apache.axis2.context.MessageContext axisOutMsgCtx) throws AxisFault {
+
+        if(log.isDebugEnabled()) {
+            log.debug("convert SOAP11 to SOAP12");
+        }
         SOAPEnvelope oldEnvelope = axisOutMsgCtx.getEnvelope();
 
-        // move all headers
+        SOAPFactory soap12Factory = OMAbstractFactory.getSOAP12Factory();
+        SOAPEnvelope newEnvelope  = soap12Factory.getDefaultEnvelope();
+
         if (oldEnvelope.getHeader() != null) {
             Iterator itr = oldEnvelope.getHeader().getChildren();
             while (itr.hasNext()) {
-                newEnvelope.getHeader().addChild(((OMNode) itr.next()));
-            }
+                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);
+                        }
+
+                        Iterator itrChildren = soapHeader.getChildren();
+                        while (itrChildren.hasNext()) {
+                            newSOAPHeader.addChild(((OMNode) itrChildren.next()));
+                        }
+
+                        newEnvelope.getHeader().addChild(newSOAPHeader);
+                    } // while(allAttributes.hasNext())
+
+                } else {
+                    newEnvelope.getHeader().addChild(omNode);
+                }
+
+            } // while (itr.hasNext())
+
+        } // if (oldEnvelope.getHeader() != null)
+
+        if (oldEnvelope.getBody() != null) {
+
+            Iterator itrBodyChildren = oldEnvelope.getBody().getChildren();
+            while (itrBodyChildren.hasNext()) {
+                OMNode omNode = (OMNode) itrBodyChildren.next();
+
+                if (omNode instanceof SOAPFault) {
+                    SOAPFault soapFault = (SOAPFault) omNode;
+                    if(soapFault != null) {
+                        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);
+
+                            String value = code.getText();
+                            if(value != null) {
+                                SOAPFaultValue newSOAPFaultValue
+                                    = soap12Factory.createSOAPFaultValue(newSOAPFaultCode);
+                                newSOAPFaultValue.setText(value);
+                            }
+
+                        }
+
+                        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);
+                        }
+
+                    } // if(soapFault != null)
+
+                } else {
+                    newEnvelope.getBody().addChild(omNode);
+
+                } // if (omNode instanceof SOAPFault)
+
+            } // while (itrBodyChildren.hasNext())
+
+        } //if (oldEnvelope.getBody() != null)
+
+        axisOutMsgCtx.setEnvelope(newEnvelope);
+    }
+
+    /**
+     * Converts the version of the the message context to 1.1.
+     * <br />
+     * <b>Message Changes:</b>
+     * <ol>
+     *     <li>Convert envelope, header elements</li>
+     *     <li>For each header block convert attribute role to actor</li>
+     *     <li>For each header block convert mustUnderstand value type</li>
+     *     <li>For each header block remove 1.2 namespaced other attributes</li>
+     * </ol>
+     *
+     * <b>Fault Changes:</b>
+     * <ol>
+     *     <li>Convert fault element</li>
+     *     <li>Fault/Code to faultcode</li>
+     *     <li>First Fault/Reason/Text to faultstring</li>
+     * </ol>
+     * @param axisOutMsgCtx
+     * @throws AxisFault
+     */
+    public static void convertSOAP12toSOAP11(
+        org.apache.axis2.context.MessageContext axisOutMsgCtx) throws AxisFault {
+        if (log.isDebugEnabled()) {
+            log.debug("convert SOAP12 to SOAP11");
         }
+        SOAPEnvelope oldEnvelope = axisOutMsgCtx.getEnvelope();
+
+        SOAPFactory soap11Factory = OMAbstractFactory.getSOAP11Factory();
+        SOAPEnvelope newEnvelope  = soap11Factory.getDefaultEnvelope();
+        if (oldEnvelope.getHeader() != null) {
+            Iterator itr = oldEnvelope.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()) {
+                            newSOAPHeader.addChild(((OMNode) itrChildren.next()));
+                        }
+
+                        newEnvelope.getHeader().addChild(newSOAPHeader);
+                    } // while(allAttributes.hasNext())
+
+                } else {
+                    newEnvelope.getHeader().addChild(omNode);
+                } // if (omNode instanceof SOAPHeaderBlock)
+
+            } // while (itr.hasNext())
+
+        } // if (oldEnvelope.getHeader() != null)
 
-        // move all bodies
         if (oldEnvelope.getBody() != null) {
             Iterator itr = oldEnvelope.getBody().getChildren();
             while (itr.hasNext()) {
-                newEnvelope.getBody().addChild(((OMNode) itr.next()));
-            }
-        }
+                OMNode omNode = (OMNode) itr.next();
+
+                if (omNode instanceof SOAPFault) {
+
+                    SOAPFault soapFault = (SOAPFault) omNode;
+                    if(soapFault != null) {
+                        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) {
+                                soap11Factory.createSOAPFaultValue(newSOAPFaultCode);
+                                if(value.getText() != null) {
+                                    newSOAPFaultCode.setText(value.getText());
+                                }
+                            }
+                        }
+
+                        SOAPFaultReason reason = soapFault.getReason();
+                        if(reason != null) {
+                            SOAPFaultReason newSOAPFaultReason
+                                = soap11Factory.createSOAPFaultReason(newSOAPFault);
+
+                            List allSoapTexts = reason.getAllSoapTexts();
+                            Iterator iterAllSoapTexts = allSoapTexts.iterator();
+                            while(iterAllSoapTexts.hasNext()) {
+                                SOAPFaultText soapFaultText
+                                    = (SOAPFaultText) iterAllSoapTexts.next();
+                                SOAPFaultText newSOAPFaultText
+                                    = soap11Factory.createSOAPFaultText(newSOAPFaultReason);
+                                newSOAPFaultReason.setText(soapFaultText.getText());
+                                break;
+                            }
+                        }
+
+                    } // if(soapFault != null)
+
+                } else {
+                    newEnvelope.getBody().addChild(omNode);
+                } // if (omNode instanceof SOAPFault)
+
+            } // while (itr.hasNext())
 
-        // set new envelope to message context; old envelope go to garbage
+        } // if (oldEnvelope.getBody() != null)
         axisOutMsgCtx.setEnvelope(newEnvelope);
     }
 

Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/SynapseCallbackReceiver.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/SynapseCallbackReceiver.java?rev=584729&r1=584728&r2=584729&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/SynapseCallbackReceiver.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/SynapseCallbackReceiver.java Mon Oct 15 03:59:21 2007
@@ -128,7 +128,7 @@
             } else {
                 // TODO invoke a generic synapse error handler for this message
                 log.warn("Synapse received a response for the request with message Id : " +
-                        messageID + " But a callback has not been registered to process this response");
+                    messageID + " But a callback has not been registered to process this response");
             }
 
         } else if (!messageCtx.isPropertyTrue(NhttpConstants.SC_ACCEPTED)){
@@ -147,7 +147,7 @@
      * @throws AxisFault 
      */
     private void handleMessage(MessageContext response,
-                               org.apache.synapse.MessageContext synapseOutMsgCtx) throws AxisFault {
+        org.apache.synapse.MessageContext synapseOutMsgCtx) throws AxisFault {
 
         Object o = response.getProperty(NhttpConstants.SENDING_FAULT);
         if (o != null && Boolean.TRUE.equals(o)) {
@@ -164,9 +164,10 @@
                         if (e == null) {
                             e = new Exception(fault.toString());
                         }
-                        // set an error code to the message context, so that error sequences can filter
-                        // using that property to determine the cause of error
-                        synapseOutMsgCtx.setProperty(SynapseConstants.ERROR_CODE, SynapseConstants.SENDING_FAULT);
+                        // set an error code to the message context, so that error sequences can
+                        // filter using that property to determine the cause of error
+                        synapseOutMsgCtx.setProperty(SynapseConstants.ERROR_CODE,
+                            SynapseConstants.SENDING_FAULT);
                         SOAPFaultReason faultReason = fault.getReason();
                         if (faultReason != null) {
                             synapseOutMsgCtx.setProperty(SynapseConstants.ERROR_MESSAGE,
@@ -182,7 +183,8 @@
             // there can always be only one instance of an Endpoint in the faultStack of a message
             // if the send was successful, so remove it before we proceed any further
             Stack faultStack = synapseOutMsgCtx.getFaultStack();
-            if (faultStack !=null && !faultStack.isEmpty() && faultStack.peek() instanceof Endpoint) {
+            if (faultStack !=null && !faultStack.isEmpty()
+                && faultStack.peek() instanceof Endpoint) {
                 faultStack.pop();
             }
             if (log.isDebugEnabled()) {
@@ -243,9 +245,9 @@
             // if they are different change to original version 
             if(axisOutMsgCtx.isSOAP11() != response.isSOAP11()) {
             	if(axisOutMsgCtx.isSOAP11()) {
-            		SOAPUtils.convertSoapVersion(response, org.apache.axis2.namespace.Constants.URI_SOAP11_ENV);
+            		SOAPUtils.convertSOAP12toSOAP11(response);
             	} else {
-            		SOAPUtils.convertSoapVersion(response, org.apache.axis2.namespace.Constants.URI_SOAP12_ENV);
+            		SOAPUtils.convertSOAP11toSOAP12(response);
             	}
             }
 



---------------------------------------------------------------------
To unsubscribe, e-mail: synapse-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: synapse-dev-help@ws.apache.org