【发布时间】: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.<init>(Unknown Source)并且许多人建议我回到 Java 7(例如stackoverflow.com/questions/27092857/…)!!这是不受支持的 Java 版本!这个问题有什么解决方法吗?