Repository: camel
Updated Branches:
  refs/heads/master 99056a1d5 -> 62b2042b2


CAMEL-9269: NotifyBuilder.fromRoute() does not work for some endpoint types


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/62b2042b
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/62b2042b
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/62b2042b

Branch: refs/heads/master
Commit: 62b2042b2fa9388aab16d5cee1385000a81a6a6b
Parents: 99056a1
Author: Gert Vanthienen <ge...@apache.org>
Authored: Thu Oct 29 09:44:10 2015 +0100
Committer: Gert Vanthienen <ge...@apache.org>
Committed: Thu Oct 29 09:44:10 2015 +0100

----------------------------------------------------------------------
 .../org/apache/camel/builder/NotifyBuilder.java |  5 +
 .../builder/NotifyBuilderFromRouteTest.java     | 96 ++++++++++++++++++++
 2 files changed, 101 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/62b2042b/camel-core/src/main/java/org/apache/camel/builder/NotifyBuilder.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/builder/NotifyBuilder.java 
b/camel-core/src/main/java/org/apache/camel/builder/NotifyBuilder.java
index 1c42ad9..e5933494 100644
--- a/camel-core/src/main/java/org/apache/camel/builder/NotifyBuilder.java
+++ b/camel-core/src/main/java/org/apache/camel/builder/NotifyBuilder.java
@@ -154,6 +154,11 @@ public class NotifyBuilder {
             @Override
             public boolean onExchange(Exchange exchange) {
                 String id = 
EndpointHelper.getRouteIdFromEndpoint(exchange.getFromEndpoint());
+
+                if (id == null) {
+                    id = exchange.getFromRouteId();
+                }
+
                 // filter non matching exchanges
                 return EndpointHelper.matchPattern(id, routeId);
             }

http://git-wip-us.apache.org/repos/asf/camel/blob/62b2042b/camel-core/src/test/java/org/apache/camel/builder/NotifyBuilderFromRouteTest.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/test/java/org/apache/camel/builder/NotifyBuilderFromRouteTest.java
 
b/camel-core/src/test/java/org/apache/camel/builder/NotifyBuilderFromRouteTest.java
new file mode 100644
index 0000000..bf94389
--- /dev/null
+++ 
b/camel-core/src/test/java/org/apache/camel/builder/NotifyBuilderFromRouteTest.java
@@ -0,0 +1,96 @@
+/**
+ * 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.builder;
+
+import org.apache.camel.*;
+import org.apache.camel.impl.DefaultComponent;
+import org.apache.camel.impl.DefaultEndpoint;
+import org.apache.camel.impl.JndiRegistry;
+
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * @version 
+ */
+public class NotifyBuilderFromRouteTest extends ContextTestSupport {
+
+    public void testDoneFromRoute() throws Exception {
+        // notify when exchange is done
+        NotifyBuilder builder =
+                new NotifyBuilder(context).fromRoute("foo").whenDone(1);
+        builder.create();
+
+        template.sendBody("seda:foo", "Hello world!");
+
+        assertTrue(builder.matchesMockWaitTime());
+    }
+
+
+    @Override
+    protected JndiRegistry createRegistry() throws Exception {
+        final JndiRegistry registry = super.createRegistry();
+        registry.bind("proxy", new ProxyComponent());
+        return registry;
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("proxy:seda:foo")
+                    .routeId("foo")
+                    .to("mock:foo");
+            }
+        };
+    }
+
+    private static final class ProxyComponent extends DefaultComponent {
+
+        @Override
+        protected Endpoint createEndpoint(String uri, String remaining, 
Map<String, Object> parameters) throws Exception {
+            return new ProxyEndpoint(this, uri, remaining);
+        }
+
+    }
+
+    private static final class ProxyEndpoint extends DefaultEndpoint {
+
+        private final Endpoint target;
+
+        private ProxyEndpoint(ProxyComponent component, String uri, String 
target) {
+            super(uri, component);
+            this.target = getCamelContext().getEndpoint(target);
+        }
+
+        @Override
+        public Producer createProducer() throws Exception {
+            return target.createProducer();
+        }
+
+        @Override
+        public Consumer createConsumer(Processor processor) throws Exception {
+            return target.createConsumer(processor);
+        }
+
+        @Override
+        public boolean isSingleton() {
+            return target.isSingleton();
+        }
+    }
+}

Reply via email to