camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject svn commit: r685557 - in /activemq/camel/trunk/camel-core/src: main/java/org/apache/camel/processor/ test/java/org/apache/camel/processor/routingslip/
Date Wed, 13 Aug 2008 14:10:25 GMT
Author: ningjiang
Date: Wed Aug 13 07:10:22 2008
New Revision: 685557

URL: http://svn.apache.org/viewvc?rev=685557&view=rev
Log:
CAMEL-818 applied patch with thanks to Jonathan

Added:
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/routingslip/DummyExchange.java
  (with props)
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/routingslip/RoutingSlipWithNonStandardExchangeTest.java
  (with props)
Modified:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RoutingSlip.java
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/routingslip/RoutingSlipDataModificationTest.java

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RoutingSlip.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RoutingSlip.java?rev=685557&r1=685556&r2=685557&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RoutingSlip.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RoutingSlip.java
Wed Aug 13 07:10:22 2008
@@ -34,8 +34,7 @@
 import static org.apache.camel.util.ObjectHelper.notNull;
 
 /**
- * Implements a <a
- * href="http://activemq.apache.org/camel/routing-slip.html">Routing Slip</a>
+ * Implements a <a href="http://activemq.apache.org/camel/routing-slip.html">Routing
Slip</a>
  * pattern where the list of actual endpoints to send a message exchange to are
  * dependent on the value of a message header.
  */
@@ -71,7 +70,7 @@
         for (String nextRecipient : recipients) {
             Endpoint<Exchange> endpoint = resolveEndpoint(exchange, nextRecipient);
             Producer<Exchange> producer = producerCache.getProducer(endpoint);
-            Exchange ex = endpoint.createExchange(ExchangePattern.InOut);
+            Exchange ex = current.newInstance();
 
             updateRoutingSlip(current);
             copyOutToIn(ex, current);

Added: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/routingslip/DummyExchange.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/routingslip/DummyExchange.java?rev=685557&view=auto
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/routingslip/DummyExchange.java
(added)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/routingslip/DummyExchange.java
Wed Aug 13 07:10:22 2008
@@ -0,0 +1,40 @@
+/**
+ * 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.camel.processor.routingslip;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.ExchangePattern;
+import org.apache.camel.impl.DefaultExchange;
+
+public class DummyExchange extends DefaultExchange {
+
+    public DummyExchange(CamelContext context, ExchangePattern pattern) {
+        super(context, pattern);
+    }
+
+    public DummyExchange(DummyExchange dummyExchange) {
+        super(dummyExchange);
+    }
+
+    @Override
+    public Exchange newInstance() {
+        return new DummyExchange(this);
+    }
+
+}

Propchange: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/routingslip/DummyExchange.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/routingslip/DummyExchange.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/routingslip/RoutingSlipDataModificationTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/routingslip/RoutingSlipDataModificationTest.java?rev=685557&r1=685556&r2=685557&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/routingslip/RoutingSlipDataModificationTest.java
(original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/routingslip/RoutingSlipDataModificationTest.java
Wed Aug 13 07:10:22 2008
@@ -34,17 +34,15 @@
     protected static final String ANSWER = "answer";
     protected static final String ROUTING_SLIP_HEADER = "routingSlipHeader";
     private static final transient Log LOG = LogFactory.getLog(RoutingSlipDataModificationTest.class);
-    protected MyBean myBean = new MyBean(ROUTING_SLIP_HEADER);
+    protected MyBean myBean = new MyBean();
 
     public void testModificationOfDataAlongRoute()
         throws Exception {
         MockEndpoint x = getMockEndpoint("mock:x");
         MockEndpoint y = getMockEndpoint("mock:y");
-        MockEndpoint z = getMockEndpoint("mock:z");
 
         x.expectedBodiesReceived(ANSWER);
         y.expectedBodiesReceived(ANSWER + ANSWER);
-        z.expectedBodiesReceived(ANSWER + ANSWER);
 
         sendBody();
 
@@ -53,7 +51,7 @@
 
     protected void sendBody() {
         template.sendBodyAndHeader("direct:a", ANSWER, ROUTING_SLIP_HEADER,
-                "mock:x,bean:myBean?method=modifyData,mock:y,mock:z");
+                "mock:x,bean:myBean?method=modifyData");
     }
 
     @Override
@@ -75,27 +73,17 @@
         return new RouteBuilder() {
             public void configure() {
                 // START SNIPPET: example
-                from("direct:a").routingSlip(ROUTING_SLIP_HEADER);
+                from("direct:a").routingSlip(ROUTING_SLIP_HEADER).to("mock:y");
                 // END SNIPPET: example
             }
         };
     }
 
     public static class MyBean {
-        private String routingSlipHeader;
-
         public MyBean() {
         }
 
-        public MyBean(String routingSlipHeader) {
-            this.routingSlipHeader = routingSlipHeader;
-        }
-
-        public String modifyData(
-            @Body String body,
-            @Headers Map<String, Object> headers,
-            @OutHeaders Map<String, Object> outHeaders) {
-            outHeaders.put(routingSlipHeader, headers.get(routingSlipHeader));
+        public String modifyData(@Body String body) {
             return body + body;
         }
     }

Added: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/routingslip/RoutingSlipWithNonStandardExchangeTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/routingslip/RoutingSlipWithNonStandardExchangeTest.java?rev=685557&view=auto
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/routingslip/RoutingSlipWithNonStandardExchangeTest.java
(added)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/routingslip/RoutingSlipWithNonStandardExchangeTest.java
Wed Aug 13 07:10:22 2008
@@ -0,0 +1,65 @@
+/**
+ * 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.camel.processor.routingslip;
+
+import java.util.List;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.ExchangePattern;
+import org.apache.camel.Message;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+
+public class RoutingSlipWithNonStandardExchangeTest extends ContextTestSupport {
+
+    protected static final String ANSWER = "answer";
+    protected static final String ROUTING_SLIP_HEADER = "routingSlipHeader";
+    
+    public void testRoutingSlipPreservesDifferentExchange()
+        throws Exception {
+        MockEndpoint end = getMockEndpoint("mock:z");
+        end.expectedMessageCount(1);
+
+        sendBody("direct:a", ROUTING_SLIP_HEADER, ",");
+
+        assertMockEndpointsSatisifed();
+        
+        List<Exchange> exchanges = end.getExchanges();
+        Exchange exchange = exchanges.get(0);
+        assertIsInstanceOf(DummyExchange.class, exchange);
+    }
+   
+    protected void sendBody(String endpoint, String header, String delimiter) {
+        DummyExchange exchange = new DummyExchange(context, ExchangePattern.InOut);
+        Message in = exchange.getIn();
+        in.setHeader(header, "mock:y" + delimiter + "mock:z");
+        in.setBody(ANSWER);        
+        
+        template.send(endpoint, exchange);
+    }
+    
+    protected RouteBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+            public void configure() {    
+                // START SNIPPET: e1
+                from("direct:a").routingSlip();
+                // END SNIPPET: e1
+            }
+        };
+    }
+}

Propchange: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/routingslip/RoutingSlipWithNonStandardExchangeTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/routingslip/RoutingSlipWithNonStandardExchangeTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



Mime
View raw message