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/11 14:21:19 UTC

svn commit: r583797 - in /webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse: core/axis2/Axis2FlexibleMEPClient.java util/MessageHelper.java

Author: ruwan
Date: Thu Oct 11 05:21:18 2007
New Revision: 583797

URL: http://svn.apache.org/viewvc?rev=583797&view=rev
Log:
Sharing the core part of the method cloneForSend to the MessageHelper

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/util/MessageHelper.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=583797&r1=583796&r2=583797&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 Thu Oct 11 05:21:18 2007
@@ -46,6 +46,7 @@
 import org.apache.axis2.description.AxisServiceGroup;
 import org.apache.axis2.engine.AxisConfiguration;
 import org.apache.synapse.util.UUIDGenerator;
+import org.apache.synapse.util.MessageHelper;
 import org.apache.axiom.attachments.Attachments;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -255,42 +256,9 @@
    }
 
     private static MessageContext cloneForSend(MessageContext ori) throws AxisFault {
-        MessageContext newMC = new MessageContext();
 
-        // do not copy options from the original
-        newMC.setConfigurationContext(ori.getConfigurationContext());
-        newMC.setMessageID(UUIDGenerator.getUUID());
-        newMC.setTo(ori.getTo());
-        newMC.setSoapAction(ori.getSoapAction());
-
-        newMC.setProperty(org.apache.axis2.Constants.Configuration.CHARACTER_SET_ENCODING,
-                ori.getProperty(org.apache.axis2.Constants.Configuration.CHARACTER_SET_ENCODING));
-        newMC.setProperty(org.apache.axis2.Constants.Configuration.ENABLE_MTOM,
-                ori.getProperty(org.apache.axis2.Constants.Configuration.ENABLE_MTOM));
-        newMC.setProperty(org.apache.axis2.Constants.Configuration.ENABLE_SWA,
-                ori.getProperty(org.apache.axis2.Constants.Configuration.ENABLE_SWA));
-
-        newMC.setDoingREST(ori.isDoingREST());
-        newMC.setDoingMTOM(ori.isDoingMTOM());
-        newMC.setDoingSwA(ori.isDoingSwA());
-
-        // if the original request carries any attachments, copy them to the clone
-        // as well, except for the soap part if any
-        Attachments attachments = ori.getAttachmentMap();
-        if (attachments != null && attachments.getAllContentIDs().length > 0) {
-            String[] cIDs = attachments.getAllContentIDs();
-            String soapPart = attachments.getSOAPPartContentID();
-            for (int i=0; i<cIDs.length; i++) {
-                if (!cIDs[i].equals(soapPart)) {
-                    newMC.addAttachment(cIDs[i], attachments.getDataHandler(cIDs[i]));
-                }
-            }
-        }
-
-        newMC.setServerSide(false);
+        MessageContext newMC = MessageHelper.clonePartially(ori);
 
-        // set SOAP envelope on the message context, removing WS-A headers
-        newMC.setEnvelope(ori.getEnvelope());
         removeAddressingHeaders(newMC);
 
         // pass any transport headers on the original request

Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/MessageHelper.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/MessageHelper.java?rev=583797&r1=583796&r2=583797&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/MessageHelper.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/MessageHelper.java Thu Oct 11 05:21:18 2007
@@ -87,11 +87,8 @@
     public static org.apache.axis2.context.MessageContext cloneAxis2MessageContext(
         org.apache.axis2.context.MessageContext mc) throws AxisFault {
 
-        org.apache.axis2.context.MessageContext newMC =
-            new org.apache.axis2.context.MessageContext();
+        org.apache.axis2.context.MessageContext newMC = clonePartially(mc);
 
-        // do not copy options from the original todo: Y?
-        newMC.setConfigurationContext(mc.getConfigurationContext());
         newMC.setServiceContext(mc.getServiceContext());
         newMC.setOperationContext(mc.getOperationContext());
         newMC.setAxisMessage(mc.getAxisMessage());
@@ -99,30 +96,55 @@
             newMC.getAxisMessage().setParent(mc.getAxisOperation());
         }
         newMC.setAxisService(mc.getAxisService());
+
+        // copying transport related parts from the original
+        newMC.setTransportIn(mc.getTransportIn());
+        newMC.setTransportOut(mc.getTransportOut());
+        newMC.setProperty(org.apache.axis2.Constants.OUT_TRANSPORT_INFO,
+            mc.getProperty(org.apache.axis2.Constants.OUT_TRANSPORT_INFO));
+        newMC.setProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS,
+            mc.getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS));
+
+        // Copying properties in the original message
+        Iterator iter = mc.getProperties().keySet().iterator();
+        while (iter.hasNext()) {
+            String key = (String) iter.next();
+            newMC.setProperty(key, mc.getProperty(key));
+        }
+
+        return newMC;
+    }
+
+    public static org.apache.axis2.context.MessageContext clonePartially(
+        org.apache.axis2.context.MessageContext ori) throws AxisFault {
+
+        org.apache.axis2.context.MessageContext newMC
+            = new org.apache.axis2.context.MessageContext();
+        
+        // do not copy options from the original
+        newMC.setConfigurationContext(ori.getConfigurationContext());
         newMC.setMessageID(UUIDGenerator.getUUID());
-        newMC.setTo(mc.getTo());
-        newMC.setSoapAction(mc.getSoapAction());
+        newMC.setTo(ori.getTo());
+        newMC.setSoapAction(ori.getSoapAction());
 
-        // copying behavioral attributes from the original message
         newMC.setProperty(org.apache.axis2.Constants.Configuration.CHARACTER_SET_ENCODING,
-            mc.getProperty(org.apache.axis2.Constants.Configuration.CHARACTER_SET_ENCODING));
+                ori.getProperty(org.apache.axis2.Constants.Configuration.CHARACTER_SET_ENCODING));
         newMC.setProperty(org.apache.axis2.Constants.Configuration.ENABLE_MTOM,
-            mc.getProperty(org.apache.axis2.Constants.Configuration.ENABLE_MTOM));
+                ori.getProperty(org.apache.axis2.Constants.Configuration.ENABLE_MTOM));
         newMC.setProperty(org.apache.axis2.Constants.Configuration.ENABLE_SWA,
-            mc.getProperty(org.apache.axis2.Constants.Configuration.ENABLE_SWA));
+                ori.getProperty(org.apache.axis2.Constants.Configuration.ENABLE_SWA));
 
-        // todo: isnt this duplicate with the above
-        newMC.setDoingREST(mc.isDoingREST());
-        newMC.setDoingMTOM(mc.isDoingMTOM());
-        newMC.setDoingSwA(mc.isDoingSwA());
+        newMC.setDoingREST(ori.isDoingREST());
+        newMC.setDoingMTOM(ori.isDoingMTOM());
+        newMC.setDoingSwA(ori.isDoingSwA());
 
         // if the original request carries any attachments, copy them to the clone
         // as well, except for the soap part if any
-        Attachments attachments = mc.getAttachmentMap();
+        Attachments attachments = ori.getAttachmentMap();
         if (attachments != null && attachments.getAllContentIDs().length > 0) {
             String[] cIDs = attachments.getAllContentIDs();
             String soapPart = attachments.getSOAPPartContentID();
-            for (int i = 0; i < cIDs.length; i++) {
+            for (int i=0; i<cIDs.length; i++) {
                 if (!cIDs[i].equals(soapPart)) {
                     newMC.addAttachment(cIDs[i], attachments.getDataHandler(cIDs[i]));
                 }
@@ -131,23 +153,8 @@
 
         newMC.setServerSide(false);
 
-        // attaching the cloned envelope to the new message context
-        newMC.setEnvelope(cloneSOAPEnvelope(mc.getEnvelope()));
-
-        // copying transport related parts from the original
-        newMC.setTransportIn(mc.getTransportIn());
-        newMC.setTransportOut(mc.getTransportOut());
-        newMC.setProperty(org.apache.axis2.Constants.OUT_TRANSPORT_INFO,
-            mc.getProperty(org.apache.axis2.Constants.OUT_TRANSPORT_INFO));
-        newMC.setProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS,
-            mc.getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS));
-
-        // Copying properties in the original message
-        Iterator iter = mc.getProperties().keySet().iterator();
-        while (iter.hasNext()) {
-            String key = (String) iter.next();
-            newMC.setProperty(key, mc.getProperty(key));
-        }
+        // set SOAP envelope on the message context, removing WS-A headers
+        newMC.setEnvelope(cloneSOAPEnvelope(ori.getEnvelope()));
 
         return newMC;
     }



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