11 Replies Latest reply on Jun 5, 2012 7:48 AM by jamie archibald

    Feature request for running camel context

    jamie archibald Apprentice

      In a Spring application you can bootstrap multiple xml files in a Single VM. For example:

       

      new ClassPathXmlApplicationContext(new String[]{....})

       

      In FuseIDE it looks like the "Run As > Local Camel context" is using the org.springframework.context.support.FileSystemXmlApplicationContext, which I also believe takes in a String[] array.

       

      It would be nice if the "Run As > Local Camel Context" supported the ability to select multiple spring files and run them in the Same VM.

        • 1. Re: Feature request for running camel context
          Claus Ibsen Master

          You can run your apps using the maven Camel plugin as well, then it by default detects all the XML files in the META-inf/spring directory.

           

          For the run as local context right click menu, we should maybe allow to do that on the project level, and then it discovers all the XML files, and show a dialog where you can mark in the XML files, or something like that.

          • 2. Re: Feature request for running camel context
            jamie archibald Apprentice

            Yeah the camel plugin runs all the stuff in META-INF/spring, which is great.

             

            Discovering the files within the /resources directory would be ideal and having the ability to select which ones you want to deploy would be sweet! Reason I ask is because I have run into situations where I have a few spring files each containing a camel context, and rather than running all the spring files at the same time, it would be nice to run just a few for debugging/prototyping purposes.

             

            On a side note. I noticed the "Run As > Local Camel Context" becomes active for Blueprint files. I thought I saw James do this successfully at the CamelOne conference (but then Jonathan told me he was running a "special" build of FuseIDE). When I attempt this in the lab I can see that the console is attempting to deploy the blueprint file within spring's FileSystemApplicationContext, which in turn croaks and throws an exception.

            • 3. Re: Feature request for running camel context
              Claus Ibsen Master

              The run as blueprint, you need to use Fuse Camel 2.9, or the latest Fuse Camel 2.8, or the upcoming Apache Camel 2.10.

              • 4. Re: Feature request for running camel context
                jamie archibald Apprentice

                I've added the fuse camel 2.9.0-fuse-7-061 to my classpath as follows:

                 

                camel-blueprint

                camel-core

                 

                When I go to perform the Run As > Local Camel Context on the following blueprint file I get an exception:

                 

                Error occurred while running main from: org.apache.camel.spring.Main

                -


                BUILD FAILURE

                -


                java.lang.ClassNotFoundException: org.apache.camel.spring.Main

                     at java.net.URLClassLoader$1.run(URLClassLoader.java:202)

                     at java.security.AccessController.doPrivileged(Native Method)

                     at java.net.URLClassLoader.findClass(URLClassLoader.java:190)

                     at java.lang.ClassLoader.loadClass(ClassLoader.java:306)

                     at java.lang.ClassLoader.loadClass(ClassLoader.java:247)

                     at org.apache.camel.maven.RunMojo$1.run(RunMojo.java:410)

                     at java.lang.Thread.run(Thread.java:662)

                *************************************

                 

                It seems that FuseIDE by default is always trying to use the spring Main to bootstrap the .xml files.

                 

                I don't think the camel spring Main supports blueprint files.

                • 5. Re: Feature request for running camel context
                  Claus Ibsen Master

                  And you use the Fuse IDE that was released as part of Fuse Enterprise?

                  • 8. Re: Feature request for running camel context
                    jamie archibald Apprentice

                    <dependency>

                                   <groupId>com.gdcanada.mw</groupId>

                                   <artifactId>camel-rti</artifactId>

                                   <version>${project.version}</version>

                              </dependency>

                              <dependency>

                                   <groupId>org.apache.camel</groupId>

                                   <artifactId>camel-core</artifactId>

                                   <version>${camel.version}</version>

                              </dependency>

                              <dependency>

                                   <groupId>org.apache.camel</groupId>

                                   <artifactId>camel-test</artifactId>

                                   <version>${camel.version}</version>

                                   <scope>test</scope>

                              </dependency>

                              <dependency>

                                   <groupId>org.apache.camel</groupId>

                                   <artifactId>camel-blueprint</artifactId>

                                   <version>${camel.version}</version>

                                   <scope>runtime</scope>

                              </dependency>

                              <dependency>

                                   <groupId>org.apache.camel</groupId>

                                   <artifactId>camel-jetty</artifactId>

                                   <version>${camel.version}</version>

                                   <scope>runtime</scope>

                              </dependency>

                              <dependency>

                                   <groupId>org.apache.camel</groupId>

                                   <artifactId>camel-sql</artifactId>

                                   <version>${camel.version}</version>

                              </dependency>

                              <dependency>

                                   <groupId>postgresql</groupId>

                                   <artifactId>postgresql</artifactId>

                                   <version>${postgresql.version}</version>

                                   <scope>runtime</scope>

                              </dependency>

                              <dependency>

                                   <groupId>commons-dbcp</groupId>

                                   <artifactId>commons-dbcp</artifactId>

                                   <version>${commons-dbcp.version}</version>

                                   <scope>runtime</scope>

                              </dependency>

                              <dependency>

                                   <groupId>org.apache.derby</groupId>

                                   <artifactId>derby</artifactId>

                                   <version>${derby.version}</version>

                                   <scope>test</scope>

                              </dependency>

                     

                    The camel-rti component is a custom component I made, so you can ignore that.

                     

                    Here is the blueprint file:

                     

                     

                    <?xml version="1.0" encoding="UTF-8"?>

                    <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"

                           xmlns:camel="http://camel.apache.org/schema/blueprint"

                           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

                           xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd

                           http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd">

                     

                      <camelContext xmlns="http://camel.apache.org/schema/blueprint" trace="false">

                        <route>

                             <from uri="timer:foo?period=1000"/>

                             <to uri="log:Hello World"/>

                        </route>

                      </camelContext>

                     

                    </blueprint>

                    • 9. Re: Feature request for running camel context
                      Claus Ibsen Master

                      And whats ${project.version} ?

                      And you do not have any plugins in the pom.xml file?

                       

                      Ah it may be related to camel-test in Camel 2.9 still being dependent on Spring Framework, which has been improved in Camel 2.10.

                       

                      Can you try to add camel-spring with  in your pom.xml, to see if it runs then?

                      • 10. Re: Feature request for running camel context
                        jamie archibald Apprentice

                        Hi Claus,

                         

                        Rather than trying to figure out what the problem is in my bloated project I started from scratch by creating a Fuse project which ran without issues. I also created a plain maven project and attempted to convert my plain maven project to a fuse-like project by copying the pieces of the pom from the fuse project to determine where the problem resided.

                         

                        It appears that the problem was as follows:

                         

                        1) Running blueprint files requires your maven project packaging to be "bundle". Duh! I should have caught this.

                         

                        2) I didn't realize under the hood that executing "Run As > Local Camel" context would require the camel-maven-plugin to be added to the pom.xml's build plugins. I guess the ClassNotFoundException which contained org.apache.camel.spring.Main() kinda threw me off as I would have expected an org.apache.camel.blueprint.Main() instead. I didn't realize that in new versions of the plugin there was an argument  Local Camel Context" and the camel spring Main() function. Perhaps I'll write a blog post on my findings such that people who are migrating their projects from existing maven projects can figure out which pieces they need to move over.

                        • 11. Re: Feature request for running camel context
                          jamie archibald Apprentice

                          I also noticed that the "Run As > Local Camel Context" for blueprint and spring behave differently.

                           

                          In the spring version, you can right click on any spring xml file and execute it from the file path. Thus, the spring file can exist anywhere within the project's file path.

                           

                          However when you click on a blueprint xml file the entire project gets deployed as an OSGi bundle. This requires all of your blueprint xml files to be defined in OSGI-INF/blueprint. It also means that if you have multiple blueprint files in OSGI-INF/blueprint it will deploy all of them.

                           

                          I understand this is by design, however it was a bit confusing from a tooling perspective. When you right click on a single XML file one would expect only that file to be deployed as part of the application.

                           

                          Just a heads up!