Camel REST-DSL 与 HTTPS 和 Undertow 组件结合使用



我试图使用undertow组件为一些骆驼路线设置https。当前的骆驼版本是 2.19.4。代码来自一个最小示例:

非https设置如下所示:

// setup    
restConfiguration()
.component("undertow")
.port(8888)
.contextPath("/api");
// routes
rest("/hello")
.get()
.to("direct:hello");
from("direct:hello")
.setBody(constant("Hello"));
rest("/world")
.get()
.to("direct:world");
from("direct:world")
.setBody(constant("World"));

到目前为止,这工作正常,我可以访问http://localhost:8888/api/hellohttp://localhost:8888/api/world很好。

现在,我配置了自己的密钥库,创建了一个SSLContextParameters对象,并将设置部分更改为:

UndertowComponent undertow = (UndertowComponent) getContext().getComponent("undertow");
undertow.setSslContextParameters(getSslConfig());
restConfiguration()
.component("undertow")
.port(8888)
.scheme("https")
.contextPath("/api");

路线与以前相同。现在,Camel无法启动服务器,并出现以下错误:

[main] INFO org.apache.camel.impl.DefaultCamelContext - Route: route1 started and consuming from: https://0.0.0.0:8888/api/hello?httpMethodRestrict=GET
[main] INFO org.apache.camel.component.undertow.DefaultUndertowHost - Starting Undertow server on https://0.0.0.0:8888
[main] WARN org.apache.camel.component.undertow.DefaultUndertowHost - Failed to start Undertow server on https://0.0.0.0:8888, reason: java.net.BindException: Address already in use: bind
[main] INFO org.apache.camel.impl.DefaultCamelContext - Apache Camel 2.19.4 (CamelContext: camel-1) is shutting down
[main] INFO org.apache.camel.impl.DefaultShutdownStrategy - Starting to graceful shutdown 15 routes (timeout 300 seconds)
[Camel (camel-1) thread #18 - ShutdownTask] INFO org.apache.camel.component.undertow.DefaultUndertowHost - Stopping Undertow server on https://0.0.0.0:8888
[Camel (camel-1) thread #18 - ShutdownTask] INFO org.apache.camel.impl.DefaultShutdownStrategy - Route: route1 shutdown complete, was consuming from: rest://get:/hello?componentName=undertow&routeId=route1

但是,如果我删除一个终结点,以便只剩下一个路由,则一切正常。显然:仅适用于那条路线。

如果我使用替代语法,也会发生同样的情况:

from("undertow:https://0.0.0.0:8888/api/hello?method=GET").to("direct:hello");
from("undertow:https://0.0.0.0:8888/api/world?method=GET").to("direct:world");

单个路由正常,多个路由失败。

我该如何解决这个问题?(顺便说一句:第一个语法是更可取的,因为一些常见的参数,如端口,TLS设置,方案,基本路径保存在一个地方。真实的东西确实有更多的路线,而不仅仅是两条。

(我在玩弄写这个问题的最小示例时注意到的另一句话:这个问题似乎是特定于暗流的。码头组件按预期工作。

在端口中设置零,但您必须检查日志以查看分配的端口号。

最新更新