我正在尝试使用ProducerTemplate#sendBody()发送POJO,但出现以下错误:
org.apache.camel.language.bean.RuntimeBeanExpressionException: Failed to invoke
method: [searchId] on app.FsiRequest due to:
java.lang.IndexOutOfBoundsException: Key: searchId not found in bean:
app.FsiRequest@5c2d65cf of type: app.FsiRequest using OGNL path [[searchId]]
at org.apache.camel.language.bean.BeanExpression.evaluate(BeanExpression.java:119) ~[camel-core-2.22.1.jar:2.22.1]
at org.apache.camel.language.bean.BeanExpression.evaluate(BeanExpression.java:135) ~[camel-core-2.22.1.jar:2.22.1]
at org.apache.camel.model.language.ExpressionDefinition.evaluate(ExpressionDefinition.java:127) ~[camel-core-2.22.1.jar:2.22.1]
at org.apache.camel.model.language.ExpressionDefinition.evaluate(ExpressionDefinition.java:119) ~[camel-core-2.22.1.jar:2.22.1]
at org.apache.camel.builder.ExpressionBuilder$40.evaluate(ExpressionBuilder.java:1004) ~[camel-core-2.22.1.jar:2.22.1]
at org.apache.camel.support.ExpressionAdapter.evaluate(ExpressionAdapter.java:36) ~[camel-core-2.22.1.jar:2.22.1]
at org.apache.camel.builder.SimpleBuilder.evaluate(SimpleBuilder.java:92) ~[camel-core-2.22.1.jar:2.22.1]
我要发送的课程(简体):
public class FsiRequest {
public String getSearchId() {
return searchId;
}
public void setSearchId(String searchId) {
this.searchId = searchId;
}
private String searchId;
public FsiRequest(Map<String, String> request) {
searchId = request.get("searchId");
}
}
这是我的调用:
private final ForkJoinPool routeExecutorPool = new ForkJoinPool(1024);
@Override
public void configure() {
from("servlet://" + SEARCH_REQUEST)
.process(exchange -> {
FsiRequest request = createRequestMap(exchange);
sendRequestToAllProviderRoutes(exchange, request);
})
.transform()
.constant("OK");
}
private void sendRequestToAllProviderRoutes(Exchange exchange, FsiRequest request) {
try {
ProducerTemplate tmpl = exchange.getContext().createProducerTemplate();
routeExecutorPool.execute(() -> getRoutes(exchange).parallelStream().forEach(
route -> tmpl.sendBody(route, request)
));
} catch (RejectedExecutionException | RuntimeCamelException e) {
log.error("FSI Servlet failed to send request to provider routes", e);
}
}
getRoutes()
通过过滤exchange.getContext().getRouteDefinitions()
获取相关路由。
sendBody()
代替FsiRequest类时, HashMap<String, Object>
可以很好地工作。
答案 0 :(得分:0)
此问题是由于我们方面的错误所致。接收路线有:
.setHeader(SEARCH_ID_KEY, simple("${body[searchId]}"))
切换到body.searchId
解决了该问题。