开发者

camel route, http4 component, dynamic url parameters

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 ho开发者_Python百科w a component that can only call static urls is very useful. Thanks for any insight.


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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜