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 2010/04/06 14:37:49 UTC

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

Author: gertv
Date: Tue Apr  6 12:37:48 2010
New Revision: 931118

URL: http://svn.apache.org/viewvc?rev=931118&view=rev
Log:
SMXCOMP-733: Camel's Exchange.getFromEndpoint() should return Camel JBI endpoint instance

Added:
    servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiEndpointAvailableInRouteTest.java
Modified:
    servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/CamelProviderEndpoint.java
    servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/JbiComponent.java
    servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiDlcForCamelRouteTest.java

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=931118&r1=931117&r2=931118&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 Apr  6 12:37:48 2010
@@ -25,7 +25,6 @@ import javax.jbi.messaging.MessageExchan
 import javax.jbi.messaging.MessagingException;
 import javax.jbi.messaging.RobustInOnly;
 import javax.xml.namespace.QName;
-import javax.xml.transform.Source;
 
 import org.apache.camel.Endpoint;
 import org.apache.camel.Exchange;
@@ -48,6 +47,8 @@ public class CamelProviderEndpoint exten
 
     private final JbiBinding binding;
 
+    private Endpoint camelEndpoint;
+
     private Processor camelProcessor;
     
     public CamelProviderEndpoint(ServiceUnit serviceUnit, QName service, String endpoint, JbiBinding binding, Processor camelProcessor) {
@@ -60,6 +61,15 @@ public class CamelProviderEndpoint exten
         this(serviceUnit, SERVICE_NAME, camelEndpoint.getEndpointUri(), binding, camelProcessor);
     }
 
+    /**
+     * Set the Camel JbiEndpoint instance that corresponds with this JBI endpoint
+     *
+     * @param camelEndpoint the Camel JbiEndpoint instance
+     */
+    public void setCamelEndpoint(Endpoint camelEndpoint) {
+        this.camelEndpoint = camelEndpoint;
+    }
+
     @Override
     public void process(MessageExchange exchange) throws Exception {
         // The component acts as a provider, this means that another component has requested our service
@@ -93,6 +103,7 @@ public class CamelProviderEndpoint exten
                 logger.debug("Received exchange: " + exchange);
             }
             final Exchange camelExchange = binding.createExchange(exchange);
+            camelExchange.setFromEndpoint(camelEndpoint);
             camelExchange.addOnCompletion(this);
             
             binding.runWithCamelContextClassLoader(new Callable<Object>() {

Modified: servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/JbiComponent.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/JbiComponent.java?rev=931118&r1=931117&r2=931118&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/JbiComponent.java (original)
+++ servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/JbiComponent.java Tue Apr  6 12:37:48 2010
@@ -128,10 +128,12 @@ public class JbiComponent implements Com
             }
             jbiEndpoint = new CamelProviderEndpoint(getCamelJbiComponent()
                     .getServiceUnit(), service, endpoint, createBinding(camelEndpoint), processor);
+
         } else {
             jbiEndpoint = new CamelProviderEndpoint(getCamelJbiComponent()
                     .getServiceUnit(), camelEndpoint, createBinding(camelEndpoint), processor);
         }
+        jbiEndpoint.setCamelEndpoint(camelEndpoint);
         return jbiEndpoint;
     }
 

Modified: servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiDlcForCamelRouteTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiDlcForCamelRouteTest.java?rev=931118&r1=931117&r2=931118&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiDlcForCamelRouteTest.java (original)
+++ servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiDlcForCamelRouteTest.java Tue Apr  6 12:37:48 2010
@@ -27,7 +27,6 @@ import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.converter.jaxp.StringSource;
-import org.apache.camel.processor.DeadLetterChannel;
 import org.apache.servicemix.jbi.container.ActivationSpec;
 import org.apache.servicemix.tck.ReceiverComponent;
 
@@ -48,8 +47,8 @@ public class JbiDlcForCamelRouteTest ext
         // Camel 2.x DLC marks the Exchange handled by default
         assertEquals("Exchange should have finished OK",
                      ExchangeStatus.DONE, exchange.getStatus());
-        assertTrue("Exception should be the original RuntimeException from the Processor",
-                   exchange.getError() instanceof RuntimeException);
+        assertNull("Exception should be cleared from the JBI Exchange",
+                   exchange.getError());
     }
 
     @Override
@@ -77,7 +76,7 @@ public class JbiDlcForCamelRouteTest ext
                 from("jbi:endpoint:urn:test:exception:endpoint")
                     .to("log:test")
                     .process(new Processor() {
-                        @Override
+                        
                         public void process(Exchange exchange) throws Exception {
                             exchange.setException(new RuntimeException("Can you handle me, JBI endpoint?"));
                         }

Added: servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiEndpointAvailableInRouteTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiEndpointAvailableInRouteTest.java?rev=931118&view=auto
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiEndpointAvailableInRouteTest.java (added)
+++ servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiEndpointAvailableInRouteTest.java Tue Apr  6 12:37:48 2010
@@ -0,0 +1,71 @@
+/*
+ * 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 javax.jbi.messaging.ExchangeStatus;
+import javax.jbi.messaging.InOnly;
+import javax.xml.namespace.QName;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.servicemix.jbi.container.ActivationSpec;
+import org.apache.servicemix.jbi.jaxp.StringSource;
+
+/**
+ * Tests to ensure that the Exchange.getFromEndpoint() call returns the originating Camel endpoint
+ */
+public class JbiEndpointAvailableInRouteTest extends JbiTestSupport {
+
+    public void testSendExchange() throws Exception {
+        InOnly exchange = getServicemixClient().createInOnlyExchange();
+        exchange.setService(new QName("urn:test", "service"));
+        exchange.getInMessage().setContent(new StringSource("<message/>"));
+
+        getServicemixClient().sendSync(exchange);
+        assertEquals("Assertions inside Camel Processor should have passed",
+                     ExchangeStatus.DONE, exchange.getStatus());
+
+    }
+
+    @Override
+    protected void appendJbiActivationSpecs(List<ActivationSpec> activationSpecList) {
+        // no additional JBI endpoints required
+    }
+
+    @Override
+    protected RouteBuilder createRoutes() {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("jbi:endpoint:urn:test:service:endpoint")
+                    .process(new Processor() {
+                        
+                        public void process(Exchange exchange) {
+                            assertTrue("The Camel JbiEndpoint should be set as the 'from' endpoint on the exchange", 
+                                       exchange.getFromEndpoint() instanceof JbiEndpoint);
+
+                            JbiEndpoint origin = (JbiEndpoint) exchange.getFromEndpoint();
+                            assertEquals("endpoint:urn:test:service:endpoint",
+                                         origin.getDestinationUri());
+                        }
+                    });
+            }
+        };
+    }
+}