如何配置Camel将所有URL查询参数通过bean方法传递给Map?
给出此示例代码
@ContextName("camelBean")
public class CamelTestRoute extends RouteBuilder {
@Override
public void configure() throws Exception {
rest("/foo").description("Test api")
.consumes("application/json").produces("application/json")
.get("/stuff").description("get stuff")
.param().name("key").type(RestParamType.query).description("The key parameter").dataType("string").endParam()
.responseMessage().code(200).message("The stuff").endResponseMessage()
.to("bean:camelBean?method=getStuff")
;
}
}
@Named("camelBean")
public class CamelServiceBean {
public String getStuff(Map<String, String> args) {
return String.valueOf(args);
}
}
我访问<camelurl>/foo/stuff?key=asdasd
时,希望通过包含getStuff
的地图来调用'key' => 'asdasd'
。
答案 0 :(得分:0)
您可以使用@Headers注释地图
http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/Headers.html
public String getStuff(@Headers Map<String, Object> args) {
return String.valueOf(args);
}
args将以this map结尾。