検索

Chapter 2. Building Your Application on JBoss EAP

download PDF

2.1. Overview

The following example demonstrates the use of camel-cdi component with Red Hat Fuse on EAP to integrate CDI beans with Camel routes.

In this example, a Camel route takes a message payload from a servlet HTTP GET request and passes it on to a direct endpoint. It then passes the payload onto a Camel CDI bean invocation to produce a message response and displays the output on the web browser page.

2.2. Running the Project

Before running the project, ensure that your set up includes maven and the application server with Red Hat Fuse. Perform the following steps to run your project:

  1. Start the application server in standalone mode:

    • For Linux: ${JBOSS_HOME}/bin/standalone.sh -c standalone-full.xml
    • For Windows: %JBOSS_HOME%\bin\standalone.bat -c standalone-full.xml
  2. Build and deploy the project: mvn install -Pdeploy
  3. Now, browse to http://localhost:8080/example-camel-cdi/?name=World location. The following message Hello World from 127.0.0.1 appears as an output on the web page. Also, you can view the Camel Route under the MyRouteBuilder.java class as:
from("direct:start").bean("helloBean");

The bean DSL makes Camel look for a bean named helloBean in the bean registry. Also, the bean is available to Camel due to the SomeBean class. By using the @Named annotation, the camel-cdi adds the bean to the Camel bean registry.

@Named("helloBean")

public class SomeBean {

     public String someMethod(String name) throws Exception {

        return String.format("Hello %s from %s", name, InetAddress.getLocalHost().getHostAddress());

    }

}

For more information, see $ EAP_HOME/quickstarts/camel/camel-cdi directory.

2.3. BOM file for JBoss EAP

The purpose of a Maven Bill of Materials (BOM) file is to provide a curated set of Maven dependency versions that work well together, saving you from having to define versions individually for every Maven artifact.

The Fuse BOM for JBoss EAP offers the following advantages:

  • Defines versions for Maven dependencies, so that you do not need to specify the version when you add a dependency to your POM.
  • Defines a set of curated dependencies that are fully tested and supported for a specific version of Fuse.
  • Simplifies upgrades of Fuse.
Important

Only the set of dependencies defined by a Fuse BOM are supported by Red Hat.

To incorporate a BOM file into your Maven project, specify a dependencyManagement element in your project’s pom.xml file (or, possibly, in a parent POM file), as shown in the following example:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project ...>
  ...
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

    <!-- configure the versions you want to use here -->
    <fuse.version>7.4.0.fuse-740036-redhat-00002</fuse.version>

  </properties>

  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.jboss.redhat-fuse</groupId>
        <artifactId>fuse-eap-bom</artifactId>
        <version>${fuse.version}</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>
  ...
</project>

After specifying the BOM using the dependency management mechanism, it becomes possible to add Maven dependencies to your POM without specifying the version of the artifact. For example, to add a dependency for the camel-velocity component, you would add the following XML fragment to the dependencies element in your POM:

<dependency>
  <groupId>org.apache.camel</groupId>
  <artifactId>camel-velocity</artifactId>
  <scope>provided</scope>
</dependency>

Note how the version element is omitted from this dependency definition.

Red Hat logoGithubRedditYoutubeTwitter

詳細情報

試用、購入および販売

コミュニティー

Red Hat ドキュメントについて

Red Hat をお使いのお客様が、信頼できるコンテンツが含まれている製品やサービスを活用することで、イノベーションを行い、目標を達成できるようにします。

多様性を受け入れるオープンソースの強化

Red Hat では、コード、ドキュメント、Web プロパティーにおける配慮に欠ける用語の置き換えに取り組んでいます。このような変更は、段階的に実施される予定です。詳細情報: Red Hat ブログ.

会社概要

Red Hat は、企業がコアとなるデータセンターからネットワークエッジに至るまで、各種プラットフォームや環境全体で作業を簡素化できるように、強化されたソリューションを提供しています。

© 2024 Red Hat, Inc.