Undertow Simple HelloWorld 不适用于 Cloud Foundry
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
经过调查,我修改推送命令:
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(System.getenv("PORT"), "0.0.0.0")
替换 .addHttpListener(8080, "0.0.0.0")
我正在按照文档创建一个简单的 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
经过调查,我修改推送命令:
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(System.getenv("PORT"), "0.0.0.0")
.addHttpListener(8080, "0.0.0.0")