camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r771301 - in /camel/trunk/camel-core/src: main/java/org/apache/camel/ main/java/org/apache/camel/impl/ main/java/org/apache/camel/model/ main/java/org/apache/camel/spi/ test/java/org/apache/camel/processor/intercept/
Date Mon, 04 May 2009 13:33:00 GMT
Author: davsclaus
Date: Mon May  4 13:32:59 2009
New Revision: 771301

URL: http://svn.apache.org/viewvc?rev=771301&view=rev
Log:
CAMEL-1584: Added header for intercepted endpoint uri, so when using wildcards you known the
real endpoint that was intercepted.

Added:
    camel/trunk/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptFromUriWildcardHeaderUriTest.java
      - copied, changed from r771262, camel/trunk/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptFromUriWildcardTest.java
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/Exchange.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/InterceptSendToEndpoint.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/model/InterceptFromDefinition.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/spi/EndpointStrategy.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptFromUriWildcardTest.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptSendToEndpointDynamicTest.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java?rev=771301&r1=771300&r2=771301&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java Mon May  4 13:32:59
2009
@@ -25,6 +25,7 @@
 import org.apache.camel.model.RouteDefinition;
 import org.apache.camel.model.dataformat.DataFormatDefinition;
 import org.apache.camel.spi.ClassResolver;
+import org.apache.camel.spi.EndpointStrategy;
 import org.apache.camel.spi.ExchangeConverter;
 import org.apache.camel.spi.FactoryFinder;
 import org.apache.camel.spi.FactoryFinderResolver;
@@ -35,7 +36,6 @@
 import org.apache.camel.spi.PackageScanClassResolver;
 import org.apache.camel.spi.Registry;
 import org.apache.camel.spi.TypeConverterRegistry;
-import org.apache.camel.spi.EndpointStrategy;
 
 /**
  * Interface used to represent the context used to configure routes and the

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/Exchange.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/Exchange.java?rev=771301&r1=771300&r2=771301&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/Exchange.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/Exchange.java Mon May  4 13:32:59
2009
@@ -77,6 +77,8 @@
     String TRANSACTED = "CamelTransacted";
     String ROLLBACK_ONLY = "CamelRollbackOnly";
 
+    String INTERCEPTED_ENDPOINT = "CamelInterceptedEndpoint";
+
     /**
      * Returns the {@link ExchangePattern} (MEP) of this exchange.
      *

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java?rev=771301&r1=771300&r2=771301&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java Mon
May  4 13:32:59 2009
@@ -35,7 +35,6 @@
 import org.apache.camel.NoFactoryAvailableException;
 import org.apache.camel.Processor;
 import org.apache.camel.ProducerTemplate;
-import org.apache.camel.spi.EndpointStrategy;
 import org.apache.camel.ResolveEndpointFailedException;
 import org.apache.camel.Route;
 import org.apache.camel.Routes;
@@ -56,6 +55,7 @@
 import org.apache.camel.processor.interceptor.Tracer;
 import org.apache.camel.spi.ClassResolver;
 import org.apache.camel.spi.ComponentResolver;
+import org.apache.camel.spi.EndpointStrategy;
 import org.apache.camel.spi.ExchangeConverter;
 import org.apache.camel.spi.FactoryFinder;
 import org.apache.camel.spi.FactoryFinderResolver;

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/InterceptSendToEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/InterceptSendToEndpoint.java?rev=771301&r1=771300&r2=771301&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/InterceptSendToEndpoint.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/InterceptSendToEndpoint.java
Mon May  4 13:32:59 2009
@@ -108,6 +108,9 @@
                 if (LOG.isDebugEnabled()) {
                     LOG.debug("Sending to endpoint: " + getEndpointUri() + " is intercepted
and detoured to: " + detour + " for exchange: " + exchange);
                 }
+                // add header with the real endpoint uri
+                exchange.getIn().setHeader(Exchange.INTERCEPTED_ENDPOINT, delegate.getEndpointUri());
+
                 detour.process(exchange);
                 // copy OUT to IN
                 if (exchange.hasOut()) {

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/model/InterceptFromDefinition.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/InterceptFromDefinition.java?rev=771301&r1=771300&r2=771301&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/model/InterceptFromDefinition.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/InterceptFromDefinition.java
Mon May  4 13:32:59 2009
@@ -21,7 +21,9 @@
 import javax.xml.bind.annotation.XmlAttribute;
 import javax.xml.bind.annotation.XmlRootElement;
 
+import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
+import org.apache.camel.impl.ExpressionAdapter;
 import org.apache.camel.spi.RouteContext;
 
 /**
@@ -61,7 +63,22 @@
     }
 
     @Override
+    @SuppressWarnings("unchecked")
     public Processor createProcessor(RouteContext routeContext) throws Exception {
+        // insert a set property defintion so we can set the intercepted endpoint
+        // this allows us to use the same header for both the interceptFrom and interceptSendToEndpoint
+        // so end users is not confused if they should use another header for interceptFrom
than interceptSendToEndpoint
+        SetHeaderDefinition headerDefinition = new SetHeaderDefinition(Exchange.INTERCEPTED_ENDPOINT,
new ExpressionAdapter() {
+            public Object evaluate(Exchange exchange, Class type) {
+                return exchange.getFromEndpoint().getEndpointUri();
+            }
+
+            public String toString() {
+                return "";
+            }
+        });
+        getOutputs().add(0, headerDefinition);
+
         return createOutputsProcessor(routeContext);
     }
 

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/spi/EndpointStrategy.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/spi/EndpointStrategy.java?rev=771301&r1=771300&r2=771301&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/spi/EndpointStrategy.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/spi/EndpointStrategy.java Mon May
 4 13:32:59 2009
@@ -30,6 +30,10 @@
  */
 public interface EndpointStrategy {
 
+    // TODO: Add more strategy methods for other endpoint related methods, such as lookup,
remove etc.
+    // and add a base class EndpointStrategySupport that has noop impl of all methods so
you can extend it
+    // if you only want to do custom behavior in one of the methods
+
     /**
      * Register the endpoint.
      *

Copied: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptFromUriWildcardHeaderUriTest.java
(from r771262, camel/trunk/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptFromUriWildcardTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptFromUriWildcardHeaderUriTest.java?p2=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptFromUriWildcardHeaderUriTest.java&p1=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptFromUriWildcardTest.java&r1=771262&r2=771301&rev=771301&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptFromUriWildcardTest.java
(original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptFromUriWildcardHeaderUriTest.java
Mon May  4 13:32:59 2009
@@ -17,12 +17,13 @@
 package org.apache.camel.processor.intercept;
 
 import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
 import org.apache.camel.builder.RouteBuilder;
 
 /**
  * Testing http://camel.apache.org/dsl.html
  */
-public class InterceptFromUriWildcardTest extends ContextTestSupport {
+public class InterceptFromUriWildcardHeaderUriTest extends ContextTestSupport {
 
     public void testNoIntercept() throws Exception {
         getMockEndpoint("mock:intercept").expectedMessageCount(0);
@@ -35,6 +36,7 @@
 
     public void testInterceptFoo() throws Exception {
         getMockEndpoint("mock:intercept").expectedMessageCount(1);
+        getMockEndpoint("mock:intercept").expectedHeaderReceived(Exchange.INTERCEPTED_ENDPOINT,
"seda:foo");
         getMockEndpoint("mock:result").expectedMessageCount(1);
 
         template.sendBody("seda:foo", "Hello World");
@@ -44,6 +46,7 @@
 
     public void testInterceptBar() throws Exception {
         getMockEndpoint("mock:intercept").expectedMessageCount(1);
+        getMockEndpoint("mock:intercept").expectedHeaderReceived(Exchange.INTERCEPTED_ENDPOINT,
"seda:bar");
         getMockEndpoint("mock:result").expectedMessageCount(1);
 
         template.sendBody("seda:bar", "Hello World");
@@ -54,8 +57,6 @@
     protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {
             public void configure() throws Exception {
-                // START SNIPPET: e1
-                // only trigger when incoming from any seda endpoint as we use the * wildcard
                 interceptFrom("seda*").to("mock:intercept");
 
                 from("direct:start").to("mock:result");
@@ -63,7 +64,6 @@
                 from("seda:bar").to("mock:result");
 
                 from("seda:foo").to("mock:result");
-                // END SNIPPET: e1
             }
         };
     }

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptFromUriWildcardTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptFromUriWildcardTest.java?rev=771301&r1=771300&r2=771301&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptFromUriWildcardTest.java
(original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptFromUriWildcardTest.java
Mon May  4 13:32:59 2009
@@ -17,6 +17,7 @@
 package org.apache.camel.processor.intercept;
 
 import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
 import org.apache.camel.builder.RouteBuilder;
 
 /**
@@ -35,6 +36,7 @@
 
     public void testInterceptFoo() throws Exception {
         getMockEndpoint("mock:intercept").expectedMessageCount(1);
+        getMockEndpoint("mock:intercept").expectedHeaderReceived(Exchange.INTERCEPTED_ENDPOINT,
"seda:foo");
         getMockEndpoint("mock:result").expectedMessageCount(1);
 
         template.sendBody("seda:foo", "Hello World");

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptSendToEndpointDynamicTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptSendToEndpointDynamicTest.java?rev=771301&r1=771300&r2=771301&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptSendToEndpointDynamicTest.java
(original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptSendToEndpointDynamicTest.java
Mon May  4 13:32:59 2009
@@ -70,6 +70,29 @@
         assertMockEndpointsSatisfied();
     }
 
+    public void testSendToWildcardHeaderUri() throws Exception {
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                interceptSendToEndpoint("file:*").skipSendToOriginalEndpoint()
+                    .to("mock:detour");
+
+                from("direct:first")
+                    .to("file://foo")
+                    .to("mock:result");
+            }
+        });
+        context.start();
+
+        getMockEndpoint("mock:detour").expectedMessageCount(1);
+        getMockEndpoint("mock:detour").expectedHeaderReceived(Exchange.INTERCEPTED_ENDPOINT,
"file://foo");
+        getMockEndpoint("mock:result").expectedMessageCount(1);
+
+        template.sendBody("direct:first", "Hello World");
+
+        assertMockEndpointsSatisfied();
+    }
+
     public void testSendToRegex() throws Exception {
         context.addRoutes(new RouteBuilder() {
             @Override



Mime
View raw message