我正在为http请求编写通用路由。端点不是静态值。路由代码:
from("direct:processRequests")
.split(body().method("getItems"), new GroupedBodyAggregationStrategy())
.parallelProcessing()
.to("direct:processRequest")
.end();
from("direct:processRequest")
.when(body().method("getHttpDetails").method("getCallType").isEqualTo("GET"))
.setProperty("type",body().method("getInterfaceId"))//to identity response later
.setHeader(Exchange.HTTP_METHOD, body().method("getHttpDetails").method("getCallType"))
.setHeader(Exchange.CONTENT_TYPE, body().method("getHttpDetails").method("getPayLoadType"))
.setHeader("Accept", body().method("getHttpDetails").method("getPayLoadType"))
.to(body().method("getEndPointUri").toString())
这里我试图从body获取端点。但是到目前为止它失败了,例外:
Caused by: org.apache.camel.NoSuchEndpointException: No endpoint could be found for: ognl(simple{${body}}, getEndPointUri), please check your classpath contains the needed Camel component jar.
at org.apache.camel.util.CamelContextHelper.getMandatoryEndpoint(CamelContextHelper.java:81)
at org.apache.camel.model.RouteDefinition.resolveEndpoint(RouteDefinition.java:211)
at org.apache.camel.impl.DefaultRouteContext.resolveEndpoint(DefaultRouteContext.java:107)
at org.apache.camel.impl.DefaultRouteContext.resolveEndpoint(DefaultRouteContext.java:113)
at org.apache.camel.model.SendDefinition.resolveEndpoint(SendDefinition.java:62)
at org.apache.camel.model.SendDefinition.createProcessor(SendDefinition.java:56)
at org.apache.camel.model.ProcessorDefinition.createProcessor(ProcessorDefinition.java:483)
at org.apache.camel.model.ProcessorDefinition.createOutputsProcessorImpl(ProcessorDefinition.java:446)
at org.apache.camel.model.ProcessorDefinition.createOutputsProcessor(ProcessorDefinition.java:413)
at org.apache.camel.model.ProcessorDefinition.createOutputsProcessor(ProcessorDefinition.java:165)
at org.apache.camel.model.ExpressionNode.createFilterProcessor(ExpressionNode.java:109)
at org.apache.camel.model.WhenDefinition.createProcessor(WhenDefinition.java:74)
at org.apache.camel.model.WhenDefinition.createProcessor(WhenDefinition.java:32)
at org.apache.camel.model.ProcessorDefinition.createProcessor(ProcessorDefinition.java:483)
at org.apache.camel.model.ChoiceDefinition.createProcessor(ChoiceDefinition.java:135)
at org.apache.camel.model.ProcessorDefinition.makeProcessorImpl(ProcessorDefinition.java:534)
at org.apache.camel.model.ProcessorDefinition.makeProcessor(ProcessorDefinition.java:495)
at org.apache.camel.model.ProcessorDefinition.addRoutes(ProcessorDefinition.java:219)
at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:1069)
... 23 more
我知道我们可以使用toD()来获取动态端点。但是为此我们需要端点的某些部分存在于toD()中。这里我试图动态加载整个端点。它有什么方法吗?< / p>
提前致谢。
答案 0 :(得分:0)
configure
类中的RouteBuilder
方法仅在启动期间调用一次来设置路由。
因此,如果你想要任何动态uri,那么就像常见问题解答所说的那样使用toD http://camel.apache.org/how-to-use-a-dynamic-uri-in-to.html