Repository: camel
Updated Branches:
  refs/heads/master 89cbfd89a -> fb2603557


CAMEL-8527: Processor in routes should be IdAware


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

Branch: refs/heads/master
Commit: fb26035576fa2565184211d5ddb2297d3b91e382
Parents: eaf8a3c
Author: Claus Ibsen <davscl...@apache.org>
Authored: Sun Mar 22 08:42:18 2015 +0100
Committer: Claus Ibsen <davscl...@apache.org>
Committed: Sun Mar 22 16:12:41 2015 +0100

----------------------------------------------------------------------
 .../java/org/apache/camel/CamelContext.java     | 17 ++++++++
 .../apache/camel/impl/DefaultCamelContext.java  | 23 +++++++++++
 .../processor/SimpleProcessorIdAwareTest.java   | 21 ++++++++++
 .../SpringSimpleProcessorIdAwareTest.java       | 29 ++++++++++++++
 .../processor/SimpleProcessorIdAwareTest.xml    | 41 ++++++++++++++++++++
 5 files changed, 131 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/fb260355/camel-core/src/main/java/org/apache/camel/CamelContext.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/CamelContext.java 
b/camel-core/src/main/java/org/apache/camel/CamelContext.java
index 84505bc..b92349e 100644
--- a/camel-core/src/main/java/org/apache/camel/CamelContext.java
+++ b/camel-core/src/main/java/org/apache/camel/CamelContext.java
@@ -27,6 +27,7 @@ import java.util.concurrent.TimeUnit;
 
 import org.apache.camel.builder.ErrorHandlerBuilder;
 import org.apache.camel.model.DataFormatDefinition;
+import org.apache.camel.model.ProcessorDefinition;
 import org.apache.camel.model.RouteDefinition;
 import org.apache.camel.model.RoutesDefinition;
 import org.apache.camel.model.rest.RestDefinition;
@@ -513,6 +514,22 @@ public interface CamelContext extends SuspendableService, 
RuntimeConfiguration {
     Route getRoute(String id);
 
     /**
+     * Gets the processor from any of the routes which with the given id
+     *
+     * @param id id of the processor
+     * @return the processor or <tt>null</tt> if not found
+     */
+    Processor getProcessor(String id);
+
+    /**
+     * Gets the processor definition from any of the routes which with the 
given id
+     *
+     * @param id id of the processor definition
+     * @return the processor definition or <tt>null</tt> if not found
+     */
+    ProcessorDefinition getProcessorDefinition(String id);
+
+    /**
      * Adds a collection of routes to this context using the given builder
      * to build them.
      * <p/>

http://git-wip-us.apache.org/repos/asf/camel/blob/fb260355/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java 
b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
index f9cfceb..9ac8692 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
@@ -709,6 +709,29 @@ public class DefaultCamelContext extends ServiceSupport 
implements ModelCamelCon
         return null;
     }
 
+    public Processor getProcessor(String id) {
+        for (Route route : getRoutes()) {
+            List<Processor> list = route.filter(id);
+            if (list.size() == 1) {
+                return list.get(0);
+            }
+        }
+        return null;
+    }
+
+    public ProcessorDefinition getProcessorDefinition(String id) {
+        for (RouteDefinition route : getRouteDefinitions()) {
+            Iterator<ProcessorDefinition> it = 
ProcessorDefinitionHelper.filterTypeInOutputs(route.getOutputs(), 
ProcessorDefinition.class);
+            while (it.hasNext()) {
+                ProcessorDefinition proc = it.next();
+                if (id.equals(proc.getId())) {
+                    return proc;
+                }
+            }
+        }
+        return null;
+    }
+
     @Deprecated
     public void setRoutes(List<Route> routes) {
         throw new UnsupportedOperationException("Overriding existing routes is 
not supported yet, use addRouteCollection instead");

http://git-wip-us.apache.org/repos/asf/camel/blob/fb260355/camel-core/src/test/java/org/apache/camel/processor/SimpleProcessorIdAwareTest.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/test/java/org/apache/camel/processor/SimpleProcessorIdAwareTest.java
 
b/camel-core/src/test/java/org/apache/camel/processor/SimpleProcessorIdAwareTest.java
index da118e0..aeabc25 100644
--- 
a/camel-core/src/test/java/org/apache/camel/processor/SimpleProcessorIdAwareTest.java
+++ 
b/camel-core/src/test/java/org/apache/camel/processor/SimpleProcessorIdAwareTest.java
@@ -22,6 +22,8 @@ import org.apache.camel.ContextTestSupport;
 import org.apache.camel.Processor;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.model.ProcessorDefinition;
+import org.apache.camel.model.SendDefinition;
 import org.apache.camel.spi.IdAware;
 
 /**
@@ -45,6 +47,25 @@ public class SimpleProcessorIdAwareTest extends 
ContextTestSupport {
 
         assertEquals("bar", ((IdAware) bar).getId());
         assertEquals("baz", ((IdAware) baz).getId());
+
+        bar = context.getProcessor("bar");
+        assertNotNull(bar);
+
+        baz = context.getProcessor("baz");
+        assertNotNull(baz);
+
+        Processor unknown = context.getProcessor("unknown");
+        assertNull(unknown);
+
+        Processor result = context.getProcessor("result");
+        assertNotNull(result);
+
+        ProcessorDefinition def = context.getProcessorDefinition("result");
+        assertNotNull(def);
+        assertEquals("result", def.getId());
+        SendDefinition send = assertIsInstanceOf(SendDefinition.class, def);
+        assertNotNull(send);
+        assertEquals("mock:result", send.getEndpointUri());
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/camel/blob/fb260355/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringSimpleProcessorIdAwareTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringSimpleProcessorIdAwareTest.java
 
b/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringSimpleProcessorIdAwareTest.java
new file mode 100644
index 0000000..0d9d565
--- /dev/null
+++ 
b/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringSimpleProcessorIdAwareTest.java
@@ -0,0 +1,29 @@
+/**
+ * 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.spring.processor;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.processor.SimpleProcessorIdAwareTest;
+
+import static 
org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext;
+
+public class SpringSimpleProcessorIdAwareTest extends 
SimpleProcessorIdAwareTest {
+
+    protected CamelContext createCamelContext() throws Exception {
+        return createSpringCamelContext(this, 
"org/apache/camel/spring/processor/SimpleProcessorIdAwareTest.xml");
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/fb260355/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SimpleProcessorIdAwareTest.xml
----------------------------------------------------------------------
diff --git 
a/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SimpleProcessorIdAwareTest.xml
 
b/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SimpleProcessorIdAwareTest.xml
new file mode 100644
index 0000000..c74dc28
--- /dev/null
+++ 
b/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SimpleProcessorIdAwareTest.xml
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans";
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+       xsi:schemaLocation="
+       http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans.xsd
+       http://camel.apache.org/schema/spring 
http://camel.apache.org/schema/spring/camel-spring.xsd
+    ">
+
+  <camelContext xmlns="http://camel.apache.org/schema/spring";>
+    <route id="foo">
+      <from uri="direct:start"/>
+      <choice>
+        <when>
+          <header>bar</header>
+          <to uri="log:bar" id="bar"/>
+        </when>
+        <otherwise>
+          <to uri="mock:result" id="result"/>
+        </otherwise>
+      </choice>
+      <to uri="log:baz" id="baz"/>
+    </route>
+  </camelContext>
+
+</beans>

Reply via email to