apache-camel: http query string parameter as headers?
20,965
Solution 1
Incoming http requests will be added as headers on the exchange with the same name as the query parameter.
Below example is from camel documentation
For example, given a client request with the URL, http://myserver/myserver?orderid=123, the exchange will contain a header named orderid with the value 123.
You can set the query parameters for other HTTP calls you make by setting by CamelHttpQuery
header. Exchange.HTTP_QUERY
is the static constant for string CamelHttpQuery
Eg:
from("jetty://0.0.0.0:8080/test")
.setHeader(Exchange.HTTP_QUERY, simple("?param1=${header.param1}")
.to("http://external-url/test")
Solution 2
You can use toD. For example:
from("direct:mycode")
.toD("https://myurl?param1=${header.param1}");
Author by
Jundl
Updated on May 06, 2021Comments
-
Jundl almost 3 years
I'm new to camel and prefer using Spring DSL for route definition. Now I find it's confusing, that http query string parameter are named and handled as headers, what they aren't. Is this an architectural bug in camel?
-
Jundl over 7 yearsdon't find it very elegant and it doesn't actually answers my question, but I'm glad that anybody answers and it works:)
-
Erik Pearson almost 6 yearsFor me, I had to use: simple("param1=${header.param1}", without the question mark.