Red Hat
Nov 18, 2015
by Christina Lin
Last post we talked about how to get your EAP Fuse ready, now it's time to start developing, there are several ways to do this
  • Spring Framework
  • CDI with Java DSL
  • XML without Spring
In this series post I am going to show the above ways of creating a web application running in JBoss EAP. To make things clear and easy, I will be using the exact same Camel route for all there different methods.What this Camel route does, is it starts up a timer that will log every 5 second, simple, easy, not much going on.

Before we start develop our simple camel route, we need to a base WAR project to work on, so first we need to create a WAR file, I am sure you must have a million way to create that, every one sort of have their own best practice for this. For me, in the example, I will create one with maven, using the webapp-javaee6 artifact. 

A. Create Project, select Maven Project, 

B. Click Next when you are at New Maven Project, and it will take you to the next step, select the webapp-javaee6 artifact.

C. Add your project name, and then click Next, you will have a ready to go WAR project in your JBoss Developer Studio. (Note, for my examples later, I am going to give them different project Names)

D. Add Camel dependency in the pom.xml file (do make sure you maven repo is configure properly pointing to http://repo.fusesource.com/nexus/content/repositories/releases)

    <!-- camel -->
    <dependency>
      <groupId>org.apache.camel</groupId>
      <artifactId>camel-core</artifactId>
      <version>2.15.1.redhat-621xxx</version>
      <scope>provided</scope>
    </dependency>


E. Optional, change your JDK version accordingly in pom.xml of the WAR project.




Spring DSL

The easiest to add you camel route the WAR application is adding an Spring DSL Camel route application in the classpath, note the file will be automatically pickup by the Camel Subsystem in JBoss EAP with name matching *-camel-context.xml.

  • Create a new WAR project, with this project, I am going to name it "mySpringdemo", find your "webapp" folder, create a "META-INF" folder for all the Camel file, please note, your camel files does not have to be in here, it should work as long as it's in the classpath, I am only placing it here so it's nice and tidy. 





  • Create Camel route called myfisrt-camel-context.xml in META-INF folder. Make sure it is set to "Spring" framework.




  • Within route, drag and drop timer and log component and configure them. 
    • Timer URI: timer:mytimer?period=5000
    • Log Message: Spring EAP Camel Demo
  • This is what your Spring DSL look like: 
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:camel="http://camel.apache.org/schema/spring"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
       http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">

  <camelContext trace="false" xmlns="http://camel.apache.org/schema/spring">
   <route>
    <from uri="timer:mytimer?period=5000"/>
    <log message="Spring EAP Camel Demo"/>
   </route>
  </camelContext>
</beans>

  • And then we are done, ready to go. Run mvn clean install to generate the war file. 





  • Start up your JBoss EAP with Fuse subsystem enabled. If you are not sure how to do it, please take a look at this post. In side bin folder, start JBoss EAP with 
    • standalone.sh
    • standalone.bat
  • Go to http://localhost:9990/, login to admin console, under Runtime/


  • Click on Add, choose the war generated under the project target folder. Click Next, Next to deploy the application. 



  • Start up application by click on the En/Disable button. 

  • Switch to the log, you will find it's now printing the message "Spring EAP Camel Demo" every 5 seconds.


Next, we are going to talk about using the Java DSL in EAP. 
Original Post