Reputation: 3234
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?
Upvotes: 7
Views: 33836
Reputation: 51
You can use toD. For example:
from("direct:mycode")
.toD("https://myurl?param1=${header.param1}");
Upvotes: 2
Reputation: 48
Another way to solve is use toD component ( SendDynamicProcessor) and internally invoke URL using http4 component.
Use camel-http4 2.X.X. & from Camel 3.X http4 is merged to http.
I'm sharing a way you can generalize and control few things.
You can this route to invoke different endpoints with few config values (headers, body, GET/POST, query params etc).
<!-- param will be List or Array of String key=value and make toString to create query of format key1=value1&key2=value2 -->
<route id="httpInvoker">
<from uri="direct:httpInvoker"/>
<setHeader headerName="CamelHttpQuery"><simple>ref:param_bean<simple></setHeader>
<setHeader headerName="CamelHttpUri"><simple>ref:uri_bean<simple></setHeader>
<toD uri="http4:\\some-example.com">
<route>
Upvotes: 0
Reputation: 29349
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")
Upvotes: 8