camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r1380570 - in /camel/trunk: components/camel-cdi/ components/camel-cdi/src/main/java/org/apache/camel/cdi/ examples/camel-example-cdi/ examples/camel-example-cdi/src/main/java/org/apache/camel/example/cdi/ examples/camel-example-cdi/src/tes...
Date Tue, 04 Sep 2012 11:36:36 GMT
Author: jstrachan
Date: Tue Sep  4 11:36:36 2012
New Revision: 1380570

URL: http://svn.apache.org/viewvc?rev=1380570&view=rev
Log:
initial spike of CAMEL-5560 to add CDI support to camel:run

Added:
    camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/cdi/Main.java   (with
props)
Modified:
    camel/trunk/components/camel-cdi/pom.xml
    camel/trunk/examples/camel-example-cdi/pom.xml
    camel/trunk/examples/camel-example-cdi/src/main/java/org/apache/camel/example/cdi/MyRouteConfig.java
    camel/trunk/examples/camel-example-cdi/src/test/java/org/apache/camel/example/cdi/IntegrationTest.java
    camel/trunk/parent/pom.xml
    camel/trunk/tooling/maven/camel-maven-plugin/pom.xml
    camel/trunk/tooling/maven/camel-maven-plugin/src/main/java/org/apache/camel/maven/RunMojo.java

Modified: camel/trunk/components/camel-cdi/pom.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cdi/pom.xml?rev=1380570&r1=1380569&r2=1380570&view=diff
==============================================================================
--- camel/trunk/components/camel-cdi/pom.xml (original)
+++ camel/trunk/components/camel-cdi/pom.xml Tue Sep  4 11:36:36 2012
@@ -34,10 +34,6 @@
 
     <properties>
         <camel.osgi.export.pkg>org.apache.camel.component.cdi.*</camel.osgi.export.pkg>
-        <deltaspike-version>0.3-incubating</deltaspike-version>
-        <!-- these properties should be in-sync with deltaspike -->
-        <owb-version>1.1.5</owb-version>
-        <weld-version>1.1.5.Final</weld-version>
         <camel.osgi.import>
             !org.apache.camel.component.cdi.*,
             org.apache.deltaspike.core.api.*;resolution:=optional,
@@ -69,6 +65,13 @@
             <version>${deltaspike-version}</version>
         </dependency>
 
+        <!-- only required for the Main -->
+        <dependency>
+            <groupId>org.apache.deltaspike.cdictrl</groupId>
+            <artifactId>deltaspike-cdictrl-api</artifactId>
+            <version>${deltaspike-version}</version>
+        </dependency>
+
         <dependency>
             <groupId>org.apache.geronimo.specs</groupId>
             <artifactId>geronimo-atinject_1.0_spec</artifactId>
@@ -97,12 +100,6 @@
             <scope>test</scope>
         </dependency>
         <dependency>
-            <groupId>org.apache.deltaspike.cdictrl</groupId>
-            <artifactId>deltaspike-cdictrl-api</artifactId>
-            <version>${deltaspike-version}</version>
-            <scope>test</scope>
-        </dependency>
-        <dependency>
             <groupId>org.slf4j</groupId>
             <artifactId>jul-to-slf4j</artifactId>
             <version>${slf4j-version}</version>
@@ -139,13 +136,13 @@
                 <dependency>
                     <groupId>org.apache.openwebbeans</groupId>
                     <artifactId>openwebbeans-impl</artifactId>
-                    <version>${owb-version}</version>
+                    <version>${openwebbeans-version}</version>
                     <scope>test</scope>
                 </dependency>
                 <dependency>
                     <groupId>org.apache.openwebbeans</groupId>
                     <artifactId>openwebbeans-spi</artifactId>
-                    <version>${owb-version}</version>
+                    <version>${openwebbeans-version}</version>
                     <scope>test</scope>
                 </dependency>
             </dependencies>

Added: camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/cdi/Main.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/cdi/Main.java?rev=1380570&view=auto
==============================================================================
--- camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/cdi/Main.java (added)
+++ camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/cdi/Main.java Tue Sep
 4 11:36:36 2012
@@ -0,0 +1,137 @@
+/**
+ *
+ * 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.cdi;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.main.MainSupport;
+import org.apache.camel.view.ModelFileGenerator;
+import org.apache.deltaspike.cdise.api.CdiContainer;
+import org.apache.deltaspike.cdise.api.CdiContainerLoader;
+import org.apache.deltaspike.core.api.provider.BeanProvider;
+
+/**
+ * Allows Camel and CDI applications to be booted up on the command line as a Java Application
+ */
+public class Main extends MainSupport {
+    private static Main instance;
+    private JAXBContext jaxbContext;
+    private CdiContainer cdiContainer;
+
+    public static void main(String... args) throws Exception {
+        Main main = new Main();
+        instance = main;
+        main.enableHangupSupport();
+        main.run(args);
+    }
+
+    /**
+     * Returns the currently executing main
+     *
+     * @return the current running instance
+     */
+    public static Main getInstance() {
+        return instance;
+    }
+
+    public Main() {
+        // add options...
+    }
+
+    @Override
+    protected ProducerTemplate findOrCreateCamelTemplate() {
+        ProducerTemplate answer = BeanProvider.getContextualReference(ProducerTemplate.class,
true);
+        if (answer != null) {
+            return answer;
+        }
+        if (getCamelContexts().isEmpty()) {
+            throw new IllegalArgumentException(
+                    "No CamelContexts are available so cannot create a ProducerTemplate!");
+        }
+        return getCamelContexts().get(0).createProducerTemplate();
+    }
+
+    @Override
+    protected Map<String, CamelContext> getCamelContextMap() {
+        List<CamelContext> contexts = BeanProvider.getContextualReferences(CamelContext.class,
true);
+        Map<String, CamelContext> answer = new HashMap<String, CamelContext>();
+        for (CamelContext context : contexts) {
+            String name = context.getName();
+            answer.put(name, context);
+        }
+        return answer;
+    }
+
+    @Override
+    protected ModelFileGenerator createModelFileGenerator() throws JAXBException {
+        return new ModelFileGenerator(getJaxbContext());
+    }
+
+    public JAXBContext getJaxbContext() throws JAXBException {
+        if (jaxbContext == null) {
+            jaxbContext = createJaxbContext();
+        }
+        return jaxbContext;
+    }
+
+    protected JAXBContext createJaxbContext() throws JAXBException {
+        StringBuilder packages = new StringBuilder();
+        for (Class<?> cl : getJaxbPackages()) {
+            if (packages.length() > 0) {
+                packages.append(":");
+            }
+            packages.append(cl.getPackage().getName());
+        }
+        return JAXBContext.newInstance(packages.toString(), getClass().getClassLoader());
+    }
+
+    protected Set<Class<?>> getJaxbPackages() {
+        Set<Class<?>> classes = new HashSet<Class<?>>();
+        //classes.add(CamelContextFactoryBean.class);
+        //classes.add(AbstractCamelContextFactoryBean.class);
+        classes.add(org.apache.camel.ExchangePattern.class);
+        classes.add(org.apache.camel.model.RouteDefinition.class);
+        classes.add(org.apache.camel.model.config.StreamResequencerConfig.class);
+        classes.add(org.apache.camel.model.dataformat.DataFormatsDefinition.class);
+        classes.add(org.apache.camel.model.language.ExpressionDefinition.class);
+        classes.add(org.apache.camel.model.loadbalancer.RoundRobinLoadBalancerDefinition.class);
+        //classes.add(SSLContextParametersFactoryBean.class);
+        return classes;
+    }
+
+    @Override
+    protected void doStart() throws Exception {
+        cdiContainer = CdiContainerLoader.getCdiContainer();
+        cdiContainer.boot();
+        super.doStart();
+    }
+
+    @Override
+    protected void doStop() throws Exception {
+        super.doStop();
+        cdiContainer.shutdown();
+    }
+}

Propchange: camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/cdi/Main.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: camel/trunk/examples/camel-example-cdi/pom.xml
URL: http://svn.apache.org/viewvc/camel/trunk/examples/camel-example-cdi/pom.xml?rev=1380570&r1=1380569&r2=1380570&view=diff
==============================================================================
--- camel/trunk/examples/camel-example-cdi/pom.xml (original)
+++ camel/trunk/examples/camel-example-cdi/pom.xml Tue Sep  4 11:36:36 2012
@@ -93,8 +93,24 @@
                 <artifactId>camel-maven-plugin</artifactId>
                 <version>${project.version}</version>
                 <configuration>
-                    <duration>5s</duration>
+                  <useCDI>true</useCDI>
+<!--
+                  <duration>5s</duration>
+-->
                 </configuration>
+                <dependencies>
+                  <!-- lets use deltaspike & weld -->
+                  <dependency>
+                      <groupId>org.apache.deltaspike.cdictrl</groupId>
+                      <artifactId>deltaspike-cdictrl-weld</artifactId>
+                      <version>${deltaspike-version}</version>
+                  </dependency>
+                  <dependency>
+                      <groupId>org.jboss.weld.se</groupId>
+                      <artifactId>weld-se-core</artifactId>
+                      <version>${weld-version}</version>
+                  </dependency>
+                </dependencies>
             </plugin>
         </plugins>
     </build>

Modified: camel/trunk/examples/camel-example-cdi/src/main/java/org/apache/camel/example/cdi/MyRouteConfig.java
URL: http://svn.apache.org/viewvc/camel/trunk/examples/camel-example-cdi/src/main/java/org/apache/camel/example/cdi/MyRouteConfig.java?rev=1380570&r1=1380569&r2=1380570&view=diff
==============================================================================
--- camel/trunk/examples/camel-example-cdi/src/main/java/org/apache/camel/example/cdi/MyRouteConfig.java
(original)
+++ camel/trunk/examples/camel-example-cdi/src/main/java/org/apache/camel/example/cdi/MyRouteConfig.java
Tue Sep  4 11:36:36 2012
@@ -18,6 +18,8 @@
 package org.apache.camel.example.cdi;
 
 import javax.annotation.PostConstruct;
+import javax.ejb.Startup;
+import javax.enterprise.context.ApplicationScoped;
 import javax.enterprise.inject.Produces;
 import javax.inject.Inject;
 import javax.inject.Named;
@@ -31,19 +33,21 @@ import org.apache.camel.cdi.Uri;
 /**
  * Configures all our Camel components, endpoints and beans and create the Camel routes
  */
+@Startup
+@ApplicationScoped
 public class MyRouteConfig {
 
     @Inject
-    public CamelContext camelContext;
+    private CamelContext camelContext;
 
     @Inject
     //@Uri("activemq:test.MyQueue")
     @Uri("file://target/testdata/queue")
-    public Endpoint queueEndpoint;
+    private Endpoint queueEndpoint;
 
     @Inject
     @Uri("file://target/testdata/result?noop=true")
-    public Endpoint resultEndpoint;
+    private Endpoint resultEndpoint;
 
     @Produces
     public RouteBuilder createRoutes() {
@@ -78,6 +82,11 @@ public class MyRouteConfig {
      */
     @PostConstruct
     public void start() throws Exception {
+        System.out.println("======= Starting MyRouteConfig!!");
         camelContext.addRoutes(createRoutes());
     }
+
+    public Endpoint getResultEndpoint() {
+        return resultEndpoint;
+    }
 }

Modified: camel/trunk/examples/camel-example-cdi/src/test/java/org/apache/camel/example/cdi/IntegrationTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/examples/camel-example-cdi/src/test/java/org/apache/camel/example/cdi/IntegrationTest.java?rev=1380570&r1=1380569&r2=1380570&view=diff
==============================================================================
--- camel/trunk/examples/camel-example-cdi/src/test/java/org/apache/camel/example/cdi/IntegrationTest.java
(original)
+++ camel/trunk/examples/camel-example-cdi/src/test/java/org/apache/camel/example/cdi/IntegrationTest.java
Tue Sep  4 11:36:36 2012
@@ -54,7 +54,7 @@ public class IntegrationTest {
     public RouteBuilder createRoutes() {
         return new RouteBuilder() {
             public void configure() {
-                from(config.resultEndpoint).to(result);
+                from(config.getResultEndpoint()).to(result);
             }
         };
     }

Modified: camel/trunk/parent/pom.xml
URL: http://svn.apache.org/viewvc/camel/trunk/parent/pom.xml?rev=1380570&r1=1380569&r2=1380570&view=diff
==============================================================================
--- camel/trunk/parent/pom.xml (original)
+++ camel/trunk/parent/pom.xml Tue Sep  4 11:36:36 2012
@@ -68,6 +68,7 @@
     <cxf-version>2.6.2</cxf-version>
     <cxf-version-range>[2.4,2.8)</cxf-version-range>
     <cxf-xjc-utils-version>2.6.0</cxf-xjc-utils-version>
+    <deltaspike-version>0.3-incubating</deltaspike-version>
     <derby-version>10.9.1.0</derby-version>
     <dnsjava-version>2.1.1</dnsjava-version>
     <dozer-version>5.3.2</dozer-version>
@@ -151,6 +152,7 @@
     <netty-bundle-version>3.2.7.Final_1</netty-bundle-version>
     <netty-version>3.5.5.Final</netty-version>
     <ode-version>1.3.4</ode-version>
+    <!-- should be in-sync with deltaspike -->
     <openwebbeans-version>1.1.5</openwebbeans-version>
     <ognl-version>3.0.5_1</ognl-version>
     <osgi-version>4.2.0</osgi-version>
@@ -197,6 +199,8 @@
     <twitter4j-version>2.2.5</twitter4j-version>
     <velocity-version>1.7</velocity-version>
     <vysper-version>0.7</vysper-version>
+    <!-- should be in-sync with deltaspike -->
+    <weld-version>1.1.5.Final</weld-version>
     <woodstox-version>4.1.4</woodstox-version>
     <xbean-spring-version>3.11.1</xbean-spring-version>
     <xml-resolver-version>1.2</xml-resolver-version>

Modified: camel/trunk/tooling/maven/camel-maven-plugin/pom.xml
URL: http://svn.apache.org/viewvc/camel/trunk/tooling/maven/camel-maven-plugin/pom.xml?rev=1380570&r1=1380569&r2=1380570&view=diff
==============================================================================
--- camel/trunk/tooling/maven/camel-maven-plugin/pom.xml (original)
+++ camel/trunk/tooling/maven/camel-maven-plugin/pom.xml Tue Sep  4 11:36:36 2012
@@ -48,6 +48,12 @@
       <groupId>org.apache.camel</groupId>
       <artifactId>camel-test-blueprint</artifactId>
     </dependency>
+    <!-- camel-cdi has Main class for running CDI -->
+    <dependency>
+      <groupId>org.apache.camel</groupId>
+      <artifactId>camel-cdi</artifactId>
+    </dependency>
+
     <dependency>
       <groupId>org.codehaus.mojo</groupId>
       <artifactId>exec-maven-plugin</artifactId>

Modified: camel/trunk/tooling/maven/camel-maven-plugin/src/main/java/org/apache/camel/maven/RunMojo.java
URL: http://svn.apache.org/viewvc/camel/trunk/tooling/maven/camel-maven-plugin/src/main/java/org/apache/camel/maven/RunMojo.java?rev=1380570&r1=1380569&r2=1380570&view=diff
==============================================================================
--- camel/trunk/tooling/maven/camel-maven-plugin/src/main/java/org/apache/camel/maven/RunMojo.java
(original)
+++ camel/trunk/tooling/maven/camel-maven-plugin/src/main/java/org/apache/camel/maven/RunMojo.java
Tue Sep  4 11:36:36 2012
@@ -122,6 +122,14 @@ public class RunMojo extends AbstractExe
     protected boolean useBlueprint;
 
     /**
+     * Whether to use CDI when running, instead of Spring
+     *
+     * @parameter expression="${camel.cdi}"
+     *            default-value="false"
+     */
+    protected boolean useCDI;
+
+    /**
      * @component
      */
     private ArtifactResolver artifactResolver;
@@ -350,6 +358,7 @@ public class RunMojo extends AbstractExe
      */
     public void execute() throws MojoExecutionException, MojoFailureException {
         boolean usingSpringJavaConfigureMain = false;
+        boolean useCdiMain = useCDI;
         boolean usingBlueprintMain = useBlueprint;
         if (killAfter != -1) {
             getLog().warn("Warning: killAfter is now deprecated. Do you need it ? Please
comment on MEXEC-6.");
@@ -400,6 +409,11 @@ public class RunMojo extends AbstractExe
         if (usingSpringJavaConfigureMain) {
             mainClass = "org.apache.camel.spring.javaconfig.Main";
             getLog().info("Using org.apache.camel.spring.javaconfig.Main to initiate a CamelContext");
+        } else if (useCdiMain) {
+            mainClass = "org.apache.camel.cdi.Main";
+            // must include plugin dependencies for blueprint
+            includePluginDependencies = true;
+            getLog().info("Using " + mainClass + " to initiate a CamelContext");
         } else if (usingBlueprintMain) {
             mainClass = "org.apache.camel.test.blueprint.Main";
             // must include plugin dependencies for blueprint



Mime
View raw message