servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lh...@apache.org
Subject svn commit: r721125 - in /servicemix/components/engines/servicemix-scripting/trunk/src: main/java/org/apache/servicemix/scripting/ScriptingEndpoint.java test/java/org/apache/servicemix/scripting/ScriptingComponentTest.java test/resources/spring.xml
Date Thu, 27 Nov 2008 08:51:44 GMT
Author: lhein
Date: Thu Nov 27 00:51:43 2008
New Revision: 721125

URL: http://svn.apache.org/viewvc?rev=721125&view=rev
Log:
it's now configurable if headers and/or attachments are copied from in msg to out msg automatically
by setting endpoint attributes correctly

Modified:
    servicemix/components/engines/servicemix-scripting/trunk/src/main/java/org/apache/servicemix/scripting/ScriptingEndpoint.java
    servicemix/components/engines/servicemix-scripting/trunk/src/test/java/org/apache/servicemix/scripting/ScriptingComponentTest.java
    servicemix/components/engines/servicemix-scripting/trunk/src/test/resources/spring.xml

Modified: servicemix/components/engines/servicemix-scripting/trunk/src/main/java/org/apache/servicemix/scripting/ScriptingEndpoint.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-scripting/trunk/src/main/java/org/apache/servicemix/scripting/ScriptingEndpoint.java?rev=721125&r1=721124&r2=721125&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-scripting/trunk/src/main/java/org/apache/servicemix/scripting/ScriptingEndpoint.java
(original)
+++ servicemix/components/engines/servicemix-scripting/trunk/src/main/java/org/apache/servicemix/scripting/ScriptingEndpoint.java
Thu Nov 27 00:51:43 2008
@@ -225,10 +225,14 @@
                 // Fault message
                 done(exchange);
             } else {
+                InOnly outExchange = null;
+                NormalizedMessage outMsg = null;
+                NormalizedMessage inMsg = exchange.getMessage("in");
+
                 Bindings scriptBindings = engine.createBindings();
                 scriptBindings.put(KEY_CONTEXT, getContext());
                 scriptBindings.put(KEY_IN_EXCHANGE, exchange);
-                scriptBindings.put(KEY_IN_MSG, exchange.getMessage("in"));
+                scriptBindings.put(KEY_IN_MSG, inMsg);
                 scriptBindings.put(KEY_ENDPOINT, this);
                 scriptBindings.put(KEY_CHANNEL, getChannel());
                 scriptBindings.put(KEY_ENDPOINTNAME, getEndpoint());
@@ -236,8 +240,6 @@
                 scriptBindings.put(KEY_INTERFACENAME, getInterfaceName());
                 scriptBindings.put(KEY_LOGGER, getScriptLogger());
 
-                InOnly outExchange = null;
-                
                 if (exchange instanceof InOnly || exchange instanceof RobustInOnly) {
                     outExchange = getExchangeFactory().createInOnlyExchange();
                     String processCorrelationId = (String)exchange.getProperty(JbiConstants.CORRELATION_ID);
@@ -245,13 +247,13 @@
                         outExchange.setProperty(JbiConstants.CORRELATION_ID, processCorrelationId);
                     }                    
                     
-                    NormalizedMessage outMsg = outExchange.createMessage();
+                    outMsg = outExchange.createMessage();
                     outExchange.setMessage(outMsg, "in");
                     
                     scriptBindings.put(KEY_OUT_EXCHANGE, outExchange);
                     scriptBindings.put(KEY_OUT_MSG, outMsg);                    
                 } else {
-                    NormalizedMessage outMsg = exchange.createMessage();
+                    outMsg = exchange.createMessage();
                     exchange.setMessage(outMsg, "out");
                     scriptBindings.put(KEY_OUT_EXCHANGE, exchange);
                     scriptBindings.put(KEY_OUT_MSG, outMsg);
@@ -313,6 +315,16 @@
                 if (!isDisableOutput()) {
                     boolean txSync = exchange.isTransacted() && Boolean.TRUE.equals(exchange.getProperty(JbiConstants.SEND_SYNC));
                     
+                    // copy headers
+                    if (isCopyProperties()) {
+                        copyProperties(inMsg, outMsg);
+                    }
+                    
+                    // copy attachments
+                    if (isCopyAttachments()) {
+                        copyAttachments(inMsg, outMsg);
+                    }                                        
+                    
                     // on InOut exchanges we always do answer
                     if (exchange instanceof InOut || exchange instanceof InOptionalOut) {
                         if (txSync) {

Modified: servicemix/components/engines/servicemix-scripting/trunk/src/test/java/org/apache/servicemix/scripting/ScriptingComponentTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-scripting/trunk/src/test/java/org/apache/servicemix/scripting/ScriptingComponentTest.java?rev=721125&r1=721124&r2=721125&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-scripting/trunk/src/test/java/org/apache/servicemix/scripting/ScriptingComponentTest.java
(original)
+++ servicemix/components/engines/servicemix-scripting/trunk/src/test/java/org/apache/servicemix/scripting/ScriptingComponentTest.java
Thu Nov 27 00:51:43 2008
@@ -16,24 +16,26 @@
  */
 package org.apache.servicemix.scripting;
 
+import javax.activation.DataHandler;
 import javax.jbi.messaging.ExchangeStatus;
 import javax.jbi.messaging.InOnly;
 import javax.jbi.messaging.InOut;
+import javax.jbi.messaging.NormalizedMessage;
 import javax.xml.namespace.QName;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.apache.servicemix.client.DefaultServiceMixClient;
 import org.apache.servicemix.jbi.jaxp.SourceTransformer;
 import org.apache.servicemix.jbi.jaxp.StringSource;
 import org.apache.servicemix.tck.Receiver;
 import org.apache.servicemix.tck.SpringTestSupport;
+import org.apache.servicemix.util.jaf.ByteArrayDataSource;
 import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
 import org.springframework.context.support.AbstractXmlApplicationContext;
 
 public class ScriptingComponentTest extends SpringTestSupport {
-    private static transient Log log = LogFactory.getLog(ScriptingComponentTest.class);
-
+    private static final String TEST_PROPERTY = "JSR-223-TEST-PROPERTY-NAME";
+    private static final String PROP_VALUE    = "JSR-223-TEST-PROPERTY-VALUE";
+    
     public void testGroovyInOut() throws Exception {
         DefaultServiceMixClient client = new DefaultServiceMixClient(jbi);
         InOut me = client.createInOutExchange();
@@ -49,6 +51,8 @@
         } else if (me.getFault() != null) {
             fail("Received fault: " + new SourceTransformer().toString(me.getFault().getContent()));
         }
+        assertNotNull("The out message was null...", me.getOutMessage());
+        assertNotNull("The out message content was null...", me.getOutMessage().getContent());
         System.err.println(new SourceTransformer().toString(me.getOutMessage().getContent()));
         client.done(me);
     }
@@ -63,6 +67,8 @@
         
         if (me.getStatus() == ExchangeStatus.DONE) {
             receiver.getMessageList().assertMessagesReceived(1);
+            NormalizedMessage msg = (NormalizedMessage)receiver.getMessageList().getMessages().get(0);
+            assertNotNull("The out message content was null...", msg.getContent());
         } else {
             if (me.getStatus() == ExchangeStatus.ERROR) {
                 if (me.getError() != null) {
@@ -91,6 +97,8 @@
         } else if (me.getFault() != null) {
             fail("Received fault: " + new SourceTransformer().toString(me.getFault().getContent()));
         }
+        assertNotNull("The out message was null...", me.getOutMessage());
+        assertNotNull("The out message content was null...", me.getOutMessage().getContent());
         System.err.println(new SourceTransformer().toString(me.getOutMessage().getContent()));
         client.done(me);
     }
@@ -105,6 +113,8 @@
         
         if (me.getStatus() == ExchangeStatus.DONE) {
             receiver.getMessageList().assertMessagesReceived(1);
+            NormalizedMessage msg = (NormalizedMessage)receiver.getMessageList().getMessages().get(0);
+            assertNotNull("The out message content was null...", msg.getContent());
         } else {
             if (me.getStatus() == ExchangeStatus.ERROR) {
                 if (me.getError() != null) {
@@ -133,6 +143,8 @@
         } else if (me.getFault() != null) {
             fail("Received fault: " + new SourceTransformer().toString(me.getFault().getContent()));
         }
+        assertNotNull("The out message was null...", me.getOutMessage());
+        assertNotNull("The out message content was null...", me.getOutMessage().getContent());
         System.err.println(new SourceTransformer().toString(me.getOutMessage().getContent()));
         client.done(me);
     }
@@ -147,6 +159,174 @@
         
         if (me.getStatus() == ExchangeStatus.DONE) {
             receiver.getMessageList().assertMessagesReceived(1);
+            NormalizedMessage msg = (NormalizedMessage)receiver.getMessageList().getMessages().get(0);
+            assertNotNull("The out message content was null...", msg.getContent());
+        } else {
+            if (me.getStatus() == ExchangeStatus.ERROR) {
+                if (me.getError() != null) {
+                    throw me.getError();
+                } else {
+                    fail("Received ERROR status");
+                }
+            } else if (me.getFault() != null) {
+                fail("Received fault: " + new SourceTransformer().toString(me.getFault().getContent()));
+            }    
+        }                
+    }
+    
+    public void testJavaScriptInOutAll() throws Exception {
+        DefaultServiceMixClient client = new DefaultServiceMixClient(jbi);
+        InOut me = client.createInOutExchange();
+        me.setService(new QName("urn:test", "js-all"));
+        me.getInMessage().setContent(new StringSource("<hello>jsr-223</hello>"));
+        me.getInMessage().setProperty(TEST_PROPERTY, PROP_VALUE);
+        me.getInMessage().addAttachment(TEST_PROPERTY, new DataHandler(new ByteArrayDataSource(PROP_VALUE.getBytes(),
"raw")));
+        client.sendSync(me);
+        if (me.getStatus() == ExchangeStatus.ERROR) {
+            if (me.getError() != null) {
+                throw me.getError();
+            } else {
+                fail("Received ERROR status");
+            }
+        } else if (me.getFault() != null) {
+            fail("Received fault: " + new SourceTransformer().toString(me.getFault().getContent()));
+        }
+        assertNotNull("The out message was null...", me.getOutMessage());
+        assertNotNull("The out message content was null...", me.getOutMessage().getContent());
+        assertNotNull("The attachment was not copied to out message...", me.getOutMessage().getAttachment(TEST_PROPERTY));
+        assertNotNull("The property was not copied to out message...", me.getOutMessage().getProperty(TEST_PROPERTY));
+        assertEquals("The property was not copied to out message correctly...", PROP_VALUE,
me.getOutMessage().getProperty(TEST_PROPERTY));
+        
+        client.done(me);
+    }
+    
+    public void testJavaScriptInOnlyAll() throws Exception {
+        DefaultServiceMixClient client = new DefaultServiceMixClient(jbi);
+        Receiver receiver = (Receiver) getBean("receiver");
+        InOnly me = client.createInOnlyExchange();
+        me.setService(new QName("urn:test", "js-all"));
+        me.getInMessage().setContent(new StringSource("<hello>jsr-223</hello>"));
+        me.getInMessage().setProperty(TEST_PROPERTY, PROP_VALUE);
+        me.getInMessage().addAttachment(TEST_PROPERTY, new DataHandler(new ByteArrayDataSource(PROP_VALUE.getBytes(),
"raw")));
+        client.sendSync(me);
+        
+        if (me.getStatus() == ExchangeStatus.DONE) {
+            receiver.getMessageList().assertMessagesReceived(1);
+            NormalizedMessage msg = (NormalizedMessage)receiver.getMessageList().getMessages().get(0);
+            assertNotNull("The out message content was null...", msg.getContent());
+            assertNotNull("The attachment was not copied to out message...", msg.getAttachment(TEST_PROPERTY));
+            assertNotNull("The property was not copied to out message...", msg.getProperty(TEST_PROPERTY));
+            assertEquals("The property was not copied to out message correctly...", PROP_VALUE,
msg.getProperty(TEST_PROPERTY));
+        } else {
+            if (me.getStatus() == ExchangeStatus.ERROR) {
+                if (me.getError() != null) {
+                    throw me.getError();
+                } else {
+                    fail("Received ERROR status");
+                }
+            } else if (me.getFault() != null) {
+                fail("Received fault: " + new SourceTransformer().toString(me.getFault().getContent()));
+            }    
+        }                
+    }
+    
+    public void testJavaScriptInOutOnlyHeaders() throws Exception {
+        DefaultServiceMixClient client = new DefaultServiceMixClient(jbi);
+        InOut me = client.createInOutExchange();
+        me.setService(new QName("urn:test", "js-headersOnly"));
+        me.getInMessage().setContent(new StringSource("<hello>jsr-223</hello>"));
+        me.getInMessage().setProperty(TEST_PROPERTY, PROP_VALUE);
+        me.getInMessage().addAttachment(TEST_PROPERTY, new DataHandler(new ByteArrayDataSource(PROP_VALUE.getBytes(),
"raw")));
+        client.sendSync(me);
+        if (me.getStatus() == ExchangeStatus.ERROR) {
+            if (me.getError() != null) {
+                throw me.getError();
+            } else {
+                fail("Received ERROR status");
+            }
+        } else if (me.getFault() != null) {
+            fail("Received fault: " + new SourceTransformer().toString(me.getFault().getContent()));
+        }
+        assertNotNull("The out message was null...", me.getOutMessage());
+        assertNotNull("The out message content was null...", me.getOutMessage().getContent());
+        assertNull("The attachment was copied to out message...", me.getOutMessage().getAttachment(TEST_PROPERTY));
+        assertNotNull("The property was not copied to out message...", me.getOutMessage().getProperty(TEST_PROPERTY));
+        assertEquals("The property was not copied to out message correctly...", PROP_VALUE,
me.getOutMessage().getProperty(TEST_PROPERTY));
+        
+        client.done(me);
+    }
+    
+    public void testJavaScriptInOnlyOnlyHeaders() throws Exception {
+        DefaultServiceMixClient client = new DefaultServiceMixClient(jbi);
+        Receiver receiver = (Receiver) getBean("receiver");
+        InOnly me = client.createInOnlyExchange();
+        me.setService(new QName("urn:test", "js-headersOnly"));
+        me.getInMessage().setContent(new StringSource("<hello>jsr-223</hello>"));
+        me.getInMessage().setProperty(TEST_PROPERTY, PROP_VALUE);
+        me.getInMessage().addAttachment(TEST_PROPERTY, new DataHandler(new ByteArrayDataSource(PROP_VALUE.getBytes(),
"raw")));
+        client.sendSync(me);
+        
+        if (me.getStatus() == ExchangeStatus.DONE) {
+            receiver.getMessageList().assertMessagesReceived(1);
+            NormalizedMessage msg = (NormalizedMessage)receiver.getMessageList().getMessages().get(0);
+            assertNotNull("The out message content was null...", msg.getContent());
+            assertNull("The attachment was copied to out message...", msg.getAttachment(TEST_PROPERTY));
+            assertNotNull("The property was not copied to out message...", msg.getProperty(TEST_PROPERTY));
+            assertEquals("The property was not copied to out message correctly...", PROP_VALUE,
msg.getProperty(TEST_PROPERTY));
+        } else {
+            if (me.getStatus() == ExchangeStatus.ERROR) {
+                if (me.getError() != null) {
+                    throw me.getError();
+                } else {
+                    fail("Received ERROR status");
+                }
+            } else if (me.getFault() != null) {
+                fail("Received fault: " + new SourceTransformer().toString(me.getFault().getContent()));
+            }    
+        }                
+    }
+    
+    public void testJavaScriptInOutOnlyAttachments() throws Exception {
+        DefaultServiceMixClient client = new DefaultServiceMixClient(jbi);
+        InOut me = client.createInOutExchange();
+        me.setService(new QName("urn:test", "js-attachmentsOnly"));
+        me.getInMessage().setContent(new StringSource("<hello>jsr-223</hello>"));
+        me.getInMessage().setProperty(TEST_PROPERTY, PROP_VALUE);
+        me.getInMessage().addAttachment(TEST_PROPERTY, new DataHandler(new ByteArrayDataSource(PROP_VALUE.getBytes(),
"raw")));
+        client.sendSync(me);
+        if (me.getStatus() == ExchangeStatus.ERROR) {
+            if (me.getError() != null) {
+                throw me.getError();
+            } else {
+                fail("Received ERROR status");
+            }
+        } else if (me.getFault() != null) {
+            fail("Received fault: " + new SourceTransformer().toString(me.getFault().getContent()));
+        }
+        assertNotNull("The out message was null...", me.getOutMessage());
+        assertNotNull("The out message content was null...", me.getOutMessage().getContent());
+        assertNotNull("The attachment was not copied to out message...", me.getOutMessage().getAttachment(TEST_PROPERTY));
+        assertNull("The property was copied to out message...", me.getOutMessage().getProperty(TEST_PROPERTY));
+        
+        client.done(me);
+    }
+    
+    public void testJavaScriptInOnlyOnlyAttachments() throws Exception {
+        DefaultServiceMixClient client = new DefaultServiceMixClient(jbi);
+        Receiver receiver = (Receiver) getBean("receiver");
+        InOnly me = client.createInOnlyExchange();
+        me.setService(new QName("urn:test", "js-attachmentsOnly"));
+        me.getInMessage().setContent(new StringSource("<hello>jsr-223</hello>"));
+        me.getInMessage().setProperty(TEST_PROPERTY, PROP_VALUE);
+        me.getInMessage().addAttachment(TEST_PROPERTY, new DataHandler(new ByteArrayDataSource(PROP_VALUE.getBytes(),
"raw")));
+        client.sendSync(me);
+        
+        if (me.getStatus() == ExchangeStatus.DONE) {
+            receiver.getMessageList().assertMessagesReceived(1);
+            NormalizedMessage msg = (NormalizedMessage)receiver.getMessageList().getMessages().get(0);
+            assertNotNull("The out message content was null...", msg.getContent());
+            assertNotNull("The attachment was not copied to out message...", msg.getAttachment(TEST_PROPERTY));
+            assertNull("The property was copied to out message...", msg.getProperty(TEST_PROPERTY));
         } else {
             if (me.getStatus() == ExchangeStatus.ERROR) {
                 if (me.getError() != null) {

Modified: servicemix/components/engines/servicemix-scripting/trunk/src/test/resources/spring.xml
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-scripting/trunk/src/test/resources/spring.xml?rev=721125&r1=721124&r2=721125&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-scripting/trunk/src/test/resources/spring.xml
(original)
+++ servicemix/components/engines/servicemix-scripting/trunk/src/test/resources/spring.xml
Thu Nov 27 00:51:43 2008
@@ -63,6 +63,34 @@
                        targetService="test:receiver">
             </scripting:endpoint>
 
+            <!-- JavaScript JSR-223 Endpoint  -->
+            <scripting:endpoint
+                       service="test:js-all" endpoint="endpoint"
+                       script="classpath:JSExchangeProcessorJSR223.js"
+                       bindings="#customBindings"
+                       targetService="test:receiver"
+                       copyProperties="true"
+                       copyAttachments="true">
+            </scripting:endpoint>
+
+            <scripting:endpoint
+                       service="test:js-headersOnly" endpoint="endpoint"
+                       script="classpath:JSExchangeProcessorJSR223.js"
+                       bindings="#customBindings"
+                       targetService="test:receiver"
+                       copyProperties="true"
+                       copyAttachments="false">
+            </scripting:endpoint>
+
+            <scripting:endpoint
+                       service="test:js-attachmentsOnly" endpoint="endpoint"
+                       script="classpath:JSExchangeProcessorJSR223.js"
+                       bindings="#customBindings"
+                       targetService="test:receiver"
+                       copyProperties="false"
+                       copyAttachments="true">
+            </scripting:endpoint>
+
         </sm:endpoints>
     </sm:container>
 



Mime
View raw message