Apache Camel: Query Params vs Header Params

Chris picture Chris · Apr 18, 2013 · Viewed 11.8k times · Source

I'm currently trying out Apache camel (as routing engine). I understand that Camel supports multiple DSLs and that it could be configured using Java (Java DSL) or Spring (Spring DSL).

Question:
I have the following Spring DSL configuration. The idea is that if the incoming request has header-param called "name", it would hit when clause or else to would route the request to google:

 <camel:route>
    <camel:from uri="servlet:///test" />
    <camel:choice>
        <camel:when>
            <camel:header>name</camel:header>
            <camel:transform>
                <camel:simple>Hello ${header.name} how are you?</camel:simple>
            </camel:transform>
        </camel:when>
        <camel:otherwise>
                <camel:to uri="http://www.google.com?bridgeEndpoint=true" />
        </camel:otherwise>
    </camel:choice>
</camel:route>

I expected the above config to work only for Header Param. However, I noticed that this configuration is working even for Query params as shown in the following request:

http://localhost:8080/<war-context>/test?name=test

Is there a way to make sure that it is made to work only for header params ?

Answer

Petter Nordlander picture Petter Nordlander · Apr 18, 2013

It's well documented here that query params are copied to exchange headers in the servlet component.