Author: jstrachan
Date: Wed Aug 13 07:18:40 2008
New Revision: 685565
URL: http://svn.apache.org/viewvc?rev=685565&view=rev
Log:
initial spike for CAMEL-817 which shows how to create a CamelContext and wire
in some RouteBuilder instances, optionally using a RouteBuilder as a builder of
other route builders
Added:
activemq/camel/trunk/components/camel-guice/
activemq/camel/trunk/components/camel-guice/pom.xml (with props)
activemq/camel/trunk/components/camel-guice/src/
activemq/camel/trunk/components/camel-guice/src/main/
activemq/camel/trunk/components/camel-guice/src/main/java/
activemq/camel/trunk/components/camel-guice/src/main/java/org/
activemq/camel/trunk/components/camel-guice/src/main/java/org/apache/
activemq/camel/trunk/components/camel-guice/src/main/java/org/apache/camel/
activemq/camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/
activemq/camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/CamelModule.java
(with props)
activemq/camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/GuiceCamelContext.java
(with props)
activemq/camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/impl/
activemq/camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/impl/GuiceInjector.java
(with props)
activemq/camel/trunk/components/camel-guice/src/main/resources/
activemq/camel/trunk/components/camel-guice/src/main/resources/META-INF/
activemq/camel/trunk/components/camel-guice/src/test/
activemq/camel/trunk/components/camel-guice/src/test/java/
activemq/camel/trunk/components/camel-guice/src/test/java/org/
activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/
activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/
activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/
activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/ConciseGuiceRouteTest.java
(with props)
activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/MyConfigurableRoute.java
(with props)
activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/MyHardcodeRoute.java
(with props)
activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/MyRouteInstaller.java
(with props)
activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/TraditionalGuiceRouteTest.java
(with props)
activemq/camel/trunk/components/camel-guice/src/test/resources/
activemq/camel/trunk/components/camel-guice/src/test/resources/log4j.properties
(with props)
Modified:
activemq/camel/trunk/apache-camel/pom.xml
activemq/camel/trunk/apache-camel/src/main/descriptors/unix-bin.xml
activemq/camel/trunk/apache-camel/src/main/descriptors/windows-bin.xml
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
activemq/camel/trunk/components/pom.xml
activemq/camel/trunk/pom.xml
Modified: activemq/camel/trunk/apache-camel/pom.xml
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/apache-camel/pom.xml?rev=685565&r1=685564&r2=685565&view=diff
==============================================================================
--- activemq/camel/trunk/apache-camel/pom.xml (original)
+++ activemq/camel/trunk/apache-camel/pom.xml Wed Aug 13 07:18:40 2008
@@ -89,6 +89,10 @@
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
+ <artifactId>camel-guice</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
<artifactId>camel-hamcrest</artifactId>
</dependency>
<dependency>
Modified: activemq/camel/trunk/apache-camel/src/main/descriptors/unix-bin.xml
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/apache-camel/src/main/descriptors/unix-bin.xml?rev=685565&r1=685564&r2=685565&view=diff
==============================================================================
--- activemq/camel/trunk/apache-camel/src/main/descriptors/unix-bin.xml
(original)
+++ activemq/camel/trunk/apache-camel/src/main/descriptors/unix-bin.xml Wed Aug
13 07:18:40 2008
@@ -102,6 +102,7 @@
<include>org.apache.camel:camel-flatpack</include>
<include>org.apache.camel:camel-ftp</include>
<include>org.apache.camel:camel-groovy</include>
+ <include>org.apache.camel:camel-guice</include>
<include>org.apache.camel:camel-hamcrest</include>
<include>org.apache.camel:camel-hl7</include>
<include>org.apache.camel:camel-http</include>
Modified: activemq/camel/trunk/apache-camel/src/main/descriptors/windows-bin.xml
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/apache-camel/src/main/descriptors/windows-bin.xml?rev=685565&r1=685564&r2=685565&view=diff
==============================================================================
--- activemq/camel/trunk/apache-camel/src/main/descriptors/windows-bin.xml
(original)
+++ activemq/camel/trunk/apache-camel/src/main/descriptors/windows-bin.xml Wed
Aug 13 07:18:40 2008
@@ -108,6 +108,7 @@
<include>org.apache.camel:camel-flatpack</include>
<include>org.apache.camel:camel-ftp</include>
<include>org.apache.camel:camel-groovy</include>
+ <include>org.apache.camel:camel-guice</include>
<include>org.apache.camel:camel-hamcrest</include>
<include>org.apache.camel:camel-hl7</include>
<include>org.apache.camel:camel-http</include>
Modified:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java?rev=685565&r1=685564&r2=685565&view=diff
==============================================================================
---
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java
(original)
+++
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java
Wed Aug 13 07:18:40 2008
@@ -224,4 +224,8 @@
protected void configureRoute(RouteType route) {
route.setGroup(getClass().getName());
}
+
+ protected void addRoutes(Routes routes) throws Exception {
+ getContext().addRoutes(routes);
+ }
}
Modified:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java?rev=685565&r1=685564&r2=685565&view=diff
==============================================================================
---
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
(original)
+++
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
Wed Aug 13 07:18:40 2008
@@ -127,7 +127,8 @@
* @param jndiContext
*/
public DefaultCamelContext(Context jndiContext) {
- this(new JndiRegistry(jndiContext));
+ this();
+ setJndiContext(jndiContext);
}
/**
@@ -439,6 +440,17 @@
return registry;
}
+ /**
+ * Sets the registry to the given JNDI context
+ *
+ * @param jndiContext is the JNDI context to use as the registry
+ *
+ * @see #setRegistry(org.apache.camel.spi.Registry)
+ */
+ public void setJndiContext(Context jndiContext) {
+ setRegistry(new JndiRegistry(jndiContext));
+ }
+
public void setRegistry(Registry registry) {
this.registry = registry;
}
Added: activemq/camel/trunk/components/camel-guice/pom.xml
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-guice/pom.xml?rev=685565&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-guice/pom.xml (added)
+++ activemq/camel/trunk/components/camel-guice/pom.xml Wed Aug 13 07:18:40 2008
@@ -0,0 +1,88 @@
+<?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.
+-->
+
+<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-parent</artifactId>
+ <version>1.5-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>camel-guice</artifactId>
+ <packaging>bundle</packaging>
+ <name>Camel :: Guice</name>
+ <description>Camel Guice</description>
+
+ <properties>
+ <camel.osgi.export.pkg>org.apache.camel.guice.*</camel.osgi.export.pkg>
+ </properties>
+
+ <repositories>
+ <!-- TODO remove ASAP when there is a real release! -->
+ <repository>
+ <id>apache.jstrachan</id>
+ <name>Temporary repo until Guice 1.1 is released</name>
+ <url>http://people.apache.org/~jstrachan/maven2/</url>
+ </repository>
+ </repositories>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.google.code.guice</groupId>
+ <artifactId>guice</artifactId>
+ <!-- TODO requires release after 1.0 as we need the Multibinder -->
+ <version>1.1-SNAPSHOT</version>
+ </dependency>
+
+ <!-- TODO should be really included by guice!! -->
+ <dependency>
+ <groupId>aopalliance</groupId>
+ <artifactId>aopalliance</artifactId>
+ <version>1.0</version>
+ </dependency>
+
+
+ <!-- testing -->
+ <dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+</project>
Propchange: activemq/camel/trunk/components/camel-guice/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Added:
activemq/camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/CamelModule.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/CamelModule.java?rev=685565&view=auto
==============================================================================
---
activemq/camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/CamelModule.java
(added)
+++
activemq/camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/CamelModule.java
Wed Aug 13 07:18:40 2008
@@ -0,0 +1,71 @@
+/**
+ *
+ * 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.guice;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.multibindings.Multibinder;
+import org.apache.camel.CamelContext;
+import org.apache.camel.Routes;
+import org.apache.camel.builder.RouteBuilder;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * A default Guice module for creating a [EMAIL PROTECTED] CamelContext} and
registering a list of [EMAIL PROTECTED] RouteBuilder} types to register.
+ * <p/>
+ * You can drive from this class to overload the [EMAIL PROTECTED]
#configureRoutes(com.google.inject.multibindings.Multibinder)} method to
perform custom binding for
+ * route builders. Another approach is to create a [EMAIL PROTECTED]
RouteBuilder} which just initialises all of your individual route builders
+ *
+ * @version $Revision: 1.1 $
+ */
+public class CamelModule extends AbstractModule {
+ private List<Class<? extends RouteBuilder>> routeClassList;
+
+ protected CamelModule(Class<? extends RouteBuilder>... routeTypes) {
+ routeClassList = new ArrayList<Class<? extends RouteBuilder>>();
+ for (Class<? extends RouteBuilder> routeType : routeTypes) {
+ routeClassList.add(routeType);
+ }
+ }
+
+ protected CamelModule(List<Class<? extends RouteBuilder>> routeClassList) {
+ this.routeClassList = routeClassList;
+ }
+
+ protected void configure() {
+
bind(CamelContext.class).to(GuiceCamelContext.class).asEagerSingleton();
+
+ Multibinder<Routes> routesBinder = Multibinder.newSetBinder(binder(),
Routes.class);
+
+ for (Class<? extends Routes> routeType : routeClassList) {
+ routesBinder.addBinding().to(routeType);
+ }
+
+ configureRoutes(routesBinder);
+ }
+
+ /**
+ * Provides a strategy method configure the routes, typically via [EMAIL
PROTECTED] RouteBuilder} instances
+ *
+ * @param routesBinder
+ */
+ protected void configureRoutes(Multibinder<Routes> routesBinder) {
+ }
+
+}
Propchange:
activemq/camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/CamelModule.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
activemq/camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/GuiceCamelContext.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/GuiceCamelContext.java?rev=685565&view=auto
==============================================================================
---
activemq/camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/GuiceCamelContext.java
(added)
+++
activemq/camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/GuiceCamelContext.java
Wed Aug 13 07:18:40 2008
@@ -0,0 +1,120 @@
+/**
+ *
+ * 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.guice;
+
+import com.google.inject.Inject;
+import org.apache.camel.Routes;
+import org.apache.camel.TypeConverter;
+import org.apache.camel.builder.ErrorHandlerBuilder;
+import org.apache.camel.guice.impl.GuiceInjector;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.spi.*;
+
+import javax.naming.Context;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+public class GuiceCamelContext extends DefaultCamelContext {
+ private final com.google.inject.Injector injector;
+
+ @Inject
+ public GuiceCamelContext(com.google.inject.Injector injector) {
+ this.injector = injector;
+ }
+
+ @Inject
+ public void setRouteBuilders(Set<Routes> routeBuilders) throws Exception {
+ for (Routes routeBuilder : routeBuilders) {
+ addRoutes(routeBuilder);
+ }
+ }
+
+ @Override
+ @Inject(optional = true)
+ public void setRegistry(Registry registry) {
+ super.setRegistry(registry);
+ }
+
+ @Override
+ @Inject(optional = true)
+ public void setJndiContext(Context jndiContext) {
+ super.setJndiContext(jndiContext);
+ }
+
+ @Override
+ @Inject(optional = true)
+ public void setInjector(Injector injector) {
+ super.setInjector(injector);
+ }
+
+ @Override
+ @Inject(optional = true)
+ public void setExchangeConverter(ExchangeConverter exchangeConverter) {
+ super.setExchangeConverter(exchangeConverter);
+ }
+
+ @Override
+ @Inject(optional = true)
+ public void setComponentResolver(ComponentResolver componentResolver) {
+ super.setComponentResolver(componentResolver);
+ }
+
+ @Override
+ @Inject(optional = true)
+ public void setAutoCreateComponents(boolean autoCreateComponents) {
+ super.setAutoCreateComponents(autoCreateComponents);
+ }
+
+ @Override
+ @Inject(optional = true)
+ public void setErrorHandlerBuilder(ErrorHandlerBuilder
errorHandlerBuilder) {
+ super.setErrorHandlerBuilder(errorHandlerBuilder);
+ }
+
+ @Override
+ @Inject(optional = true)
+ public void setInterceptStrategies(List<InterceptStrategy>
interceptStrategies) {
+ super.setInterceptStrategies(interceptStrategies);
+ }
+
+ @Override
+ @Inject(optional = true)
+ public void setLanguageResolver(LanguageResolver languageResolver) {
+ super.setLanguageResolver(languageResolver);
+ }
+
+ @Override
+ @Inject(optional = true)
+ public void setLifecycleStrategy(LifecycleStrategy lifecycleStrategy) {
+ super.setLifecycleStrategy(lifecycleStrategy);
+ }
+
+ @Override
+ @Inject(optional = true)
+ public void setTypeConverter(TypeConverter typeConverter) {
+ super.setTypeConverter(typeConverter);
+ }
+
+ @Override
+ protected Injector createInjector() {
+ return new GuiceInjector(injector);
+ }
+}
Propchange:
activemq/camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/GuiceCamelContext.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
activemq/camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/impl/GuiceInjector.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/impl/GuiceInjector.java?rev=685565&view=auto
==============================================================================
---
activemq/camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/impl/GuiceInjector.java
(added)
+++
activemq/camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/impl/GuiceInjector.java
Wed Aug 13 07:18:40 2008
@@ -0,0 +1,38 @@
+/**
+ *
+ * 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.guice.impl;
+
+import org.apache.camel.spi.Injector;
+
+/**
+ * An injector which uses Guice to perform the dependency injection of types
+ *
+ * @version $Revision: 1.1 $
+ */
+public class GuiceInjector implements Injector {
+ private final com.google.inject.Injector injector;
+
+ public GuiceInjector(com.google.inject.Injector injector) {
+ this.injector = injector;
+ }
+
+ public <T> T newInstance(Class<T> type) {
+ return injector.getInstance(type);
+ }
+
+}
Propchange:
activemq/camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/impl/GuiceInjector.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/ConciseGuiceRouteTest.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/ConciseGuiceRouteTest.java?rev=685565&view=auto
==============================================================================
---
activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/ConciseGuiceRouteTest.java
(added)
+++
activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/ConciseGuiceRouteTest.java
Wed Aug 13 07:18:40 2008
@@ -0,0 +1,40 @@
+/**
+ *
+ * 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.guice;
+
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+import junit.framework.TestCase;
+import org.apache.camel.CamelContext;
+
+/**
+ * Lets use a RouteBuilder to bind instances of routes to the CamelContext
+ *
+ * @version $Revision: 1.1 $
+ */
+public class ConciseGuiceRouteTest extends TestCase {
+
+ public void testGuice() throws Exception {
+ Injector injector = Guice.createInjector(new
CamelModule(MyRouteInstaller.class, MyHardcodeRoute.class));
+ CamelContext camelContext = injector.getInstance(CamelContext.class);
+ camelContext.start();
+ Thread.sleep(1000);
+ camelContext.stop();
+ }
+
+}
\ No newline at end of file
Propchange:
activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/ConciseGuiceRouteTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/MyConfigurableRoute.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/MyConfigurableRoute.java?rev=685565&view=auto
==============================================================================
---
activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/MyConfigurableRoute.java
(added)
+++
activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/MyConfigurableRoute.java
Wed Aug 13 07:18:40 2008
@@ -0,0 +1,43 @@
+/**
+ *
+ * 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.guice;
+
+import com.google.inject.Inject;
+import com.google.inject.name.Named;
+import org.apache.camel.Endpoint;
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ * A route which is reused multiple times with different configurations
+ *
+ * @version $Revision: 1.1 $
+ */
+public class MyConfigurableRoute extends RouteBuilder {
+ protected Endpoint foo;
+ protected Endpoint bar;
+
+ @Inject
+ public MyConfigurableRoute(@Named("bar") Endpoint bar, @Named("foo")
Endpoint foo) {
+ this.bar = bar;
+ this.foo = foo;
+ }
+
+ public void configure() throws Exception {
+ from(foo).to(bar);
+ }
+}
Propchange:
activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/MyConfigurableRoute.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/MyHardcodeRoute.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/MyHardcodeRoute.java?rev=685565&view=auto
==============================================================================
---
activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/MyHardcodeRoute.java
(added)
+++
activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/MyHardcodeRoute.java
Wed Aug 13 07:18:40 2008
@@ -0,0 +1,42 @@
+/**
+ *
+ * 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.guice;
+
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ * A single hard coded route
+ *
+ * @version $Revision: 1.1 $
+ */
+public class MyHardcodeRoute extends RouteBuilder {
+ protected String foo = "direct:foo";
+ protected String bar = "direct:bar";
+
+ public void configure() throws Exception {
+ from(foo).to(bar);
+ }
+
+ public void setBar(String bar) {
+ this.bar = bar;
+ }
+
+ public void setFoo(String foo) {
+ this.foo = foo;
+ }
+}
\ No newline at end of file
Propchange:
activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/MyHardcodeRoute.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/MyRouteInstaller.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/MyRouteInstaller.java?rev=685565&view=auto
==============================================================================
---
activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/MyRouteInstaller.java
(added)
+++
activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/MyRouteInstaller.java
Wed Aug 13 07:18:40 2008
@@ -0,0 +1,37 @@
+/**
+ *
+ * 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.guice;
+
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ * Lets use a RouteBuilder as an installer of other routes
+ * where we can let the CamelContext resolve endpoints for us
+ */
+public class MyRouteInstaller extends RouteBuilder {
+
+ public void configure() throws Exception {
+ // TODO we could register explicit endpoints here too if we want
+
+ // lets add some other route builders
+ addRoutes(new MyConfigurableRoute(endpoint("direct:a"),
endpoint("direct:b")));
+ addRoutes(new MyConfigurableRoute(endpoint("direct:c"),
endpoint("direct:d")));
+
+ }
+
+}
Propchange:
activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/MyRouteInstaller.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/TraditionalGuiceRouteTest.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/TraditionalGuiceRouteTest.java?rev=685565&view=auto
==============================================================================
---
activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/TraditionalGuiceRouteTest.java
(added)
+++
activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/TraditionalGuiceRouteTest.java
Wed Aug 13 07:18:40 2008
@@ -0,0 +1,62 @@
+/**
+ *
+ * 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.guice;
+
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+import com.google.inject.multibindings.Multibinder;
+import junit.framework.TestCase;
+import org.apache.camel.CamelContext;
+import org.apache.camel.Routes;
+
+/**
+ * Lets use a custom CamelModule to perform explicit binding of route builders
+ *
+ * @version $Revision: 1.1 $
+ */
+public class TraditionalGuiceRouteTest extends TestCase {
+
+ public static class MyModule extends CamelModule {
+
+ /**
+ * Lets add the routes
+ */
+ @Override
+ protected void configureRoutes(Multibinder<Routes> binder) {
+ // use traditional Guice approach to configure routes
+ binder.addBinding().to(MyHardcodeRoute.class);
+ binder.addBinding().to(MyRouteInstaller.class);
+
+ // TODO allow injection by @Named("foo") endpoints? Let the
CamelContext provide it??
+ }
+
+ // TODO demo binding endpoints?
+ //bind(Endpoint.class).annotatedWith(Names.name("")).
+
+ }
+
+
+ public void testGuice() throws Exception {
+ Injector injector = Guice.createInjector(new MyModule());
+ CamelContext camelContext = injector.getInstance(CamelContext.class);
+ camelContext.start();
+ Thread.sleep(1000);
+ camelContext.stop();
+ }
+
+}
Propchange:
activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/TraditionalGuiceRouteTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
activemq/camel/trunk/components/camel-guice/src/test/resources/log4j.properties
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-guice/src/test/resources/log4j.properties?rev=685565&view=auto
==============================================================================
---
activemq/camel/trunk/components/camel-guice/src/test/resources/log4j.properties
(added)
+++
activemq/camel/trunk/components/camel-guice/src/test/resources/log4j.properties
Wed Aug 13 07:18:40 2008
@@ -0,0 +1,35 @@
+## ------------------------------------------------------------------------
+## 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.
+## ------------------------------------------------------------------------
+
+#
+# The logging properties used during tests..
+#
+log4j.rootLogger=INFO, out
+
+log4j.logger.org.apache.camel=DEBUG
+
+# CONSOLE appender not used by default
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1}
- %m%n
+
+# File appender
+log4j.appender.out=org.apache.log4j.FileAppender
+log4j.appender.out.layout=org.apache.log4j.PatternLayout
+log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} -
%m%n
+log4j.appender.out.file=target/test.log
+log4j.appender.out.append=true
Propchange:
activemq/camel/trunk/components/camel-guice/src/test/resources/log4j.properties
------------------------------------------------------------------------------
svn:eol-style = native
Modified: activemq/camel/trunk/components/pom.xml
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/pom.xml?rev=685565&r1=685564&r2=685565&view=diff
==============================================================================
--- activemq/camel/trunk/components/pom.xml (original)
+++ activemq/camel/trunk/components/pom.xml Wed Aug 13 07:18:40 2008
@@ -41,7 +41,8 @@
<module>camel-cxf</module>
<module>camel-flatpack</module>
<module>camel-ftp</module>
- <module>camel-groovy</module>
+ <module>camel-guice</module>
+ <!--<module>camel-groovy</module>-->
<module>camel-hamcrest</module>
<module>camel-http</module>
<module>camel-ibatis</module>
@@ -55,6 +56,7 @@
<module>camel-jms</module>
<module>camel-josql</module>
<module>camel-jcr</module>
+ <!--<module>camel-jmxconnect</module>-->
<module>camel-jpa</module>
<module>camel-jt400</module>
<module>camel-juel</module>
Modified: activemq/camel/trunk/pom.xml
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/pom.xml?rev=685565&r1=685564&r2=685565&view=diff
==============================================================================
--- activemq/camel/trunk/pom.xml (original)
+++ activemq/camel/trunk/pom.xml Wed Aug 13 07:18:40 2008
@@ -218,6 +218,11 @@
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
+ <artifactId>camel-guice</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
<artifactId>camel-hamcrest</artifactId>
<version>${project.version}</version>
</dependency>