DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
View Events Video Library
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Integrating PostgreSQL Databases with ANF: Join this workshop to learn how to create a PostgreSQL server using Instaclustr’s managed service

Mobile Database Essentials: Assess data needs, storage requirements, and more when leveraging databases for cloud and edge applications.

Monitoring and Observability for LLMs: Datadog and Google Cloud discuss how to achieve optimal AI model performance.

Automated Testing: The latest on architecture, TDD, and the benefits of AI and low-code tools.

Related

  • Why "Polyglot Programming" or "Do It Yourself Programming Languages" or "Language Oriented Programming" sucks?
  • Deploy a Java application using Helm, Part 2
  • Deploy a Java application using Helm, Part 1
  • How to Automatically Detect Multiple Cybersecurity Threats from an Input Text String in Java

Trending

  • Creating a Deep vs. Shallow Copy of an Object in Java
  • Leveraging FastAPI for Building Secure and High-Performance Banking APIs
  • What Is Good Database Design?
  • The Emergence of Cloud-Native Integration Patterns in Modern Enterprises
  1. DZone
  2. Coding
  3. Java
  4. Red Hat JBoss Fuse: 3 Ways to Develop Your Fuse Application in JBoss EAP, Java DSL

Red Hat JBoss Fuse: 3 Ways to Develop Your Fuse Application in JBoss EAP, Java DSL

Trying to develop a Camel web app in JBoss EAP? Here are three different methods.

Christina Lin user avatar by
Christina Lin
CORE ·
Nov. 19, 15 · Tutorial
Like (5)
Save
Tweet
Share
7.76K Views

Join the DZone community and get the full member experience.

Join For Free

In this post, I am going to show the different ways of developing a Camel web application running in JBoss EAP.

  • Spring Framework
  • CDI with Java DSL
  • XML without Spring

To make things clear and easy, I will be using the exact same Camel route for all three different methods. What this Camel route does is it starts up a timer that will log every 5 seconds.

Before we start develop our simple camel route, we need 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. 

Image title

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

Image title

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).

Image title

D. Add Camel dependency in the pom.xml file (do make sure your 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.

Image title

Java DSL

The major difference between Karaf and JBoss EAP is that JBoss EAP supports JavaEE specification. From JavaEE 6, it introduces a new framework, Contexts and Dependency injection, similar to what Spring has done, allows users to defines a type-safe dependency injection as well as provide a well managed "contextual" references lifecycle for Java beans. In many cases, we want to take advantage of this standard and let it manage our bean in Camel. To lookup these beans in Camel route, we need to use the Java DSL.  

Before we start, we are going to need another Camel dependency, 

        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-cdi</artifactId>
            <version>2.15.1.redhat-620133</version>
            <scope>provided</scope>
        </dependency>

Enable CDI in your web application by placing an empty beans.xml under WEB-INF in webapp folder. Create folder WEB-INF , and XML file beans.xml

Image title

Image title

This is what your beans.xml should look like:

 <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
       bean-discovery-mode="all">
</beans>

Now I am going to show you how to create one, create a Java Class that extends org.apache.camel.builder.RouteBuilder, called MyCamelRouteBuilder.java

Image title

Inside the method , add the following Camel Route, 

    from("timer:mytimer?period=5000")
    .log("Java DSL Camel Demo");

Add your camel route to the application scope, register it's context,  and start up by setting the following annotation on top of your class.

    • @Startup
    • @ApplicationScoped
    • @ContextName("cdi-context")

Your Java Class will look like this:

 package com.redhat.mycdidemo;

import org.apache.camel.builder.RouteBuilder;

@Startup
@ApplicationScoped
@ContextName("cdi-context")
public class MyCamelRouteBuilder extends RouteBuilder {

  @Override
  public void configure() throws Exception {
    from("timer:mytimer?period=5000")
    .log("Java DSL Camel Demo");
  }
}

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

Image title

Image title

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/

Image title

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

Image title

Start up application by clicking on the En/Disable button. 

Image title

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

Image title

Enterprise architecture planning Domain-Specific Language Web application Java (programming language) JBoss

Published at DZone with permission of Christina Lin, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Why "Polyglot Programming" or "Do It Yourself Programming Languages" or "Language Oriented Programming" sucks?
  • Deploy a Java application using Helm, Part 2
  • Deploy a Java application using Helm, Part 1
  • How to Automatically Detect Multiple Cybersecurity Threats from an Input Text String in Java

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: