1

I'm new to apache-camel and I'm just trying to get a feel for what it can and can't do. I'd like to use the http4 component to dynamically provide url parameters. For example, if I have something like this:

from("direct:start").to("http4://hostname.com/the/path")
.unmarshal().json(JsonLibrary.Jackson,MyBeanClass.class)
.to("mock:result");

And then I have a producer template like this:

ProducerTemplate template = camelContext.createProducerTemplate();
Map<String,String> m = new HashMap<String,String>();
m.put("key1","val1");
m.put("key2", "val2");
template.sendBody("direct:start", m);

I'm hoping there's some way to magically convert the map to url parameters, so that the actual url that gets sent is "http://hostname.com/the/path?key1=val1&key2=val2".

Is this sort of thing possible? The documentation doesn't mention anything like this, but I don't really see how a component that can only call static urls is very useful. Thanks for any insight.

1 Answer 1

4

Found the answer:

the route can do this:

from("direct:start")
.setHeader(Exchange.HTTP_QUERY, simple("key1=${in.headers.key1}&key2=${in.headers.key2}"))
.to("http4://host.com/the/path")

And then the producer template can do this:

Map<String,Object> m = new HashMap<String,Object>();
m.put("key1", "1");
m.put("key2", "2");
template.sendBodyAndHeaders("direct:start", null, m);
Sign up to request clarification or add additional context in comments.

1 Comment

hey @kevin. Lets say i have exposed a service in from() and i want to add parameters from the from url and some extra parameters. If i add those extra params, in the query will my camel proxy route work?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.