[英]Undertow Simple HelloWorld not working on Cloud Foundry
我根据文档创建了一个简单的undertow HTTP服务器: http : //undertow.io/undertow-docs/undertow-docs-1.3.0/index.html
public static void main(final String[] args) {
Undertow server = Undertow.builder()
.addHttpListener(8080, "0.0.0.0")
.setHandler(new HttpHandler() {
@Override
public void handleRequest(final HttpServerExchange exchange) throws Exception {
exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "text/plain");
exchange.getResponseSender().send("Hello World");
}
}).build();
server.start();
}
它可以在本地主机上正常工作。 但是,当我作为独立的Java应用程序部署在Cloud Foundry上时:
cf push im-gateway -p target\gateway.jar
该应用无法启动,并在日志中显示此错误:
Instance (index 0) failed to start accepting connections
经过调查,我修改了push命令:
cf push im-gateway -p target\gateway.jar --no-route
这次部署成功,我手动创建了路由并尝试访问它,但收到错误消息:
502 Bad Gateway: Registered endpoint failed to handle the request.
我应该在哪个端口上监听? Cloud Foundry如何将请求重定向到我的应用程序?
感谢您的答复。
根据文档,Cloud Foundry为每个应用程序实例动态分配一个端口。
https://docs.cloudfoundry.org/devguide/deploy-apps/environment-variable.html#PORT
尝试将.addHttpListener(8080, "0.0.0.0")
替换为.addHttpListener(System.getenv("PORT"), "0.0.0.0")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.