Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9063657
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T16:03:32+00:00 2026-06-16T16:03:32+00:00

This is the example that is bundled with apache camel binaries <route> <!– incoming

  • 0

This is the example that is bundled with apache camel binaries

 <route>
      <!-- incoming requests from the servlet is routed -->
      <from uri="servlet:///hello"/>
      <choice>
        <when>
          <!-- is there a header with the key name? -->
          <header>name</header>
          <!-- yes so return back a message to the user -->
          <transform>
            <simple>Hello ${header.name} how are you?</simple>
          </transform>
        </when>
        <otherwise>
          <!-- if no name parameter then output a syntax to the user -->
          <transform>
            <constant>Add a name parameter to uri, eg ?name=foo</constant>
          </transform>
        </otherwise>
      </choice>
    </route>

How to translate this to Java

Am a beginner in camel, and some how came up to this

CamelContext context = new DefaultCamelContext();

context.addRoutes(new RouteBuilder(){

 public void configure(){

 from("servlet://hello").transform().....
}
});

But dont know how to proceed further…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T16:03:33+00:00Added an answer on June 16, 2026 at 4:03 pm

    If you want to port it over to java without any XML (spring that is) you can’t (easily) use the servlet component.

    Just porting the route will be like:

    from("servlet:///hello")
          .choice()
            .when()
               .header("name")
                  .transform(simple("Hello ${header.name} how are you?"))
            .otherwise()
                .transform(constant("Add a name parameter to uri, eg ?name=foo"));
    

    It should work in the spring example (or any spring web app), just replacing the <route> in the <CamelContext> with <routeBuilder ref="demoRoute"> given you have defined your route as a spring bean (<bean id="demoRoute" class="org.example.demo.DemoRoute">).

    However, I guess you want to do this in plain java (no spring, no xml, no webapp). You could go with the Jetty component. The difference being that Camel then will start the servlet container, instead of the servlet container starting Camel. No difference for this simple example though.

    I suggest you start out with a Maven archetype to get the skeleton up

    e.g. mvn archetype:generate then choose org.apache.camel.archetypes:camel-archetype-java (Creates a new Camel project using Java DSL.)
    Well, you don’t need the maven archetype if you have your own java application and have the thread keep running. Then you should do fine with your approach. The maven archetype is however very good for training purposes.

    You then need to add a dependency to Jetty (camel-jetty.jar) (read more here).

    The actual route would be exactly the same except the first row: from("jetty:http://localhost:8080/camel/hello")

    Nice and easy.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is an example XML file that would come from the Android Client. <test>
So I'm having a bit of trouble understanding this example that was shown in
This is an example that searches PDF files in the current directory. import os,
I have this very simple example that I am using to learn structs in
I have this code (an example that PHP generates for me)... <select id=outsideBlue3> <option
can any body help me on separating this example of data that i need
Trying to follow this example. (Section String sorting...) Is there anything obvious that would
I am trying to reproduce a simple jquery slider example that works on this
Based on this SO post , and this example , I expect that, when
Still fighting with templates. In this example, despite the fact that is copied straight

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.