【问题标题】:How to resolve the HTTP:503 service unavailable error, using jetty drivers with java11?如何解决 HTTP:503 服务不可用错误,使用 java11 的码头驱动程序?
【发布时间】:2020-03-06 19:09:29
【问题描述】:

我需要使用 java 11 的码头驱动程序启动本地服务器。 我可以启动服务器并使用 Java8 访问它,但是使用 java 11 当我使用 curl 命令检查服务器是否可访问时,它会返回以下内容:

$ curl http://localhost:8080//sample/site/URL/info
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<title>Error 503 Service Unavailable</title>
</head>
<body><h2>HTTP ERROR 503</h2>
<p>Problem accessing /sample/site/URL/info. Reason:
<pre>    Service Unavailable</pre></p><hr><a href="http://eclipse.org/jetty">Powered by Jetty:// 9.4.20.v20190813</a><hr/>

</body>
</html>

堆栈跟踪

java.io.IOException: Server returned HTTP response code: 503 for URL: http://localhost:8080/idp/idpservice/register
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1894) ~[na:1.8.0_192]
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1492) ~[na:1.8.0_192]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_192]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_192]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_192]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_192]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) [javax.servlet-api-3.1.0.jar!/:na]
    at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:808) [jetty-servlet-9.2.9.v20150224.jar!/:na]
    at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:587) [jetty-servlet-9.2.9.v20150224.jar!/:na]
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143) [jetty-server-9.2.9.v20150224.jar!/:na]
    at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:577) [jetty-security-9.2.9.v20150224.jar!/:na]
    at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:223) [jetty-server-9.2.9.v20150224.jar!/:na]
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1127) [jetty-server-9.2.9.v20150224.jar!/:na]
    at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515) [jetty-servlet-9.2.9.v20150224.jar!/:na]
    at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185) [jetty-server-9.2.9.v20150224.jar!/:na]
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1061) [jetty-server-9.2.9.v20150224.jar!/:na]
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141) [jetty-server-9.2.9.v20150224.jar!/:na]
    at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:215) [jetty-server-9.2.9.v20150224.jar!/:na]
    at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:110) [jetty-server-9.2.9.v20150224.jar!/:na]
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97) [jetty-server-9.2.9.v20150224.jar!/:na]
    at org.eclipse.jetty.server.handler.StatisticsHandler.handle(StatisticsHandler.java:159) [jetty-server-9.2.9.v20150224.jar!/:na]
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97) [jetty-server-9.2.9.v20150224.jar!/:na]
    at org.eclipse.jetty.server.Server.handle(Server.java:497) [jetty-server-9.2.9.v20150224.jar!/:na]
    at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:310) [jetty-server-9.2.9.v20150224.jar!/:na]
    at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:257) [jetty-server-9.2.9.v20150224.jar!/:na]
    at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:540) [jetty-io-9.2.9.v20150224.jar!/:na]
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635) [jetty-util-9.2.9.v20150224.jar!/:na]
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555) [jetty-util-9.2.9.v20150224.jar!/:na]
    at java.lang.Thread.run(Thread.java:748) [na:1.8.0_192]

如您所见,我使用的是 Jetty 9.4.20.v20190813 版本的 jar。 知道除了码头我还应该研究哪些其他事情吗?

【问题讨论】:

  • 使用正确的 URL。 http://localhost:8080/sample/site/URL/info(修复双重//
  • 我们需要更多信息。服务器启动日志也许? 503 通常暗示有东西存在,但没有开始。 Jetty 9.4.x 适用于从 8.0 到 Java 14 的所有 Java 版本。每个提交甚至都在 Java 8、Java 11 和 Java 13 上构建和测试。
  • 从我的日志中添加了堆栈跟踪

标签: jetty java-11 maven-jetty-plugin


【解决方案1】:

码头版

如您所见,我正在使用 Jetty 9.4.20.v20190813 版本的 jar。知道除了码头我还应该研究哪些其他事情吗?

实际上,您的堆栈跟踪另有说明...

... .run(QueuedThreadPool.java:555) [jetty-util-9.2.9.v20150224.jar!/:na]

Jetty 9.2.x 是 EOL(生命终结)。

见:https://www.eclipse.org/jetty/documentation/current/what-jetty-version.html

直到 Jetty 9.4.8 才支持 Java 11

503 根据您的 Stacktrace 原因

堆栈跟踪中的状态码 503 来自 HttpURLConnection,而不是 Jetty。

java.io.IOException: Server returned HTTP response code: 503 for URL: http://localhost:8080/idp/idpservice/register
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1894) ~[na:1.8.0_192]
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1492) ~[na:1.8.0_192]

网址不匹配

您的堆栈跟踪和原始问题使用不同的 URL。

原来的问题

http://localhost:8080//sample/site/URL/info

堆栈跟踪

http://localhost:8080/idp/idpservice/register

Jetty 如何响应 503

只有少数几个地方 Jetty 本身会响应状态码 503(服务不可用)。 (所有其他状态码 503 响应来自应用程序及其自己的库,而不是 Jetty)

  1. 部署失败 - 如果您的 webapp 部署失败,它将在服务器端、服务器启动期间或 webapp 部署期间生成日志,说明部署失败的原因。这些失败的 web 应用程序将由 503 响应。
  2. 服务器正常关闭 - 当服务器被告知关闭时,所有在启动正常关闭和服务器实际关闭之间的狭窄时间窗口内到达的请求都会以 503 响应。
  3. DoSFilter - 如果使用拒绝服务防护过滤器,超过配置的 MaxRequestsMs 的请求将使用状态码 503 进行响应。
  4. 扩展 org.eclipse.jetty.servlets.DataRateLimitedServlet 的应用程序 servlet 将以状态码 503 响应目录请求(以 / 结尾的请求)。(Jetty 本身中没有 servlet 或过滤器使用此 Servlet)
  5. 如果您的应用程序在处理请求期间抛出javax.servlet.UnavailableException

这就是 Jetty 本身的所有 503 起源。

503 的最常见原因是错误的 webapp 部署,只有来自服务器端的日志(在 webapp 部署期间)才能帮助发现此状态及其原因。

【讨论】:

  • 现在我更深入地查看了日志。我看到服务器没有正确启动。我看到以下错误,关于文件之一,Could not resolve placeholder 'tss.data' in string value "file:${tss.data}/idp/resources/conf/internal.xml" 知道导致此错误的原因吗?
  • 知道了。该项目试图在加载值之前访问 tss.data 的值。但是我仍然面临同样的 HTTP:503 错误问题。
  • 在将代码从 java 8 迁移到 java 11 平台时,我已经使用 java 11 兼容版本更新了所有包。
猜你喜欢
  • 1970-01-01
  • 2019-12-08
  • 1970-01-01
  • 2021-06-16
  • 1970-01-01
  • 1970-01-01
  • 2012-08-17
  • 2017-03-26
相关资源
最近更新 更多