synapse-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ru...@apache.org
Subject svn commit: r601692 - in /webservices/synapse/trunk/java/modules: core/src/main/java/org/apache/synapse/mediators/eip/splitter/ core/src/main/java/org/apache/synapse/util/ samples/src/main/java/samples/userguide/
Date Thu, 06 Dec 2007 10:52:52 GMT
Author: ruwan
Date: Thu Dec  6 02:52:52 2007
New Revision: 601692

URL: http://svn.apache.org/viewvc?rev=601692&view=rev
Log:
Minor refatoring and reformatting

Modified:
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eip/splitter/IterateMediator.java
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/MessageHelper.java
    webservices/synapse/trunk/java/modules/samples/src/main/java/samples/userguide/GenericJMSClient.java

Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eip/splitter/IterateMediator.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eip/splitter/IterateMediator.java?rev=601692&r1=601691&r2=601692&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eip/splitter/IterateMediator.java
(original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eip/splitter/IterateMediator.java
Thu Dec  6 02:52:52 2007
@@ -119,54 +119,21 @@
                 // iterate through the list
                 for (Object o : splitElements) {
 
-                    // clone the message for the mediation in iteration
-                    MessageContext newCtx = MessageHelper.cloneMessageContext(synCtx);
-                    // set the messageSequence property for possibal aggreagtions
-                    newCtx.setProperty(EIPConstants.MESSAGE_SEQUENCE,
-                        msgNumber + EIPConstants.MESSAGE_SEQUENCE_DELEMITER + msgCount);
-                    // get a clone of the envelope to be attached
-                    SOAPEnvelope newEnvelope = MessageHelper.cloneSOAPEnvelope(envelope);
-
                     // for the moment iterator will look for an OMNode as the iteration element
                     if (!(o instanceof OMNode)) {
-                        handleException(
-                            "Error in splitting the message with expression : " + expression,
-                            synCtx);
-                    }
-
-                    // if payload should be preserved then attach the iteration element to
the
-                    // node specified by the attachPath
-                    if (preservePayload) {
-
-                        Object attachElem = attachPath.evaluate(newEnvelope);
-                        if (attachElem instanceof List) {
-                            attachElem = ((List) attachElem).get(0);
-                        }
-
-                        // for the moment attaching element should be an OMElement
-                        if (attachElem instanceof OMElement) {
-                            ((OMElement) attachElem).addChild((OMNode) o);
-                        } else {
-                            handleException("Error in attaching the splitted elements ::
" +
-                                "Unable to get the attach path specified by the expression
" +
-                                attachPath, synCtx);
-                        }
-                        // if not preserve payload then attach the iteration element to the
body
-                    } else if (o instanceof OMNode && newEnvelope.getBody() != null)
{
-                        newEnvelope.getBody().addChild((OMNode) o);
+                        handleException("Error in splitting the message with expression :
"
+                            + expression, synCtx);
                     }
 
-                    // set the envelope ant mediate as specified in the target
-                    newCtx.setEnvelope(newEnvelope);
-                    target.mediate(newCtx);
+                    target.mediate(
+                        getIteratedMessage(synCtx, msgNumber, msgCount, envelope, (OMNode)
o));
                     msgNumber++;
 
                 }
 
             } else {
-                handleException(
-                    "Splitting by expression : " + expression + " did not yeild in an OMElement",
-                    synCtx);
+                handleException("Splitting by expression : " + expression
+                    + " did not yeild in an OMElement", synCtx);
             }
 
         } catch (JaxenException e) {
@@ -191,6 +158,57 @@
 
         // whether to continue mediation on the original message
         return continueParent;
+    }
+
+    /**
+     * This will create a new message context with the iteration parameters
+     *
+     * @param synCtx    - original message context
+     * @param msgNumber - message number in the iteration
+     * @param msgCount  - message count in the iteration
+     * @param envelope  - cloned envelope to be used in the iteration
+     * @param o         - element which participates in the iteration replacement
+     * @return newCtx created by the iteration
+     * @throws AxisFault if there is a message creation failure
+     * @throws JaxenException if the expression evauation failure
+     */
+    private MessageContext getIteratedMessage(MessageContext synCtx, int msgNumber, int msgCount,
+        SOAPEnvelope envelope, OMNode o) throws AxisFault, JaxenException {
+        
+        // clone the message for the mediation in iteration
+        MessageContext newCtx = MessageHelper.cloneMessageContext(synCtx);
+        // set the messageSequence property for possibal aggreagtions
+        newCtx.setProperty(EIPConstants.MESSAGE_SEQUENCE,
+            msgNumber + EIPConstants.MESSAGE_SEQUENCE_DELEMITER + msgCount);
+        // get a clone of the envelope to be attached
+        SOAPEnvelope newEnvelope = MessageHelper.cloneSOAPEnvelope(envelope);
+
+        // if payload should be preserved then attach the iteration element to the
+        // node specified by the attachPath
+        if (preservePayload) {
+
+            Object attachElem = attachPath.evaluate(newEnvelope);
+            if (attachElem instanceof List) {
+                attachElem = ((List) attachElem).get(0);
+            }
+
+            // for the moment attaching element should be an OMElement
+            if (attachElem instanceof OMElement) {
+                ((OMElement) attachElem).addChild(o);
+            } else {
+                handleException("Error in attaching the splitted elements :: " +
+                    "Unable to get the attach path specified by the expression " +
+                    attachPath, synCtx);
+            }
+            // if not preserve payload then attach the iteration element to the body
+        } else if (newEnvelope.getBody() != null) {
+            newEnvelope.getBody().addChild(o);
+        }
+
+        // set the envelope ant mediate as specified in the target
+        newCtx.setEnvelope(newEnvelope);
+
+        return newCtx;
     }
 
     ///////////////////////////////////////////////////////////////////////////////////////

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=601692&r1=601691&r2=601692&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 Dec  6 02:52:52 2007
@@ -179,10 +179,9 @@
         for (Object o1 : ori.getProperties().keySet()) {
             String key = (String) o1;
             if (key != null) {
-                //In clustered environment, all the properties that are need to be relpicated,
-                //will be replicated explicitly  by the corresponding  Mediators
-                //(Ex: throttle,cache),therefore It should avoid any implicitly replication
from
-                //any other component.
+                // In a clustered environment, all the properties that need to be relpicated,
+                // are replicated explicitly  by the corresponding Mediators (Ex: throttle,
+                // cache), and therefore we should avoid any implicit replication
                 newMC.setNonReplicableProperty(key, ori.getPropertyNonReplicable(key));
             }
         }

Modified: webservices/synapse/trunk/java/modules/samples/src/main/java/samples/userguide/GenericJMSClient.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/samples/src/main/java/samples/userguide/GenericJMSClient.java?rev=601692&r1=601691&r2=601692&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/samples/src/main/java/samples/userguide/GenericJMSClient.java
(original)
+++ webservices/synapse/trunk/java/modules/samples/src/main/java/samples/userguide/GenericJMSClient.java
Thu Dec  6 02:52:52 2007
@@ -70,8 +70,10 @@
     private void sendBytesMessage(String destName, byte[] payload) throws Exception {
         InitialContext ic = getInitialContext();
         ConnectionFactory confac = (ConnectionFactory) ic.lookup("ConnectionFactory");
-        Connection connection = JMSUtils.createConnection(confac, null, null, JMSConstants.DESTINATION_TYPE_QUEUE);
-        Session session = JMSUtils.createSession(connection, false, Session.AUTO_ACKNOWLEDGE,
JMSConstants.DESTINATION_TYPE_QUEUE);
+        Connection connection = JMSUtils.createConnection(
+            confac, null, null, JMSConstants.DESTINATION_TYPE_QUEUE);
+        Session session = JMSUtils.createSession(
+            connection, false, Session.AUTO_ACKNOWLEDGE, JMSConstants.DESTINATION_TYPE_QUEUE);
 
         BytesMessage bm = session.createBytesMessage();
         bm.writeBytes(payload);
@@ -82,8 +84,10 @@
     private void sendTextMessage(String destName, String payload) throws Exception {
         InitialContext ic = getInitialContext();
         ConnectionFactory confac = (ConnectionFactory) ic.lookup("ConnectionFactory");
-        Connection connection = JMSUtils.createConnection(confac, null, null, JMSConstants.DESTINATION_TYPE_QUEUE);
-        Session session = JMSUtils.createSession(connection, false, Session.AUTO_ACKNOWLEDGE,
JMSConstants.DESTINATION_TYPE_QUEUE);
+        Connection connection = JMSUtils.createConnection(
+            confac, null, null, JMSConstants.DESTINATION_TYPE_QUEUE);
+        Session session = JMSUtils.createSession(
+            connection, false, Session.AUTO_ACKNOWLEDGE, JMSConstants.DESTINATION_TYPE_QUEUE);
 
         TextMessage tm = session.createTextMessage(payload);
         JMSUtils.sendMessageToJMSDestination(session, (Destination) ic.lookup(destName),
tm);
@@ -96,7 +100,8 @@
             env.put("java.naming.provider.url", "tcp://localhost:61616");
         }
         if (System.getProperty("java.naming.factory.initial") == null) {
-            env.put("java.naming.factory.initial", "org.apache.activemq.jndi.ActiveMQInitialContextFactory");
+            env.put("java.naming.factory.initial",
+                "org.apache.activemq.jndi.ActiveMQInitialContextFactory");
         }
         return new InitialContext(env);
     }



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


Mime
View raw message