【发布时间】:2018-06-05 11:52:35
【问题描述】:
我正在尝试使用 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/hello 和http://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");
单条OK,多条失败。
我该如何解决这个问题? (顺便说一句:第一种语法更受欢迎,因为端口、tls-setup、scheme、base-path 等一些常见参数都保存在一个地方。真实的东西确实有更多的路由,而不仅仅是两个。)
(我在玩写这个问题的最小示例时注意到的另一句话:问题似乎是特定于 undertow。码头组件按预期工作。)
【问题讨论】:
标签: apache-camel