【问题标题】:Secure WebSocket/Jetty server (not embedded)/HTTPS: Service unavailable (503)安全 WebSocket/Jetty 服务器(未嵌入)/HTTPS:服务不可用 (503)
【发布时间】:2016-02-23 11:55:38
【问题描述】:

我有一个来自 Danny Cowards 的“Java WebSocket Programming book”的非常简单的 WebSocket 服务器,如下所示:

import javax.websocket.server.ServerEndpoint;
import javax.websocket.OnMessage;

@ServerEndpoint (value="/echo")
public class EchoServer
{
    @OnMessage
    public String echo (String incomingMessage)
    {
    return "I got this (" + incomingMessage + "), so I am sending it back!";
    }
}

我使用 gradle 2.7 编译它(见下面的build.gradle

apply plugin: 'java'
apply plugin: "war"

repositories {
    mavenCentral()
}

dependencies {
        compile 'javax.websocket:javax.websocket-api:1.1'
}

并将它放在普通(仅限 HTTP)Jetty 服务器 (jetty-distribution-9.3.6.v20151106) 的 webapps 目录中,我可以让它与访问 WebSocket 接口的客户端对话,如下所示:

            var wsUri = "ws://localhost:8080/echoserver/echo";

然后,我将相同的 *.war 文件放在安全的码头服务器上(运行 jetty-9.1.3.v20140225),但部署不起作用,我使用服务器访问(注意 @987654330 @ 现在)

            var wsUri = "wss://localhost:8443/echoserver/echo";

没有为错误工作。来自 chrome 上的 JavaScript 控制台的具体错误是 'WebSocket connection to 'wss://localhost:8443/echoserver/echo' failed: Error during WebSocket handshake: Unexpected Response code: 503'。但我认为这是因为发生了一个 RunTimeException 扫描 EchoServer.class (正如码头stderrout.log 所证明的那样):

2015-11-20 15:32:14.320:INFO:oejs.Server:main: jetty-9.1.3.v20140225
2015-11-20 15:32:14.329:INFO:oejs.AbstractNCSARequestLog:main: Opened /opt/jetty/logs/2015_11_20.request.log
2015-11-20 15:32:14.329:INFO:oejs.AbstractNCSARequestLog:main: Opened /opt/jetty/logs/2015_11_20.request.log
2015-11-20 15:32:14.331:INFO:oejdp.ScanningAppProvider:main: Deployment monitor [file:/opt/jetty/webapps/] at interval 1
2015-11-20 15:32:14.421:INFO:oeja.AnnotationConfiguration:main: Scanned 1 container path jars, 1 WEB-INF/lib jars, 1 WEB-INF/classes d
irs in 17ms for context o.e.j.w.WebAppContext@4c70fda8{/echoserver,file:/tmp/jetty-0.0.0.0-8443-echoserver.war-_echoserver-any-7817985
952118790015.dir/webapp/,STARTING}{/echoserver.war}
2015-11-20 15:32:14.421:WARN:oejw.WebAppContext:main: Failed startup of context o.e.j.w.WebAppContext@4c70fda8{/echoserver,file:/tmp/j
etty-0.0.0.0-8443-echoserver.war-_echoserver-any-7817985952118790015.dir/webapp/,STARTING}{/echoserver.war}
java.lang.RuntimeException: Error scanning file EchoServer.class
    at org.eclipse.jetty.annotations.AnnotationParser.parseDir(AnnotationParser.java:705)
    at org.eclipse.jetty.annotations.AnnotationParser.parseDir(AnnotationParser.java:686)
    at org.eclipse.jetty.annotations.AnnotationParser.parseDir(AnnotationParser.java:686)
    at org.eclipse.jetty.annotations.AnnotationParser.parseDir(AnnotationParser.java:686)
    at org.eclipse.jetty.annotations.AnnotationParser.parse(AnnotationParser.java:821)
    at org.eclipse.jetty.annotations.AnnotationConfiguration$ParserTask.call(AnnotationConfiguration.java:159)
    at org.eclipse.jetty.annotations.AnnotationConfiguration$1.run(AnnotationConfiguration.java:542)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:607)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:536)
    at java.lang.Thread.run(Thread.java:745)
Caused by: 
java.lang.IllegalArgumentException
    at org.objectweb.asm.ClassReader.<init>(Unknown Source)
    at org.objectweb.asm.ClassReader.<init>(Unknown Source)
    at org.objectweb.asm.ClassReader.<init>(Unknown Source)
    at org.eclipse.jetty.annotations.AnnotationParser.scanClass(AnnotationParser.java:970)
    at org.eclipse.jetty.annotations.AnnotationParser.parseDir(AnnotationParser.java:700)
    at org.eclipse.jetty.annotations.AnnotationParser.parseDir(AnnotationParser.java:686)
    at org.eclipse.jetty.annotations.AnnotationParser.parseDir(AnnotationParser.java:686)
    at org.eclipse.jetty.annotations.AnnotationParser.parseDir(AnnotationParser.java:686)
    at org.eclipse.jetty.annotations.AnnotationParser.parse(AnnotationParser.java:821)
    at org.eclipse.jetty.annotations.AnnotationConfiguration$ParserTask.call(AnnotationConfiguration.java:159)
    at org.eclipse.jetty.annotations.AnnotationConfiguration$1.run(AnnotationConfiguration.java:542)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:607)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:536)
    at java.lang.Thread.run(Thread.java:745)

我的环境是 Ubuntu 14.04/x64/Oracle java 8。顺便说一句,我从网站上下载了 Danny Cowards 的源代码,它与我的代码完全相同。但是,它有自己的神秘 *.war(在 dist 目录中,但 ant build.xml 显然是指所有没有业务的 NetBeans 依赖项,所以我无法使用 @987654336 编译它@) 并将其放置在 HTTPS 码头中,它完全按预期运行,当我使用 wss: 访问它时没有收到错误,所以这不是 SSL/自签名证书问题,或者我认为.

谁能告诉我这里可能是什么问题?对此的任何帮助都深表感谢。

谢谢, 桑尼。

PS:我查看了一些关于 SO 的 WebSocket/SSL/Jetty 帖子,但它们似乎没有解决我在使用 Jetty 时遇到的问题。

【问题讨论】:

  • 我更详细地查看了错误 java.lang.IllegalArgumentException at org.objectweb.asm.ClassReader.&lt;init&gt;(Unknown Source) 并且许多人建议我回到 Java 7(例如stackoverflow.com/questions/27092857/…)!!这是不受支持的 Java 版本!这个问题有什么解决方法吗?

标签: java ssl websocket jetty


【解决方案1】:

Jetty 9.1.x 对于 JSR356 (javax.websocket) 使用来说太旧了。

使用 Jetty 9.2.x 或 Jetty 9.3.x 来支持 JSR356。

由于您似乎使用的是 Java 8,请使用版本 Jetty 版本9.3.6.v20151106

【讨论】:

  • 谢谢。在接受您的回答之前,我想尽快尝试一下,但是我在密钥库和 SSL 配置方面遇到了很多麻烦,以便在 9.3.6 上切换到 SSL/HTTPS。我查看了 Jetty 网站 (eclipse.org/jetty/documentation/current/…) 并一直跟踪它,但它没有帮助,启动 Jetty 导致Caused by: java.io.IOException: Keystore was tampered with, or password was incorrect 我再次在 SO 上查看,再次无济于事。我认为 Jetty 文档需要做很多工作;希望能帮到你。
  • 必须做{jetty.home} $ java -cp lib/jetty-util-9.3.6.v20151106.jar org.eclipse.jetty.util.security.Password "MyInterestingAndAwesomPassword" 并替换{jetty.home}/etc/jetty-ssl-context.xmlwss 中的OBF.. 行,HTTPS 现在可以工作。谢谢!
  • 不要修改/删除/更改/编辑${jetty.home}下的任何文件。正确设置您的 ${jetty.base}/start.ini 并在那里设置您的密钥库的属性。
  • 想搞清楚jetty.base新概念的朋友请看eclipse.org/jetty/documentation/current/…
猜你喜欢
  • 1970-01-01
  • 2013-03-16
  • 2018-11-08
  • 2017-01-01
  • 2017-01-14
  • 1970-01-01
  • 2016-04-17
  • 2017-08-23
  • 1970-01-01
相关资源
最近更新 更多