骆驼航线,http4组件,动态网址参数 [英] camel route, http4 component, dynamic url parameters
问题描述
我是新来的Apache的骆驼,我只是想获得它所能做和不能做的感觉。我想用http4组件动态提供URL参数。举例来说,如果我有这样的事情:
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);
我希望有一些方法来转换成神奇的地图URL参数,使该被发送实际的URL是http://hostname.com/the/path?key1=val1&key2=val2。
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".
是这样的事情可能吗?文档没有提到这样的事,但我实在不明白,只能调用静态URL的组件如何是非常有用的。感谢您的任何见解。
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.
推荐答案
找到了答案:
路由可以做到这一点:
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);
这篇关于骆驼航线,http4组件,动态网址参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!