Skip to main content
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 Red Hat 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

    • Red Hat OpenShift AI
    • 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.

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

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

ConsoleDocsSupport Search
New For you

Resources to explore

Check out popular resources, tools, and information from Red Hat. We'll recommend more as you browse.

  • Product downloads
  • Cheat sheets
  • Red Hat Developer learning portal
  • Developer blog
  • E-books
  • Developer Sandbox
Log in

Get more with a Red Hat Developer account

  • Product downloads
  • Console access
  • Event registration
  • Training & trials
Explore more account benefitsLog in or register

A subscription may be required for some services.

Contact us

The Camel Rest DSL

February 2, 2017
Mary Cochran
Related topics:
Developer tools
Related products:
Red Hat Fuse

    Camel

    Apache Camel is a piece of JBoss Fuse.  It is an open source integration framework with a variety of components to fit your integration needs.  Camel is a Java-based implementation of the Enterprise Integration Patterns based on a book by Gregor Hohpe and Bobby Woolf.  Camel includes components for HTTP, Files, FTP, JMS, JDBC, AWS, and much more.  While Camel can be used for many different purposes, this post will focus on the REST DSL specifically.

    Rest DSL Overview

    Apache Camel provides a quick and easy way to get REST endpoints up and running without a dependency on CXF by using the Rest DSL.  Red Hat support for the Rest DSL came with the release of JBoss Fuse 6.2. Before Camel 2.15, most Rest implementation was done using the CXFRS Camel component.  While the CXFRS component did its job, many found it complex and confusing.  It required more files to be maintained than the new Rest DSL and made the application dependent on CXF.  The following Camel components support the use of the Rest DSL:

    • camel-coap
    • camel-netty-http
    • camel-netty4-http
    • camel-jetty
    • camel-restlet
    • camel-servlet
    • camel-spark-rest
    • camel-undertow

    Rest DSL Syntax

    As with any Camel route, if using the Java DSL, the class must extend the RouteBuilder class and implement a configure() method to form the route definition. One must specify which Camel component the route should use in the restConfiguration() call.  In this configuration, the servlet component is being used.  The binding mode is set to enforce the use of json.  You can leave it as auto so that the rest endpoint can process json, xml, or something else.  Next, the endpoint can be defined.  The root URL will be defined in using syntax like rest ("/user").  Then you can specify what type of call can be made to the endpoint: GET, PUT, POST, or DELETE. What the endpoint produces and consumes may also be defined in addition to defining what type of object the endpoint is expecting to be produced or consumed.  From there, the route is defined the same as any other Camel route.

     @Override
     public void configure() throws Exception {
         restConfiguration().component("servlet").bindingMode(RestBindingMode.json);
    
         rest("/user")
             .get("/{id}").produces("application/json").to("direct:getUser")
             .post().consumes("application/json").type(User.class).to("direct:createUser")
             .delete("/{id}").to("direct:deleteUser");
    
         from("direct:getUser")
             .log("GET /user/${header.id} request received!")
             .setBody(simple("${header.id}"))
             .to("bean:usersBean?method=getUser");
    
         from("direct:createUser")
             .log("POST /user/ request received!")
             .to("bean:usersBean?method=createUser");
    
         from("direct:deleteUser")
             .log("DELETE /user/${header.id} request received!")
             .setBody(simple("${header.id}"))
             .to("bean:usersBean?method=deleteUser");
     }
    
    

    Rest DSL on JBoss EAP

    In order to get your Rest DSL Camel route running properly on EAP using CDI, you will need to add a servlet to the web.xml.  Please note the camel-servlet is the only supported way of using the Rest DSL with CDI on JBoss EAP at the current time.  If you want to use the Rest DSL with Spring on EAP I would suggest packing the Camel jars in your war.  If you choose to use CDI, the only edits needed are to the web.xml and then an additional annotation on your route class.

    web.xml

    <?xml version="1.0" encoding="ISO-8859-1"?>
    <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    
       <listener>
          <listener-class>org.jboss.weld.environment.servlet.Listener</listener-class>
       </listener>
    
       <!-- Camel Servlet -->
       <servlet>
          <servlet-name>CamelServlet</servlet-name>
          <servlet-class>org.apache.camel.component.servlet.CamelHttpTransportServlet</servlet-class>
          <load-on-startup>1</load-on-startup>
       </servlet>
    
       <!-- Camel Servlet Mapping -->
       <servlet-mapping>
          <servlet-name>CamelServlet</servlet-name>
          <url-pattern>/rest/*</url-pattern>
       </servlet-mapping>
    </web-app>

    route class

    @ContextName("rest-dsl")
    public class RestRoutes extends RouteBuilder {}

    Rest DSL on JBoss Fuse Karaf

    In order to get your Rest DSL route running on Karaf, you will need to have a camel-context.xml file.  Aside from this file, you will need to have proper import-packages and export-packages configured for your bundle.  This is a standard OSGi configuration.  See the JBoss Fuse documentation for more information on import and export packages.

    camel-context.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0"
     xmlns:jaxws="http://cxf.apache.org/blueprint/jaxws" xmlns:camel="http://camel.apache.org/schema/blueprint"
     xsi:schemaLocation="
     http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
     http://cxf.apache.org/blueprint/jaxws http://cxf.apache.org/schemas/blueprint/jaxws.xsd
     http://cxf.apache.org/blueprint/core http://cxf.apache.org/schemas/blueprint/core.xsd
     ">
    
       <!-- The camel context which registers the route -->
       <camel:camelContext id="fusequickstart-restdsl-camel" xmlns="http://camel.apache.org/schema/blueprint">
          <!-- Package Scanning finds the Routes -->
          <packageScan>
             <package>com.redhat.consulting.fusequickstarts.karaf.rest.dsl.route</package>
          </packageScan>
       </camel:camelContext>
    
    </blueprint>

    These examples and more can found in full at https://github.com/rhtconsulting/fuse-quickstarts.

    Last updated: February 23, 2024

    Recent Posts

    • Securing multimodal AI with NeMo Guardrails and vision models

    • Scaling multicluster GitOps with argocd-agent and Red Hat Advanced Cluster Management for Kubernetes

    • JBoss EAP 8.2 Beta: Java SE 25 and automated provisioning

    • Chasing CVEs: Lessons from a real container build using Red Hat Hardened Images

    • Draining 10K VMs with Dirty Memory at 100-Node Scale

    Red Hat Developers logo

    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
    Ask AI