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 2009/03/31 14:47:56 UTC

svn commit: r760421 - in /servicemix/components/engines/servicemix-camel/trunk/src: main/java/org/apache/servicemix/camel/ test/java/org/apache/servicemix/camel/ test/resources/

Author: gertv
Date: Tue Mar 31 12:47:50 2009
New Revision: 760421

URL: http://svn.apache.org/viewvc?rev=760421&view=rev
Log:
SMXCOMP-494: Camel route should avoid returning null out message when receiving InOut exchange

Added:
    servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiInOutFromCamelRoute.java
Modified:
    servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/CamelConsumerEndpoint.java
    servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/CamelProviderEndpoint.java
    servicemix/components/engines/servicemix-camel/trunk/src/test/resources/log4j.properties

Modified: servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/CamelConsumerEndpoint.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/CamelConsumerEndpoint.java?rev=760421&r1=760420&r2=760421&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/CamelConsumerEndpoint.java (original)
+++ servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/CamelConsumerEndpoint.java Tue Mar 31 12:47:50 2009
@@ -64,7 +64,7 @@
                 exchange.getFault().setBody(messageExchange.getFault().getContent());
                 addHeaders(messageExchange.getFault(), exchange.getFault());
                 addAttachments(messageExchange.getFault(), exchange.getFault());
-            } else {
+            } else if (messageExchange.getMessage("out") != null) {
                 exchange.getOut().setBody(messageExchange.getMessage("out").getContent());
                 addHeaders(messageExchange.getMessage("out"), exchange.getOut());
                 addAttachments(messageExchange.getMessage("out"), exchange.getOut());
@@ -88,11 +88,7 @@
 
             send(messageExchange);
             return false;
-        } catch (MessagingException e) {
-            exchange.setException(e);
-            asyncCallback.done(true);
-            return true;
-        } catch (URISyntaxException e) {
+        } catch (Exception e) {
             exchange.setException(e);
             asyncCallback.done(true);
             return true;
@@ -119,7 +115,7 @@
                     exchange.getFault().setBody(messageExchange.getFault().getContent());
                     addHeaders(messageExchange.getFault(), exchange.getFault());
                     addAttachments(messageExchange.getFault(), exchange.getFault());
-                } else {
+                } else if (messageExchange.getMessage("out") != null) {
                     exchange.getOut().setBody(messageExchange.getMessage("out").getContent());
                     addHeaders(messageExchange.getMessage("out"), exchange.getOut());
                     addAttachments(messageExchange.getMessage("out"), exchange.getOut());
@@ -141,6 +137,7 @@
         // No validation required
     }
 
+    @SuppressWarnings("unchecked")
     private void addHeaders(MessageExchange messageExchange, Exchange camelExchange) {
         Set entries = messageExchange.getPropertyNames();
         for (Object o : entries) {
@@ -149,6 +146,7 @@
         }
     }
 
+    @SuppressWarnings("unchecked")
     private void addHeaders(NormalizedMessage normalizedMessage, Message camelMessage) {
         Set entries = normalizedMessage.getPropertyNames();
         for (Object o : entries) {
@@ -157,6 +155,7 @@
         }
     }
 
+    @SuppressWarnings("unchecked")
     private void addAttachments(NormalizedMessage normalizedMessage, Message camelMessage) {
         Set entries = normalizedMessage.getAttachmentNames();
         for (Object o : entries) {

Modified: servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/CamelProviderEndpoint.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/CamelProviderEndpoint.java?rev=760421&r1=760420&r2=760421&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/CamelProviderEndpoint.java (original)
+++ servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/CamelProviderEndpoint.java Tue Mar 31 12:47:50 2009
@@ -127,6 +127,9 @@
                     fail(exchange, e);
                 } else {
                     boolean txSync = exchange.isTransacted() && Boolean.TRUE.equals(exchange.getProperty(JbiConstants.SEND_SYNC));
+//                    if (camelExchange.getOut(false) == null) {
+//                        camelExchange.getOut().copyFrom(camelExchange.getIn());
+//                    }
                     if (txSync) {
                         sendSync(exchange);
                     } else {

Added: servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiInOutFromCamelRoute.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiInOutFromCamelRoute.java?rev=760421&view=auto
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiInOutFromCamelRoute.java (added)
+++ servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiInOutFromCamelRoute.java Tue Mar 31 12:47:50 2009
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.camel;
+
+import java.util.List;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.impl.DefaultExchange;
+import org.apache.servicemix.jbi.container.ActivationSpec;
+
+/**
+ * Tests on sending JBI InOut exchanges from within a Camel route
+ */
+public class JbiInOutFromCamelRoute extends JbiTestSupport {
+
+    private static final String MESSAGE = "<just><a>test</a></just>";
+    private static final String REPLY = "<just><a>reply</a></just>";
+    private static final String REPLY_HEADER = "replies?";
+
+    public void testInOutEchoesReply() throws Exception {
+        MockEndpoint inout = getMockEndpoint("mock:in-out");
+        inout.expectedMessageCount(2);
+
+        // when the route creates a reply, expect that as the out message
+        doTestInOutReply("direct:in-out", true, REPLY);
+        
+        // otherwise, just expect it to echo back the original message
+        doTestInOutReply("direct:in-out", false, MESSAGE);
+        
+        inout.assertIsSatisfied();
+    }
+    
+    public void testInOutEchoesReplyAsync() throws Exception {
+        MockEndpoint inout = getMockEndpoint("mock:in-out");
+        inout.expectedMessageCount(2);
+
+        // when the route creates a reply, expect that as the out message
+        doTestInOutReply("direct:async-in-out", true, REPLY);
+        
+        // otherwise, just expect it to echo back the original message
+        doTestInOutReply("direct:async-in-out", false, MESSAGE);
+        
+        inout.assertIsSatisfied();
+    }
+
+
+    private void doTestInOutReply(String uri, Boolean reply, Object result) {
+        Exchange exchange = new DefaultExchange(camelContext);
+        exchange.getIn().setHeader(REPLY_HEADER, reply);
+        exchange.getIn().setBody(MESSAGE);
+        client.send(uri, exchange);
+        assertEquals(result, exchange.getOut().getBody(String.class));
+    }
+
+    @Override
+    protected void appendJbiActivationSpecs(List<ActivationSpec> activationSpecList) {
+        // no additional activation specs required
+    }
+
+    @Override
+    protected RouteBuilder createRoutes() {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:in-out")
+                  .choice()
+                    .when(header(REPLY_HEADER).isEqualTo(Boolean.TRUE)).to("jbi:service:urn:test:in-out-reply?mep=in-out")
+                    .otherwise().to("jbi:service:urn:test:in-out-quiet?mep=in-out");
+                
+                from("direct:async-in-out")
+                  .thread(1)
+                  .choice()
+                    .when(header(REPLY_HEADER).isEqualTo(Boolean.TRUE)).to("jbi:service:urn:test:in-out-reply?mep=in-out")
+                    .otherwise().to("jbi:service:urn:test:in-out-quiet?mep=in-out");
+                
+                from("jbi:service:urn:test:in-out-quiet").to("mock:in-out");
+                from("jbi:service:urn:test:in-out-reply").setBody(constant(REPLY)).to("mock:in-out");
+            }
+        };
+    }
+}

Modified: servicemix/components/engines/servicemix-camel/trunk/src/test/resources/log4j.properties
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/test/resources/log4j.properties?rev=760421&r1=760420&r2=760421&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/src/test/resources/log4j.properties (original)
+++ servicemix/components/engines/servicemix-camel/trunk/src/test/resources/log4j.properties Tue Mar 31 12:47:50 2009
@@ -18,7 +18,7 @@
 #
 # The logging properties used during tests..
 #
-log4j.rootLogger=DEBUG, out
+log4j.rootLogger=DEBUG, out, stdout
 
 log4j.logger.org.apache.activemq=INFO
 log4j.logger.org.apache.activemq.spring=WARN