Author: gertv
Date: Sun Oct 19 12:44:59 2008
New Revision: 706059
URL: http://svn.apache.org/viewvc?rev=706059&view=rev
Log:
CAMEL-999: Allow Scala RouteBuilders to be discovered from the classpath
Added:
activemq/camel/trunk/components/camel-scala/src/test/resources/org/apache/camel/scala/dsl/builder/
activemq/camel/trunk/components/camel-scala/src/test/resources/org/apache/camel/scala/dsl/builder/scan/
activemq/camel/trunk/components/camel-scala/src/test/resources/org/apache/camel/scala/dsl/builder/scan/scan-camel-context.xml
activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/builder/scan/
activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/builder/scan/DiscoverRouteBuilderTest.scala
activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/builder/scan/DiscoverableRouteBuilder.scala
Modified:
activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/builder/RouteBuilder.scala
activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/RouteBuilderFinder.java
Modified:
activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/builder/RouteBuilder.scala
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/builder/RouteBuilder.scala?rev=706059&r1=706058&r2=706059&view=diff
==============================================================================
---
activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/builder/RouteBuilder.scala
(original)
+++
activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/builder/RouteBuilder.scala
Sun Oct 19 12:44:59 2008
@@ -18,6 +18,7 @@
import org.apache.camel.model.ProcessorType
import org.apache.camel.model.ChoiceType
+import org.apache.camel.Routes
import collection.mutable.Stack
import _root_.scala.reflect.Manifest
@@ -27,7 +28,7 @@
/**
* Scala RouteBuilder implementation
*/
-class RouteBuilder extends Preamble with DSL {
+class RouteBuilder extends Preamble with DSL with Routes {
val builder = new org.apache.camel.builder.RouteBuilder {
override def configure() = {}
@@ -77,4 +78,9 @@
def setheader(name: String, expression: Exchange => Any) =
stack.top.setheader(name, expression)
def aggregate(expression: Exchange => Any) = stack.top.aggregate(expression)
+ // implementing the Routes interface to allow RouteBuilder to be discovered
by Spring
+ def getRouteList : java.util.List[Route[_ <: org.apache.camel.Exchange]] =
builder.getRouteList()
+ def getContext = builder.getContext()
+ def setContext(context: CamelContext) = builder.setContext(context)
+
}
Added:
activemq/camel/trunk/components/camel-scala/src/test/resources/org/apache/camel/scala/dsl/builder/scan/scan-camel-context.xml
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-scala/src/test/resources/org/apache/camel/scala/dsl/builder/scan/scan-camel-context.xml?rev=706059&view=auto
==============================================================================
---
activemq/camel/trunk/components/camel-scala/src/test/resources/org/apache/camel/scala/dsl/builder/scan/scan-camel-context.xml
(added)
+++
activemq/camel/trunk/components/camel-scala/src/test/resources/org/apache/camel/scala/dsl/builder/scan/scan-camel-context.xml
Sun Oct 19 12:44:59 2008
@@ -0,0 +1,29 @@
+<?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://activemq.apache.org/camel/schema/spring
+ http://activemq.apache.org/camel/schema/spring/camel-spring.xsd
+ http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
+
+ <camelContext xmlns="http://activemq.apache.org/camel/schema/spring">
+ <package>org.apache.camel.scala.dsl.builder.scan</package>
+ </camelContext>
+
+</beans>
Added:
activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/builder/scan/DiscoverRouteBuilderTest.scala
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/builder/scan/DiscoverRouteBuilderTest.scala?rev=706059&view=auto
==============================================================================
---
activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/builder/scan/DiscoverRouteBuilderTest.scala
(added)
+++
activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/builder/scan/DiscoverRouteBuilderTest.scala
Sun Oct 19 12:44:59 2008
@@ -0,0 +1,44 @@
+/**
+ * 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.scala.dsl.builder.scan
+
+import org.apache.camel.CamelContext
+import org.apache.camel.component.mock.MockEndpoint
+import org.springframework.context.support.ClassPathXmlApplicationContext
+import junit.framework.TestCase
+import junit.framework.Assert._
+
+/**
+ * Test to make sure that Scala DSL RouteBuilders can be discovered from the
classpath
+ */
+class DiscoverRouteBuilderTest extends TestCase {
+
+ def testDiscovery = {
+ val spring = new
ClassPathXmlApplicationContext("org/apache/camel/scala/dsl/builder/scan/scan-camel-context.xml")
+ val camel = spring.getBean("camelContext").asInstanceOf[CamelContext]
+ assertNotNull(camel)
+ assertEquals(1, camel.getRoutes().size())
+
+ // let us just send a simple message to make sure we discovered the
correct RouteBuilder
+ val template = camel.createProducerTemplate()
+ template.sendBody("direct:scan", "request");
+ val mock = camel.getEndpoint("mock:discovery").asInstanceOf[MockEndpoint]
+ mock.expectedMessageCount(1)
+ mock.assertIsSatisfied()
+ }
+
+}
Added:
activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/builder/scan/DiscoverableRouteBuilder.scala
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/builder/scan/DiscoverableRouteBuilder.scala?rev=706059&view=auto
==============================================================================
---
activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/builder/scan/DiscoverableRouteBuilder.scala
(added)
+++
activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/builder/scan/DiscoverableRouteBuilder.scala
Sun Oct 19 12:44:59 2008
@@ -0,0 +1,27 @@
+/**
+ * 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.scala.dsl.builder.scan
+
+/**
+ * RouteBuilder to be discovered by the DiscoverRouteBuilderTest
+ */
+class DiscoverableRouteBuilder extends RouteBuilder {
+
+ // Just a simple Route
+ "direct:scan" to "mock:discovery"
+
+}
Modified:
activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java?rev=706059&r1=706058&r2=706059&view=diff
==============================================================================
---
activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
(original)
+++
activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
Sun Oct 19 12:44:59 2008
@@ -28,6 +28,7 @@
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
+import org.apache.camel.Routes;
import org.apache.camel.builder.ErrorHandlerBuilder;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultLifecycleStrategy;
@@ -112,7 +113,7 @@
@XmlTransient
private RouteBuilder routeBuilder;
@XmlTransient
- private List<RouteBuilder> additionalBuilders = new
ArrayList<RouteBuilder>();
+ private List<Routes> additionalBuilders = new ArrayList<Routes>();
@XmlTransient
private ApplicationContext applicationContext;
@XmlTransient
@@ -499,7 +500,7 @@
}
}
}
- for (RouteBuilder routeBuilder : additionalBuilders) {
+ for (Routes routeBuilder : additionalBuilders) {
getContext().addRoutes(routeBuilder);
}
if (routeBuilder != null) {
Modified:
activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/RouteBuilderFinder.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/RouteBuilderFinder.java?rev=706059&r1=706058&r2=706059&view=diff
==============================================================================
---
activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/RouteBuilderFinder.java
(original)
+++
activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/RouteBuilderFinder.java
Sun Oct 19 12:44:59 2008
@@ -21,6 +21,7 @@
import java.util.Map;
import java.util.Set;
+import org.apache.camel.Routes;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.util.ResolverUtil;
import org.apache.commons.logging.Log;
@@ -73,15 +74,15 @@
/**
* Appends all the [EMAIL PROTECTED] RouteBuilder} instances that can be
found on the classpath
*/
- public void appendBuilders(List<RouteBuilder> list) throws
IllegalAccessException, InstantiationException {
- resolver.findImplementations(RouteBuilder.class, packages);
+ public void appendBuilders(List<Routes> list) throws
IllegalAccessException, InstantiationException {
+ resolver.findImplementations(Routes.class, packages);
Set<Class> classes = resolver.getClasses();
for (Class aClass : classes) {
if (shouldIgnoreBean(aClass)) {
continue;
}
if (isValidClass(aClass)) {
- RouteBuilder builder = instantiateBuilder(aClass);
+ Routes builder = instantiateBuilder(aClass);
if (beanPostProcessor != null) {
// Inject the annotated resource
beanPostProcessor.postProcessBeforeInitialization(builder,
builder.toString());
@@ -116,7 +117,7 @@
return false;
}
- protected RouteBuilder instantiateBuilder(Class type) throws
IllegalAccessException, InstantiationException {
- return (RouteBuilder) camelContext.getInjector().newInstance(type);
+ protected Routes instantiateBuilder(Class type) throws
IllegalAccessException, InstantiationException {
+ return (Routes) camelContext.getInjector().newInstance(type);
}
-}
\ No newline at end of file
+}