6 Replies Latest reply on May 28, 2014 6:11 AM by jorgemoralespou_2

    Using Camel velocity

    magick93

      Hi

       

      I'm trying to understand how to add additional camel components.

       

      My use-case is I would like to use apache velocity to generate a email body.

       

      I've added

        <dependency>
         <groupId>org.apache.camel</groupId>
         <artifactId>camel-velocity</artifactId>
         <version>2.1.0</version>
         <!-- use the same version as your Camel core version -->
      </dependency

       

      at which point the projects only test no longer passes :/

       

      My SY project has a camel xml route - and this is where I would like to call velocity - however, just adding the velocity dependency is causing problems. :

      <?xml version="1.0" encoding="ASCII"?>
      <routes xmlns="http://camel.apache.org/schema/spring">
          <route>
              <from uri="switchyard://Email"/>
              <log message="Email - message received: ${body}" loggingLevel="INFO"/>
              <to uri="switchyard://OutputTemplate"/>
          </route>
      </routes>
      

       

      My questions are:

      • Should I be able to just add the camel velocity dependency, then add the <to "velocity:com/acme/MyResponse.vm" /> line?
      • Or is there more required?
        • 1. Re: Using Camel velocity
          trohovsky

          Hi Anton,

           

          you have to add the Camel Velocity dependency to the SwitchYard, because it is not packaged by default. How to do that: Extensions - SwitchYard - Project Documentation Editor

           

          You let your route as it is: <to uri="switchyard://OutputTemplate"/>. The reference named OutputTemplate should contain Camel URI binding with appropriate configuration (velocity:com/acme/MyResponse.vm")

           

          Tomas

          • 2. Re: Using Camel velocity
            magick93

            Thanks Tomas

             

            A few questions:

            1. I had read the above link and that appears to be for when running in the application server. Is it also needed for when running unit tests from eclipse?
            2. In eclipse, I was not able to add the SY runtime to the SY project configuration, so I assume that adding the SY extension to the EAP modules would not make any difference. The drop down list where I should be able to select the SY runtime was always empty, even though I had setup a SY runtime in eclipse.
            3. Once I have the extension added, will I be able to add it to the already existing camel xml route? Or do I need to create a new SY Camel xml route?
            • 3. Re: Using Camel velocity
              jorgemoralespou_2

              Anton Hughes escribió:

               

              Thanks Tomas

               

              A few questions:

              1. I had read the above link and that appears to be for when running in the application server. Is it also needed for when running unit tests from eclipse?
              2. In eclipse, I was not able to add the SY runtime to the SY project configuration, so I assume that adding the SY extension to the EAP modules would not make any difference. The drop down list where I should be able to select the SY runtime was always empty, even though I had setup a SY runtime in eclipse.
              3. Once I have the extension added, will I be able to add it to the already existing camel xml route? Or do I need to create a new SY Camel xml route?

              Hi,

              To have a complete working example you can refer to (fsw-demo/switchyard-stringtemplate/stringtemplate-example at master · jorgemoralespou/fsw-demo · GitHub) which is the exact thing that you want but using stringtemplate component.

              1. Yes, extensions need to be registered only for running server. (In my project you can see a JUnit without extension being registered, only dependencies for maven are set)

              2. No worry about this, as runtime is only (AFAIK) for setting swithyard version in pom, and for running container (start/stop). Extension will not have any effect on eclipse.

              3. You can add it to any route that will run in that container (JBossAS). The extension is availabe to every composite, and every component.

               

              Cheers,

              1 of 1 people found this helpful
              • 4. Re: Using Camel velocity
                magick93

                Thanks Jorge, thats really helpful.

                 

                I have one question. I cannot see in any of your poms where you add the dependency for the string-template. How/where does SY get this camel component? Or is it already part of SY?

                • 5. Re: Using Camel velocity
                  tcunning

                  Anton,

                   

                  Jorge could explain what he's doing better, but I think what we don't see in his example is him adding camel-stringtemplate to the extensions (https://docs.jboss.org/author/display/SWITCHYARD/Extensions - see the "Registering the Extension Module" part).


                  --Tom

                  • 6. Re: Using Camel velocity
                    jorgemoralespou_2

                    Hi Anton, Tom,

                    Thanks for your comments. Since this post was started, the project has changed slightly, as this project is used to demonstrate a BUG in the product that we are facing. Coming back to your question, there are 2 parts here:

                     

                    • Adding the dependency to the pom, for the JUnit to work:
                    <dependency>
                    <groupId>com.example.switchyard.stringtemplate</groupId>
                    <artifactId>stringtemplate-common</artifactId>
                    <version>0.0.1-SNAPSHOT</version>
                    <scope>provided</scope>
                    </dependency>
                    
                    • Adding the dependency to the runtime, thus installing the extension. As Tom said, instructions are there on how to add the extension, and the extension configuration is in the README of the project:
                    <module xmlns="urn:jboss:module:1.0" name="org.apache.camel.stringtemplate">
                    
                      <resources>
                      <resource-root path="camel-stringtemplate-2.10.0.redhat-60024.jar"/>
                      <resource-root path="stringtemplate-3.2.1.jar"/>
                      </resources>
                    
                      <dependencies>
                      <module name="org.slf4j"/>
                      <module name="javax.api"/>
                      <module name="org.apache.camel.core"/>
                      <module name="org.antlr"/>
                      </dependencies>
                    </module>
                    

                     

                    So all you need to do is:

                    • Create the folder $JBOSS_HOME/modules/system/layers/soa/org/apache/camel/stringtemplate/main
                    • Copy the extract from above as module.xml
                    • Copy the jars that are there referred
                    • Modify standalone.xml to add the dependency:
                            <subsystem xmlns="urn:jboss:domain:switchyard:1.0">
                                <security-configs/>
                                <modules>
                                   ...
                                </modules>
                                <extensions>
                                    ...
                                    <extension identifier="org.apache.camel.stringtemplate"/>
                                </extensions>
                            </subsystem>
                    

                     

                     

                    Cheers,