0
votes

I'm new to camel and in my opinion the documentation is large but could be structured better. So it's hard to find what you are looking for.

My problem: I've defined a camel route in spring DSL for redirection from the camel servlet to another http endpoint. On redirecting, some http query parameter like PARAM1 should be set:

<route id="bridge">
    <from uri="servlet:bridge" />
    <setHeader headerName="HTTP_QUERY">
        <constant>PARAM1=value1</constant>
    </setHeader>
    <to uri="http://127.0.0.1:8081/actions.do?bridgeEndpoint=true" />
</route>

The redirection works, but the "TO" endpoint doesn't gets the parameter PARAM1. Where is my mistake?

regards jundl

3

3 Answers

2
votes

To send query parameters to an http end point you can use HTTP_QUERY header as below

   <route>
    <from uri="servlet:bridge" />
    <setHeader headerName="HTTP_QUERY">
     <constant>param1=value1&param2=value2</constant>        
    </setHeader>
    <to uri="http://127.0.0.1:8081/actions.do?bridgeEndpoint=true" />
   </route>

and if you want some dynamic values like a header value as value1 you must use camel simple tag as below

  <route>
    <from uri="servlet:bridge" />
    <setHeader headerName="HTTP_QUERY">
     <simple>param1=${headerNameOfValue1}&param2=value2</simple>        
    </setHeader>
    <to uri="http://127.0.0.1:8081/actions.do?bridgeEndpoint=true" />
   </route>

Hope it helps!

1
votes

try this http://camel.apache.org/constant.html

<route>
   <from uri="servlet:bridge" />
  <setHeader headerName="PARAM1">
    <constant>value1</constant>        
  </setHeader>
  <to uri="http://127.0.0.1:8081/actions.do?bridgeEndpoint=true" />
</route>
1
votes

You are using a wrong headerName. If you want to use in a DSL route the Exchange.HTTP_QUERY constant, you need to write its value. That is, instead of write "HTTP_QUERY", you have to write "CamelHttpQuery". Take a look to https://camel.apache.org/maven/current/camel-core/apidocs/constant-values.html.

If you change your code in this way, it will work:

<route id="bridge">
    <from uri="servlet:bridge" />
    <setHeader headerName="CamelHttpQuery">
        <constant>PARAM1=value1</constant>
    </setHeader>
    <to uri="http://127.0.0.1:8081/actions.do?bridgeEndpoint=true" />
</route>