0

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&param2=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.

WeGa
  • 801
  • 4
  • 10
  • 24
  • I'm currently thinking of writing custom Processor and packing it into jar, then into OSGI bundle and use it inside camel route this way `` or ``... – WeGa May 18 '18 at 12:18
  • My attempt with Processor :) - https://stackoverflow.com/questions/50414055 – WeGa May 23 '18 at 08:22

0 Answers0