Skip to main content
Redhat Developers  Logo
  • AI

    Get started with AI

    • Red Hat AI
      Accelerate the development and deployment of enterprise AI solutions.
    • AI learning hub
      Explore learning materials and tools, organized by task.
    • AI interactive demos
      Click through scenarios with Red Hat AI, including training LLMs and more.
    • AI/ML learning paths
      Expand your OpenShift AI knowledge using these learning resources.
    • AI quickstarts
      Focused AI use cases designed for fast deployment on Red Hat AI platforms.
    • No-cost AI training
      Foundational Red Hat AI training.

    Featured resources

    • OpenShift AI learning
    • Open source AI for developers
    • AI product application development
    • Open source-powered AI/ML for hybrid cloud
    • AI and Node.js cheat sheet

    Red Hat AI Factory with NVIDIA

    • Red Hat AI Factory with NVIDIA is a co-engineered, enterprise-grade AI solution for building, deploying, and managing AI at scale across hybrid cloud environments.
    • Explore the solution
  • Learn

    Self-guided

    • Documentation
      Find answers, get step-by-step guidance, and learn how to use Red Hat products.
    • Learning paths
      Explore curated walkthroughs for common development tasks.
    • Guided learning
      Receive custom learning paths powered by our AI assistant.
    • See all learning

    Hands-on

    • Developer Sandbox
      Spin up Red Hat's products and technologies without setup or configuration.
    • Interactive labs
      Learn by doing in these hands-on, browser-based experiences.
    • Interactive demos
      Click through product features in these guided tours.

    Browse by topic

    • AI/ML
    • Automation
    • Java
    • Kubernetes
    • Linux
    • See all topics

    Training & certifications

    • Courses and exams
    • Certifications
    • Skills assessments
    • Red Hat Academy
    • Learning subscription
    • Explore training
  • Build

    Get started

    • Red Hat build of Podman Desktop
      A downloadable, local development hub to experiment with our products and builds.
    • Developer Sandbox
      Spin up Red Hat's products and technologies without setup or configuration.

    Download products

    • Access product downloads to start building and testing right away.
    • Red Hat Enterprise Linux
    • Red Hat AI
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    Featured

    • Red Hat build of OpenJDK
    • Red Hat JBoss Enterprise Application Platform
    • Red Hat OpenShift Dev Spaces
    • Red Hat Developer Toolset

    References

    • E-books
    • Documentation
    • Cheat sheets
    • Architecture center
  • Community

    Get involved

    • Events
    • Live AI events
    • Red Hat Summit
    • Red Hat Accelerators
    • Community discussions

    Follow along

    • Articles & blogs
    • Developer newsletter
    • Videos
    • Github

    Get help

    • Customer service
    • Customer support
    • Regional contacts
    • Find a partner

    Join the Red Hat Developer program

    • Download Red Hat products and project builds, access support documentation, learning content, and more.
    • Explore the benefits

Getting Started with Global Beans in Fuse Tooling 10.0.0

August 23, 2017
Brian Fitzpatrick
Related topics:
Developer tools
Related products:
Developer ToolsetRed Hat Fuse

    Red Hat JBoss Fuse provides an open source, lightweight, modular platform that enables you to connect a variety of services and systems across your application environment. And, included with Red Hat JBoss Developer Studio, is the Fuse Tooling that helps you take advantage of that platform.

    The route editor initially focused on the parts of the Camel configuration inside the route or Camel context element, but in version 8.0.0, we began adding support for global elements such as data formats and endpoints on the Configurations tab. With the 10.0 release, we add support for beans that are outside the route.

    This tutorial shows how to create a customizable service that uses a global Java bean and Camel XML. By the end, you will have a simple Fuse integration project, which includes a Camel test that verifies the bean logic.

    The main steps in this tutorial are:

    1. Create a Fuse integration project.
    2. Create a bean in the project.
    3. Finish the bean class.
    4. Create a route.
    5. Create a test.
    6. Finish the generated test.

    Prerequisites: Eclipse Oxygen is required. During installation of Red Hat Developer Studio 11.0, you should have selected installation of JBoss Fuse Tooling.

    Step 1: Create a Project

    First, we have to create a project for where we can put our code.

    1. In the Developer Studio menu bar, click File->New->Fuse Integration Project.
    2. In the new project wizard, in the Project Name field, enter global-bean-tutorial.
    3. Accept all defaults to create a new, empty Fuse project.
    4. Click Finish.

    Fuse tooling will then build a new Blueprint Camel project, which can take a few moments.

    Step 2: Create our Global Bean

    Create a simple Java bean to use in the Camel route:

    1. In the route editor, click the Configurations tab and then click Add.
    2. In the “Create new global element...” dialog, click Bean and then click OK.
    3. In the “Add Bean” dialog, in the Id field, enter GreetingBean.
    4. To the right of the Class field, click the + button to create a new class.
    5. In the “New Java Class” wizard:
      1. In the Package field, enter org.example.
      2. In the Name field, enter Greeting.
      3. Click Finish.
    6. In the “Add Bean” dialog, click Finish.

    Step 3: Finish the Bean Class

    The previous step created a rough outline for the Java bean. To finish the bean class and make it do something, change the code to something like this:

    package org.example;
    
    import java.util.ArrayList;
    import java.util.List;
    
    public class Greeting {
    
       private List messageCache = new ArrayList<>();
       private String greetingText = "Hello";
    
       public Greeting() {
          // empty
       }
    
       public Greeting(String newGreeting) {
          greetingText = newGreeting;
       }
    
       public String hello(String msg) {
          String helloMsg = greetingText + " " + msg;
          messageCache.add(helloMsg);
          return helloMsg;
       }
    
       public String toString() {
          return messageCache.toString();
       }
    }

    This simple bean has one method, hello(String), that;

    1. Attaches a greeting string to the beginning of the method argument.
    2. Caches the modified string.
    3. Returns the modified string.

    The hello(String) method provides a way to customize the greeting in the constructor and to retrieve the cache. A Camel route can use these various points of entry into the bean code.

    Step 4: Create a Route

    Create a route that will use the bean:

    1. In the route editor, click the Design tab.
    2. In the Palette, under Components, click and drag Direct onto the Route_route1 container. This tutorial uses the Direct component to keep the example simple. You can, of course, use a File component, JMS component, or some other component.
    3. With the new “direct” component in the route selected:
      1. Open the Properties view.
      2. Click the Details tab.
      3. In the Uri field, change the value to direct:beanTutorial.
    4. In the Palette, under Components, click and drag the Bean component onto the direct component.
    5. With the Bean_bean1 component selected, in the Properties view:
      1. Select the Details tab.
      2. In the Ref field, display the dropdown list.
      3. Select the GreetingBean, which appears here because you previously added it as a global bean. This creates a reference to the global bean and inserts it into the route.
    6. In the Palette, drag another Direct component onto the Bean in the route.
    7. With the second “direct” component in the route selected, in the Properties view:
      • In the Uri field, change the value to direct:beanTutorialOut. This creates the final destination for the route.
    8. Save the route.

    Step 5: Create a Test

    In the project you created in step 1, create a test:

    1. In the Project Explorer view, in the src folder, create a new folder named test.
    2. In the test folder, create a new folder named java.
    3. In the Developer Studio menu bar, select File -> New -> Camel Test Case.
    4. In the New Camel JUnit Test Case wizard:
      1. Make sure the Source Folder path is global-bean-tutorial/src/test/java.
      2. In the Package field, enter org.example.
      3. To the right of the Camel XML file under test field, click Browse.
      4. Select the blueprint.xml file and click OK.
      5. In the Name field, enter GreetingTest.
      6. Click Finish.

    Step 6: Finish the Generated Test

    The Camel Test Case wizard generates a test class that extends CamelBlueprintTestSupport and provides some templated code. To finish the generated test, provide some sample input and output messages and then send them to the project’s Camel route.

    Change your class to resemble the following:

    package org.example;
    
    import org.apache.camel.EndpointInject;
    import org.apache.camel.Produce;
    import org.apache.camel.ProducerTemplate;
    import org.apache.camel.builder.RouteBuilder;
    import org.apache.camel.component.mock.MockEndpoint;
    import org.apache.camel.test.blueprint.CamelBlueprintTestSupport;
    import org.junit.Test;
    
    public class GreetingTest extends CamelBlueprintTestSupport {
    
      // Input message bodies to test with
      protected Object[] inputBodies = 
        { "This is one bean example.",
          "This is another bean example." };
    
      // Expected message bodies
      protected Object[] expectedBodies = 
        { "Hello This is one bean example.",
          "Hello This is another bean example."};
    
      // Templates to send to input endpoints
      @Produce(uri = "direct:beanTutorial")
      protected ProducerTemplate inputEndpoint;
    
      // Mock endpoints used to consume messages from the output 
      // endpoints and then perform assertions
      @EndpointInject(uri = "mock:output")
      protected MockEndpoint outputEndpoint;
    
      @Test
      public void testCamelRoute() throws Exception {
         // Create routes from the output endpoints to our mock 
         // endpoints so we can assert expectations
         context.addRoutes(new RouteBuilder() {
              @Override
              public void configure() throws Exception {
                   from("direct:beanTutorialOut").to(outputEndpoint);
              }
         });
    
         // Define some expectations
         outputEndpoint.expectedBodiesReceivedInAnyOrder(expectedBodies);
    
         // Send some messages to input endpoints
         for (Object inputBody : inputBodies) {
              inputEndpoint.sendBody(inputBody);
         }
    
         // Validate our expectations
         assertMockEndpointsSatisfied();
      }
    
      @Override
      protected String getBlueprintDescriptor() {
         return "OSGI-INF/blueprint/blueprint.xml";
      }
    }

    With these changes in place, in the Project Explorer view, right-click the GreetingTest class and select Run As -> JUnit Test. Your test should pass.

    The next route editor bean tutorial article in this series will show how to:

    • Update the route to be more specific about which bean method to call.
    • Customize the greeting by passing a constructor argument.
    • Update the test according to the route and bean updates.

    Click here to for an overview of Red Hat JBoss Fuse a lightweight and modular integration platform.

    Last updated: November 9, 2023

    Recent Posts

    • SQL Server HA on RHEL: Meet Pacemaker HA Agent v2 (tech preview)

    • Deploy with confidence: Continuous integration and continuous delivery for agentic AI

    • Every layer counts: Defense in depth for AI agents with Red Hat AI

    • Fun in the RUN instruction: Why container builds with distroless images can surprise you

    • Trusted software factory: Building trust in the agentic AI era

    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Platforms

    • Red Hat AI
    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    Build

    • Developer Sandbox
    • Developer tools
    • Interactive tutorials
    • API catalog

    Quicklinks

    • Learning resources
    • E-books
    • Cheat sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site status dashboard
    • Report a security problem

    RED HAT DEVELOPER

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit
    © 2026 Red Hat

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility

    Chat Support

    Please log in with your Red Hat account to access chat support.