I've got camel (2.16.4) routes described in Spring DSL like this
...
<from uri="restlet:http://localhost:8081/service_url?restletMethod=get"/>
<to uri="velocity:{{templates.uri}}/stub-answer.vm{{velocity.opts}}"/>
...
Typical request is like http://localhost:8081/service_url?param1=123¶m2=hello
I want to obtain the value of request's query parameter with name param2 from rest endpoint to velocity endpoint (file stub-answer.vm)
According to docs, Camel should pass every parameter from request in message headers, i.e. ${headers.param2}
. It works fine with path parameters (/service_url/{param3}
) but doesn't work with query parameters.
I found out that all query parameters are passed as a string into CamelHttpQuery header. And I've managed to extract it inside .vm file with help of Velocity language, like this
#set($splittedParams = $headers.CamelHttpQuery.split("\/"))
#set($splittedParamsSize = $splittedParams.size())
#set($param2Index = $splittedParamsSize - 1)
#set($param2 = $splittedParams[$param2Index])
But it's a ducktape and I believe there is more straight-forvard way to get request parameter by name (maybe with some route config in xml).
TIA.