由于某种原因,第二个和后续的查询参数只是null。第一个完美无缺。我正在使用Camel + JAX-RS(CXF)。这只是一个GET请求。我正在使用的网址是
http://localhost:8181/cxf/coreservices/search?q=health&start=100&size=924
这是我的界面声明
@Path( “搜索”) 公共接口SearchRestService {
@GET
@Produces(MediaType.APPLICATION_JSON)
public String searchGet(@QueryParam ("q") String q, @DefaultValue("0") @QueryParam("start") String start, @DefaultValue("10") @QueryParam("size") String size );
实施
public SearchResult<WikiSearchHit> searchGet(String q, String start, String size){
logger.info("Inside wiki GET method: " +q + " start:"+start + " size:"+ size);
q
参数正好health
,但start和size参数只是null。令人惊讶的是,默认值也没有被提升。
恐怕我在骆驼路线上做错了什么。
路由器
@Override
public void configure() throws Exception {
from("cxfrs://bean://rsServer?bindingStyle=SimpleConsumer")
.multicast()
.parallelProcessing()
.aggregationStrategy(new CoreSearchResponseAggregator())
.beanRef("searchRestServiceImpl", "searchGet")
...
感谢您的时间: - )
答案 0 :(得分:0)
Camel团队正在努力在不久的将来解决这个问题。在此之前使用以下解决方法。
您可以按如下方式获取整个查询字符串
String query = exchange.getIn()。getHeader(Exchange.HTTP_QUERY,String.class);
//会返回类似的内容:q = health&amp; start = 100&amp; size = 924
界面
@GET
@Path("search")
@Produces(MediaType.APPLICATION_JSON)
public String searchGet();
实施 - 目标方法
public SearchResult<WikiSearchHit> wikiGet(Exchange exchange){
String q = exchange.getIn().getHeader("q", String.class);
String size = exchange.getIn().getHeader("size", String.class);
String start = exchange.getIn().getHeader("start", String.class);
<强>路由器强>
public class RestToBeanRouter extends RouteBuilder {
@Override
public void configure() throws Exception {
from("cxfrs://bean://rsServer?bindingStyle=SimpleConsumer")
.process(new ParameterProcessor())
.removeHeaders("CamelHttp*")
.multicast()
.parallelProcessing()
.aggregationStrategy(new CoreSearchResponseAggregator())
.beanRef("searchRestServiceImpl", "wikiGet")
....
.end()
.marshal().json(JsonLibrary.Jackson);
//.to("log://camelLogger?level=TRACE");
}
class ParameterProcessor implements Processor {
@Override
public void process(Exchange exchange) throws Exception {
Map<String, String> stringStringMap = convertQueryStringAsMap(exchange.getIn().getHeader(Exchange.HTTP_QUERY, String.class));
//System.out.println("stringStringMap = " + stringStringMap);
for (Map.Entry<String, String> eachParamEntry : stringStringMap.entrySet()) {
exchange.getIn().setHeader(eachParamEntry.getKey(), eachParamEntry.getValue());
}
}
private Map<String,String> convertQueryStringAsMap(String queryString){
//some Guava magic
return Splitter.on("&").omitEmptyStrings().trimResults().withKeyValueSeparator("=").split(queryString);
}
}
}