You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by ge...@apache.org on 2008/10/09 12:34:11 UTC

svn commit: r703121 - in /servicemix/components/engines/servicemix-eip/trunk/src: main/java/org/apache/servicemix/eip/ main/java/org/apache/servicemix/eip/patterns/ test/java/org/apache/servicemix/eip/

Author: gertv
Date: Thu Oct  9 03:34:10 2008
New Revision: 703121

URL: http://svn.apache.org/viewvc?rev=703121&view=rev
Log:
SM-1622: servicemix-eip content enricher should copy message properties and attachments

Modified:
    servicemix/components/engines/servicemix-eip/trunk/src/main/java/org/apache/servicemix/eip/EIPEndpoint.java
    servicemix/components/engines/servicemix-eip/trunk/src/main/java/org/apache/servicemix/eip/patterns/ContentEnricher.java
    servicemix/components/engines/servicemix-eip/trunk/src/test/java/org/apache/servicemix/eip/AbstractEIPTest.java
    servicemix/components/engines/servicemix-eip/trunk/src/test/java/org/apache/servicemix/eip/ContentEnricherTest.java

Modified: servicemix/components/engines/servicemix-eip/trunk/src/main/java/org/apache/servicemix/eip/EIPEndpoint.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-eip/trunk/src/main/java/org/apache/servicemix/eip/EIPEndpoint.java?rev=703121&r1=703120&r2=703121&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-eip/trunk/src/main/java/org/apache/servicemix/eip/EIPEndpoint.java (original)
+++ servicemix/components/engines/servicemix-eip/trunk/src/main/java/org/apache/servicemix/eip/EIPEndpoint.java Thu Oct  9 03:34:10 2008
@@ -24,8 +24,8 @@
 import javax.jbi.messaging.ExchangeStatus;
 import javax.jbi.messaging.MessageExchange;
 import javax.jbi.messaging.MessagingException;
-import javax.jbi.messaging.NormalizedMessage;
 import javax.jbi.messaging.MessageExchange.Role;
+import javax.jbi.messaging.NormalizedMessage;
 import javax.jbi.servicedesc.ServiceEndpoint;
 import javax.wsdl.Definition;
 import javax.wsdl.WSDLException;

Modified: servicemix/components/engines/servicemix-eip/trunk/src/main/java/org/apache/servicemix/eip/patterns/ContentEnricher.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-eip/trunk/src/main/java/org/apache/servicemix/eip/patterns/ContentEnricher.java?rev=703121&r1=703120&r2=703121&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-eip/trunk/src/main/java/org/apache/servicemix/eip/patterns/ContentEnricher.java (original)
+++ servicemix/components/engines/servicemix-eip/trunk/src/main/java/org/apache/servicemix/eip/patterns/ContentEnricher.java Thu Oct  9 03:34:10 2008
@@ -20,6 +20,7 @@
 import javax.jbi.messaging.InOnly;
 import javax.jbi.messaging.InOut;
 import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.MessagingException;
 import javax.jbi.messaging.NormalizedMessage;
 import javax.jbi.messaging.RobustInOnly;
 import javax.xml.namespace.QName;
@@ -75,6 +76,16 @@
     private QName resultElementName = new QName("result");
 
     /**
+     * Should message properties be copied ?
+     */
+    private boolean copyProperties;
+
+    /**
+     * Should message attachments be copied ?
+     */
+    private boolean copyAttachments;
+
+    /**
      * returns the QName of the resulting root node
      * @return QName of the resulting root node
      */
@@ -132,6 +143,34 @@
         this.resultElementName = resultElementName;
     }
 
+    public boolean isCopyProperties() {
+        return copyProperties;
+    }
+
+    /**
+     * If this is set to <code>true</code>, message properties from the incoming exchange and the enricher exchange will be copied
+     * to the outgoing message exchange.  The default value is <code>false</code> (do not copy message properties).
+     *
+     * @param copyProperties 
+     */
+    public void setCopyProperties(boolean copyProperties) {
+        this.copyProperties = copyProperties;
+    }
+
+    public boolean isCopyAttachments() {
+        return copyAttachments;
+    }
+
+    /**
+     * If this is set to <code>true</code>, message attachments from the incoming exchange and the enricher exchange will be copied
+     * to the outgoing message exchange.  The default value is <code>false</code> (do not copy message atachments).
+     *
+     * @param copyAttachments
+     */
+    public void setCopyAttachments(boolean copyAttachments) {
+        this.copyAttachments = copyAttachments;
+    }
+
     protected void processAsync(MessageExchange exchange) throws Exception {
         throw new IllegalStateException();
     }
@@ -176,9 +215,13 @@
 
         outExchange.setMessage(out, "in");
 
+        if (copyProperties || copyAttachments) {
+            copyPropertiesAndAttachments(exchange.getMessage("in"), outExchange.getMessage("in"));
+            copyPropertiesAndAttachments(enricherTargetME.getMessage("out"), outExchange.getMessage("in"));
+        }
+        
         sendSync(outExchange);
         done(exchange);
-
     }
 
     /**
@@ -259,4 +302,21 @@
         this.enricherTarget = enricherTarget;
     }
 
+
+    /**
+     * Copies properties and attachments from one message to another
+     * depending on the endpoint configuration
+     *
+     * @param from the message containing the properties and attachments
+     * @param to the destination message where the properties and attachments are set
+     */
+    private void copyPropertiesAndAttachments(NormalizedMessage from, NormalizedMessage to) throws MessagingException {
+        if (copyProperties) {
+            copyProperties(from, to);
+        }
+        if (copyAttachments) {
+            copyAttachments(from, to);
+        }
+    }
+
 }

Modified: servicemix/components/engines/servicemix-eip/trunk/src/test/java/org/apache/servicemix/eip/AbstractEIPTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-eip/trunk/src/test/java/org/apache/servicemix/eip/AbstractEIPTest.java?rev=703121&r1=703120&r2=703121&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-eip/trunk/src/test/java/org/apache/servicemix/eip/AbstractEIPTest.java (original)
+++ servicemix/components/engines/servicemix-eip/trunk/src/test/java/org/apache/servicemix/eip/AbstractEIPTest.java Thu Oct  9 03:34:10 2008
@@ -146,7 +146,13 @@
     }
     
     protected static class ReturnMockComponent extends ComponentSupport implements MessageExchangeListener {
+
+        //message property (name, value) to be set on the generated message
+        public static final String PROPERTY_NAME = "ReturnMockComponentPropName";
+        public static final String PROPERTY_VALUE = "ReturnMockComponentPropValue";
+
         private String response;
+
         public ReturnMockComponent(String response) {
             this.response = response;
         }
@@ -156,6 +162,10 @@
                     && Boolean.TRUE.equals(exchange.getProperty(JbiConstants.SEND_SYNC));
                 NormalizedMessage out = exchange.createMessage();
                 out.setContent(createSource(response));
+
+                //add some message properties
+                out.setProperty(PROPERTY_NAME, PROPERTY_VALUE);
+
                 exchange.setMessage(out, "out");
                 if (txSync) {
                     sendSync(exchange);

Modified: servicemix/components/engines/servicemix-eip/trunk/src/test/java/org/apache/servicemix/eip/ContentEnricherTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-eip/trunk/src/test/java/org/apache/servicemix/eip/ContentEnricherTest.java?rev=703121&r1=703120&r2=703121&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-eip/trunk/src/test/java/org/apache/servicemix/eip/ContentEnricherTest.java (original)
+++ servicemix/components/engines/servicemix-eip/trunk/src/test/java/org/apache/servicemix/eip/ContentEnricherTest.java Thu Oct  9 03:34:10 2008
@@ -93,4 +93,37 @@
         assertEquals(ExchangeStatus.ERROR, me.getStatus());
 
     }
+
+    public void testMsgProperties() throws Exception {
+
+        String propName1 = "propName1";
+        String propName2 = "propName2";
+        String propVal1 = "propVal1";
+        String propVal2 = "propVal2";
+
+        enricher.setCopyProperties(true);
+        
+        activateComponent(new ReturnMockComponent("<helloMock/>"),
+                "enricherTarget");
+
+        ReceiverComponent rec = activateReceiver("target");
+
+        InOnly me = client.createInOnlyExchange();
+
+        me.setService(new QName("enricher"));
+        me.getInMessage().setContent(createSource("<hello/>"));
+        me.getInMessage().setProperty(propName1, propVal1);
+        me.getInMessage().setProperty(propName2, propVal2);
+        client.sendSync(me);
+                
+        NormalizedMessage msg = (NormalizedMessage) rec.getMessageList()
+            .getMessages().get(0);
+
+        //assertions
+        assertEquals(ExchangeStatus.DONE, me.getStatus());
+        assertEquals(1, rec.getMessageList().getMessageCount());
+        assertEquals(propVal1, msg.getProperty(propName1));
+        assertEquals(propVal2, msg.getProperty(propName2));
+        assertEquals(ReturnMockComponent.PROPERTY_VALUE, msg.getProperty(ReturnMockComponent.PROPERTY_NAME));
+    }
 }