Author: davsclaus
Date: Wed Aug 25 07:38:16 2010
New Revision: 988835
URL: http://svn.apache.org/viewvc?rev=988835&view=rev
Log:
Added logic to lookup endpoint registry id.
Added:
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/util/EndpointHelperTest.java
camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/util/
camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/util/EndpointHelperTest.xml
- copied, changed from r988830,
camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/camelContextRouteBuilderRef.xml
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/spi/HasId.java
camel/trunk/camel-core/src/main/java/org/apache/camel/util/EndpointHelper.java
camel/trunk/camel-core/src/test/java/org/apache/camel/util/EndpointHelperTest.java
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/spi/HasId.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/spi/HasId.java?rev=988835&r1=988834&r2=988835&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/spi/HasId.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/spi/HasId.java Wed
Aug 25 07:38:16 2010
@@ -21,5 +21,11 @@ package org.apache.camel.spi;
* in REST or JMX style APIs
*/
public interface HasId {
+
+ /**
+ * Returns the id
+ *
+ * @return the id
+ */
String getId();
}
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/util/EndpointHelper.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/util/EndpointHelper.java?rev=988835&r1=988834&r2=988835&view=diff
==============================================================================
---
camel/trunk/camel-core/src/main/java/org/apache/camel/util/EndpointHelper.java
(original)
+++
camel/trunk/camel-core/src/main/java/org/apache/camel/util/EndpointHelper.java
Wed Aug 25 07:38:16 2010
@@ -366,9 +366,32 @@ public final class EndpointHelper {
}
/**
- * A helper method for Endpoint implementations to create new Ids for
Endpoints which also implement {...@link HasId}
+ * A helper method for Endpoint implementations to create new Ids for
Endpoints which also implement
+ * {...@link org.apache.camel.spi.HasId}
*/
public static String createEndpointId() {
return "endpoint" + ENDPOINT_COUNTER.incrementAndGet();
}
+
+ /**
+ * Lookup the id the given endpoint has been enlisted with in the
{...@link org.apache.camel.spi.Registry}.
+ *
+ * @param endpoint the endpoint
+ * @return the endpoint id, or <tt>null</tt> if not found
+ */
+ public static String lookupEndpointRegistryId(Endpoint endpoint) {
+ if (endpoint == null || endpoint.getCamelContext() == null) {
+ return null;
+ }
+
+ Map<String, Endpoint> map =
endpoint.getCamelContext().getRegistry().lookupByType(Endpoint.class);
+ for (Map.Entry<String, Endpoint> entry : map.entrySet()) {
+ if (entry.getValue().equals(endpoint)) {
+ return entry.getKey();
+ }
+ }
+
+ // not found
+ return null;
+ }
}
Modified:
camel/trunk/camel-core/src/test/java/org/apache/camel/util/EndpointHelperTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/util/EndpointHelperTest.java?rev=988835&r1=988834&r2=988835&view=diff
==============================================================================
---
camel/trunk/camel-core/src/test/java/org/apache/camel/util/EndpointHelperTest.java
(original)
+++
camel/trunk/camel-core/src/test/java/org/apache/camel/util/EndpointHelperTest.java
Wed Aug 25 07:38:16 2010
@@ -19,15 +19,22 @@ package org.apache.camel.util;
import java.util.ArrayList;
import java.util.List;
+import org.apache.camel.CamelContext;
import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Endpoint;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.impl.SimpleRegistry;
/**
* @version $Revision$
*/
public class EndpointHelperTest extends ContextTestSupport {
+ private Endpoint foo;
+ private Endpoint bar;
+
public void testPollEndpoint() throws Exception {
template.sendBody("seda:foo", "Hello World");
template.sendBody("seda:foo", "Bye World");
@@ -60,4 +67,23 @@ public class EndpointHelperTest extends
assertEquals("Bye World", bodies.get(1));
}
+ @Override
+ protected CamelContext createCamelContext() throws Exception {
+ SimpleRegistry reg = new SimpleRegistry();
+ CamelContext context = new DefaultCamelContext(reg);
+
+ foo = context.getEndpoint("mock:foo");
+ bar = context.getEndpoint("mock:bar");
+ reg.put("foo", foo);
+ reg.put("coolbar", bar);
+
+ return context;
+ }
+
+ public void testLookupEndpointRegistryId() throws Exception {
+ assertEquals("foo", EndpointHelper.lookupEndpointRegistryId(foo));
+ assertEquals("coolbar", EndpointHelper.lookupEndpointRegistryId(bar));
+ assertEquals(null,
EndpointHelper.lookupEndpointRegistryId(context.getEndpoint("mock:cheese")));
+ }
+
}
Added:
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/util/EndpointHelperTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/util/EndpointHelperTest.java?rev=988835&view=auto
==============================================================================
---
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/util/EndpointHelperTest.java
(added)
+++
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/util/EndpointHelperTest.java
Wed Aug 25 07:38:16 2010
@@ -0,0 +1,49 @@
+/**
+ * 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.util;
+
+import org.apache.camel.Endpoint;
+import org.apache.camel.spring.SpringTestSupport;
+import org.apache.camel.util.EndpointHelper;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+/**
+ * @version $Revision$
+ */
+public class EndpointHelperTest extends SpringTestSupport {
+
+ @Override
+ protected int getExpectedRouteCount() {
+ return 0;
+ }
+
+ @Override
+ protected AbstractXmlApplicationContext createApplicationContext() {
+ return new
ClassPathXmlApplicationContext("org/apache/camel/spring/util/EndpointHelperTest.xml");
+ }
+
+ public void testLookupEndpointRegistryId() throws Exception {
+ Endpoint foo = context.getEndpoint("ref:foo");
+ Endpoint bar = context.getEndpoint("ref:coolbar");
+
+ assertEquals("foo", EndpointHelper.lookupEndpointRegistryId(foo));
+ assertEquals("coolbar", EndpointHelper.lookupEndpointRegistryId(bar));
+ assertEquals(null,
EndpointHelper.lookupEndpointRegistryId(context.getEndpoint("mock:cheese")));
+ }
+
+}
Copied:
camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/util/EndpointHelperTest.xml
(from r988830,
camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/camelContextRouteBuilderRef.xml)
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/util/EndpointHelperTest.xml?p2=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/util/EndpointHelperTest.xml&p1=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/camelContextRouteBuilderRef.xml&r1=988830&r2=988835&rev=988835&view=diff
==============================================================================
---
camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/camelContextRouteBuilderRef.xml
(original)
+++
camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/util/EndpointHelperTest.xml
Wed Aug 25 07:38:16 2010
@@ -21,13 +21,10 @@
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
">
-
- <!-- START SNIPPET: example5 -->
- <camelContext id="camel5" xmlns="http://camel.apache.org/schema/spring">
- <routeBuilder ref="myBuilder" />
- </camelContext>
-
- <bean id="myBuilder"
class="org.apache.camel.spring.example.test1.MyRouteBuilder"/>
- <!-- END SNIPPET: example4 -->
-
+
+ <camelContext xmlns="http://camel.apache.org/schema/spring">
+ <endpoint id="foo" uri="mock:foo"/>
+ <endpoint id="coolbar" uri="mock:bar"/>
+ </camelContext>
+
</beans>