You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by js...@apache.org on 2008/11/28 16:41:12 UTC
svn commit: r721522 - in
/activemq/camel/trunk/components/camel-spring-javaconfig: ./ src/ src/main/
src/main/java/ src/main/java/org/ src/main/java/org/apache/
src/main/java/org/apache/camel/ src/main/java/org/apache/camel/spring/
src/main/java/org/ap...
Author: jstrachan
Date: Fri Nov 28 07:41:11 2008
New Revision: 721522
URL: http://svn.apache.org/viewvc?rev=721522&view=rev
Log:
added a first spike for CAMEL-1128
Added:
activemq/camel/trunk/components/camel-spring-javaconfig/
activemq/camel/trunk/components/camel-spring-javaconfig/pom.xml (with props)
activemq/camel/trunk/components/camel-spring-javaconfig/src/
activemq/camel/trunk/components/camel-spring-javaconfig/src/main/
activemq/camel/trunk/components/camel-spring-javaconfig/src/main/java/
activemq/camel/trunk/components/camel-spring-javaconfig/src/main/java/org/
activemq/camel/trunk/components/camel-spring-javaconfig/src/main/java/org/apache/
activemq/camel/trunk/components/camel-spring-javaconfig/src/main/java/org/apache/camel/
activemq/camel/trunk/components/camel-spring-javaconfig/src/main/java/org/apache/camel/spring/
activemq/camel/trunk/components/camel-spring-javaconfig/src/main/java/org/apache/camel/spring/javaconfig/
activemq/camel/trunk/components/camel-spring-javaconfig/src/main/java/org/apache/camel/spring/javaconfig/CamelConfiguration.java (with props)
activemq/camel/trunk/components/camel-spring-javaconfig/src/main/java/org/apache/camel/spring/javaconfig/SingleRouteCamelConfiguration.java (with props)
activemq/camel/trunk/components/camel-spring-javaconfig/src/main/resources/
activemq/camel/trunk/components/camel-spring-javaconfig/src/main/resources/META-INF/
activemq/camel/trunk/components/camel-spring-javaconfig/src/main/resources/META-INF/services/
activemq/camel/trunk/components/camel-spring-javaconfig/src/test/
activemq/camel/trunk/components/camel-spring-javaconfig/src/test/java/
activemq/camel/trunk/components/camel-spring-javaconfig/src/test/java/org/
activemq/camel/trunk/components/camel-spring-javaconfig/src/test/java/org/apache/
activemq/camel/trunk/components/camel-spring-javaconfig/src/test/java/org/apache/camel/
activemq/camel/trunk/components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/
activemq/camel/trunk/components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/javaconfig/
activemq/camel/trunk/components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/javaconfig/examples/
activemq/camel/trunk/components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/javaconfig/examples/FilterConfig.java (with props)
activemq/camel/trunk/components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/javaconfig/examples/FilterTest.java (with props)
activemq/camel/trunk/components/camel-spring-javaconfig/src/test/resources/
Added: activemq/camel/trunk/components/camel-spring-javaconfig/pom.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring-javaconfig/pom.xml?rev=721522&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-spring-javaconfig/pom.xml (added)
+++ activemq/camel/trunk/components/camel-spring-javaconfig/pom.xml Fri Nov 28 07:41:11 2008
@@ -0,0 +1,105 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project>
+ <parent>
+ <artifactId>components</artifactId>
+ <groupId>org.apache.camel</groupId>
+ <version>2.0-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-spring-javaconfig</artifactId>
+ <name>Camel :: Spring JavaConfig</name>
+ <description>Camel Spring JavaConfig support</description>
+ <packaging>bundle</packaging>
+
+ <properties>
+ <camel.osgi.export.pkg>org.apache.camel.component.spring.javaconfig.*</camel.osgi.export.pkg>
+ </properties>
+
+
+ <!--
+
+ <build>
+ <defaultGoal>install</defaultGoal>
+ <resources>
+ <resource>
+ <directory>src/main/resources</directory>
+ <includes>
+ <include>**/*</include>
+ </includes>
+ <filtering>true</filtering>
+ </resource>
+ </resources>
+ <plugins>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>build-helper-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>attach-artifacts</id>
+ <phase>package</phase>
+ <goals>
+ <goal>attach-artifact</goal>
+ </goals>
+ <configuration>
+ <artifacts>
+ <artifact>
+ <file>./src/main/resources/schema/camel-spring-javaconfig.xsd</file>
+ <type>xsd</type>
+ </artifact>
+ </artifacts>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ -->
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-spring</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.javaconfig</groupId>
+ <artifactId>org.springframework.config.java</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-test</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.annotation</groupId>
+ <artifactId>jsr250-api</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+</project>
Propchange: activemq/camel/trunk/components/camel-spring-javaconfig/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/camel/trunk/components/camel-spring-javaconfig/src/main/java/org/apache/camel/spring/javaconfig/CamelConfiguration.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring-javaconfig/src/main/java/org/apache/camel/spring/javaconfig/CamelConfiguration.java?rev=721522&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-spring-javaconfig/src/main/java/org/apache/camel/spring/javaconfig/CamelConfiguration.java (added)
+++ activemq/camel/trunk/components/camel-spring-javaconfig/src/main/java/org/apache/camel/spring/javaconfig/CamelConfiguration.java Fri Nov 28 07:41:11 2008
@@ -0,0 +1,82 @@
+/**
+ *
+ * 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.javaconfig;
+
+import org.apache.camel.Routes;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.spring.CamelBeanPostProcessor;
+import org.apache.camel.spring.SpringCamelContext;
+import org.springframework.beans.BeansException;
+import org.springframework.beans.factory.BeanInitializationException;
+import org.springframework.config.java.annotation.Bean;
+import org.springframework.config.java.annotation.Configuration;
+
+import java.util.List;
+
+/**
+ * A useful base class for writing
+ * <a href="http://www.springsource.org/javaconfig">Spring JavaConfig</a>
+ * configurations for working with Camel
+ *
+ * @version $Revision: 1.1 $
+ */
+@Configuration
+public abstract class CamelConfiguration {
+
+ @Bean
+ public CamelBeanPostProcessor camelBeanPostProcessor() throws Exception {
+ return new CamelBeanPostProcessor(){
+ @Override
+ public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
+ try {
+ SpringCamelContext context = getCamelContext();
+ if (context == null) {
+ // we have not yet injected the context so lets set it
+ setCamelContext(camelContext());
+ }
+ return super.postProcessAfterInitialization(bean, beanName);
+ } catch (BeansException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new BeanInitializationException(e.getMessage(), e);
+ }
+ }
+ };
+ }
+
+ /**
+ * Returns the CamelContext
+ */
+ @Bean
+ public SpringCamelContext camelContext() throws Exception {
+ SpringCamelContext camelContext = new SpringCamelContext();
+ List<RouteBuilder> routes = routes();
+ for (Routes route : routes) {
+ camelContext.addRoutes(route);
+ }
+ return camelContext;
+ }
+
+
+ /**
+ * Returns the list of routes to use in this configuration
+ */
+ @Bean
+ public abstract List<RouteBuilder> routes();
+
+}
Propchange: activemq/camel/trunk/components/camel-spring-javaconfig/src/main/java/org/apache/camel/spring/javaconfig/CamelConfiguration.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/camel/trunk/components/camel-spring-javaconfig/src/main/java/org/apache/camel/spring/javaconfig/SingleRouteCamelConfiguration.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring-javaconfig/src/main/java/org/apache/camel/spring/javaconfig/SingleRouteCamelConfiguration.java?rev=721522&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-spring-javaconfig/src/main/java/org/apache/camel/spring/javaconfig/SingleRouteCamelConfiguration.java (added)
+++ activemq/camel/trunk/components/camel-spring-javaconfig/src/main/java/org/apache/camel/spring/javaconfig/SingleRouteCamelConfiguration.java Fri Nov 28 07:41:11 2008
@@ -0,0 +1,47 @@
+/**
+ *
+ * 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.javaconfig;
+
+import org.apache.camel.Routes;
+import org.apache.camel.builder.RouteBuilder;
+import org.springframework.config.java.annotation.Bean;
+
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Collections;
+
+/**
+ * A useful base class for writing
+ * <a href="http://www.springsource.org/javaconfig">Spring JavaConfig</a>
+ * configurations to configure a CamelContext with a single {@link RouteBuilder} instance
+
+ * @version $Revision: 1.1 $
+ */
+public abstract class SingleRouteCamelConfiguration extends CamelConfiguration {
+ //@Bean
+ public List<RouteBuilder> routes() {
+ return Collections.singletonList(route());
+ }
+
+ /**
+ * Creates the single {@link RouteBuilder} to use in this confguration
+ * @return
+ */
+ //@Bean
+ public abstract RouteBuilder route();
+}
Propchange: activemq/camel/trunk/components/camel-spring-javaconfig/src/main/java/org/apache/camel/spring/javaconfig/SingleRouteCamelConfiguration.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/camel/trunk/components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/javaconfig/examples/FilterConfig.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/javaconfig/examples/FilterConfig.java?rev=721522&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/javaconfig/examples/FilterConfig.java (added)
+++ activemq/camel/trunk/components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/javaconfig/examples/FilterConfig.java Fri Nov 28 07:41:11 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.spring.javaconfig.examples;
+
+import org.springframework.config.java.annotation.Configuration;
+import org.springframework.config.java.annotation.Bean;
+import org.apache.camel.spring.javaconfig.SingleRouteCamelConfiguration;
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ * @version $Revision: 1.1 $
+*/
+@Configuration
+public class FilterConfig extends SingleRouteCamelConfiguration {
+ @Bean
+ public RouteBuilder route() {
+ return new RouteBuilder() {
+ public void configure() {
+ from("direct:start").filter(header("foo").isEqualTo("bar")).to("mock:result");
+ }
+ };
+ }
+}
Propchange: activemq/camel/trunk/components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/javaconfig/examples/FilterConfig.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/camel/trunk/components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/javaconfig/examples/FilterTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/javaconfig/examples/FilterTest.java?rev=721522&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/javaconfig/examples/FilterTest.java (added)
+++ activemq/camel/trunk/components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/javaconfig/examples/FilterTest.java Fri Nov 28 07:41:11 2008
@@ -0,0 +1,66 @@
+/**
+ *
+ * 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.javaconfig.examples;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Produce;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.CamelContext;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.springframework.config.java.test.JavaConfigContextLoader;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit38.AbstractJUnit38SpringContextTests;
+import org.springframework.beans.factory.annotation.Autowired;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+@ContextConfiguration(locations = "org.apache.camel.spring.javaconfig.examples.FilterConfig", loader = JavaConfigContextLoader.class)
+public class FilterTest extends AbstractJUnit38SpringContextTests {
+
+ @Autowired
+ protected CamelContext camelContext;
+
+ @Produce(uri = "direct:start")
+ protected ProducerTemplate template;
+
+ @EndpointInject(uri = "mock:result")
+ protected MockEndpoint resultEndpoint;
+
+ public void testSendMatchingMessage() throws Exception {
+ assertNotNull("No injection for camelContext", camelContext);
+ assertNotNull("No Camel injection for template", template);
+ assertNotNull("No Camel injection for resultEndpoint", resultEndpoint);
+
+ resultEndpoint.expectedMessageCount(1);
+
+ template.sendBodyAndHeader("direct:start", "<matched/>", "foo", "bar");
+
+ resultEndpoint.assertIsSatisfied();
+ }
+
+ public void testSendNotMatchingMessage() throws Exception {
+ resultEndpoint.expectedMessageCount(0);
+
+ template.sendBodyAndHeader("direct:start", "<notMatched/>", "foo", "notMatchedHeaderValue");
+
+ resultEndpoint.assertIsSatisfied();
+ }
+
+
+}
Propchange: activemq/camel/trunk/components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/javaconfig/examples/FilterTest.java
------------------------------------------------------------------------------
svn:eol-style = native