- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我有一个在嵌入式 jetty (8.1.8.v20121106) 中运行的 WebSocket 服务器,我想从另一个带有 jetty WebSocketClient 的 Java 应用程序连接到它。这是我使用的测试方法:
@Test
public void testWebSockets() throws Exception {
logger.debug("START testWebSockets()");
WebSocketClientFactory factory = new WebSocketClientFactory();
factory.setBufferSize(4096);
factory.start();
WebSocketClient client = factory.newWebSocketClient();
client.setMaxIdleTime(30000);
client.setMaxTextMessageSize(1024);
client.setProtocol("MyProtocol");
WebSocket webSocket = new ClientWebSocket();
String wsUrl = "ws://localhost:8080/websocket";
String wssUrl = "wss://localhost:8443/websocket";
Future future = client.open(new URI(wssUrl), webSocket);
WebSocket.Connection connection = (Connection) future.get(10, TimeUnit.SECONDS);
assertNotNull("No connection!", connection);
connection.sendMessage("TestMessage");
connection.close();
logger.debug("END testWebSockets()");
}
使用 wsUrl 没有问题,但我无法让它与 wss 一起工作。我不认为服务器是问题,因为我从 javascript 连接 wss 没有问题。我在这个测试中做错了什么?
服务器和客户端都在 ssl 设置上记录了“错误记录 MAC”。这是服务器日志的最后一部分:
2013-01-15 10:26:06,398 qtp9902580-25 DEBUG org.eclipse.jetty.io.nio.ssl - [Session-1, SSL_NULL_WITH_NULL_NULL] unwrap OK NEED_TASK consumed=107 produced=0
2013-01-15 10:26:06,399 qtp9902580-25 DEBUG org.eclipse.jetty.io.nio.ssl - [Session-1, SSL_NULL_WITH_NULL_NULL] SslConnection@9063ac SSL NEED_TASK i/o/u=75/0/0 ishut=false oshut=false {AsyncHttpConnection@17fc2ee,g=HttpGenerator{s=0,h=-1
,b=-1,c=-1},p=HttpParser{s=-14,l=0,c=0},r=0} NEED_TASK filled=69/75 flushed=0/0
2013-01-15 10:26:06,413 qtp9902580-25 DEBUG org.eclipse.jetty.io.nio.ssl - [Session-1, SSL_NULL_WITH_NULL_NULL] SslConnection@9063ac SSL NEED_UNWRAP i/o/u=75/0/0 ishut=false oshut=false {AsyncHttpConnection@17fc2ee,g=HttpGenerator{s=0,h=
-1,b=-1,c=-1},p=HttpParser{s=-14,l=0,c=0},r=0} NEED_UNWRAP filled=0/75 flushed=0/0
2013-01-15 10:26:06,415 qtp9902580-25 DEBUG org.eclipse.jetty.io.nio.ssl - [Session-1, SSL_NULL_WITH_NULL_NULL] unwrap OK NEED_UNWRAP consumed=6 produced=0
2013-01-15 10:26:06,416 qtp9902580-25 DEBUG org.eclipse.jetty.io.nio.ssl - [Session-1, SSL_NULL_WITH_NULL_NULL] SslConnection@9063ac SSL NEED_UNWRAP i/o/u=69/0/0 ishut=false oshut=false {AsyncHttpConnection@17fc2ee,g=HttpGenerator{s=0,h=
-1,b=-1,c=-1},p=HttpParser{s=-14,l=0,c=0},r=0} NEED_UNWRAP filled=0/69 flushed=0/0
2013-01-15 10:26:06,419 qtp9902580-25 DEBUG org.eclipse.jetty.io.nio.ssl - [Session-1, SSL_NULL_WITH_NULL_NULL] unwrap OK NEED_WRAP consumed=69 produced=0
2013-01-15 10:26:06,420 qtp9902580-25 DEBUG org.eclipse.jetty.io.nio.ssl - [Session-1, SSL_NULL_WITH_NULL_NULL] SslConnection@9063ac SSL NEED_WRAP i/o/u=0/0/0 ishut=false oshut=false {AsyncHttpConnection@17fc2ee,g=HttpGenerator{s=0,h=-1,
b=-1,c=-1},p=HttpParser{s=-14,l=0,c=0},r=0} NEED_WRAP filled=0/0 flushed=0/0
2013-01-15 10:26:06,421 qtp9902580-25 DEBUG org.eclipse.jetty.io.nio.ssl - [Session-1, SSL_NULL_WITH_NULL_NULL] wrap OK NEED_WRAP consumed=0 produced=6
2013-01-15 10:26:06,422 qtp9902580-25 DEBUG org.eclipse.jetty.io.nio.ssl - [Session-1, SSL_NULL_WITH_NULL_NULL] SslConnection@9063ac SSL NEED_WRAP i/o/u=0/0/0 ishut=false oshut=false {AsyncHttpConnection@17fc2ee,g=HttpGenerator{s=0,h=-1,
b=-1,c=-1},p=HttpParser{s=-14,l=0,c=0},r=0} NEED_WRAP filled=0/0 flushed=6/0
2013-01-15 10:26:06,423 qtp9902580-25 DEBUG org.eclipse.jetty.io.nio.ssl - [Session-1, SSL_NULL_WITH_NULL_NULL] wrap OK FINISHED consumed=0 produced=69
2013-01-15 10:26:06,424 qtp9902580-25 DEBUG org.eclipse.jetty.io.nio.ssl - [Session-1, SSL_NULL_WITH_NULL_NULL] SslConnection@9063ac SSL NOT_HANDSHAKING i/o/u=0/0/0 ishut=false oshut=false {AsyncHttpConnection@17fc2ee,g=HttpGenerator{s=0
,h=-1,b=-1,c=-1},p=HttpParser{s=-14,l=0,c=0},r=0} NOT_HANDSHAKING filled=0/0 flushed=69/0
2013-01-15 10:26:06,426 qtp9902580-25 DEBUG org.eclipse.jetty.io.nio.ssl - [Session-1, SSL_NULL_WITH_NULL_NULL] SslConnection@9063ac SSL NOT_HANDSHAKING i/o/u=0/0/0 ishut=false oshut=false {AsyncHttpConnection@17fc2ee,g=HttpGenerator{s=0
,h=-1,b=-1,c=-1},p=HttpParser{s=-14,l=0,c=0},r=0} NOT_HANDSHAKING filled=0/0 flushed=0/0
2013-01-15 10:26:06,428 qtp9902580-25 DEBUG org.eclipse.jetty.io.nio.ssl - [Session-1, SSL_NULL_WITH_NULL_NULL] SslConnection@9063ac SSL NOT_HANDSHAKING i/o/u=245/0/0 ishut=false oshut=false {AsyncHttpConnection@17fc2ee,g=HttpGenerator{s
=0,h=-1,b=-1,c=-1},p=HttpParser{s=-14,l=0,c=0},r=0} NOT_HANDSHAKING filled=245/245 flushed=0/0
2013-01-15 10:26:06,430 qtp9902580-25 DEBUG org.eclipse.jetty.io.nio.ssl - SCEP@1dac071{l(/127.0.0.1:65084)<->r(/127.0.0.1:8444),d=true,open=true,ishut=false,oshut=false,rb=false,wb=false,w=true,i=1r}-{SslConnection@9063ac SSL NEED_WRAP
i/o/u=245/0/0 ishut=false oshut=false {AsyncHttpConnection@17fc2ee,g=HttpGenerator{s=0,h=-1,b=-1,c=-1},p=HttpParser{s=-14,l=0,c=0},r=0}}
javax.net.ssl.SSLException: bad record MAC
at sun.security.ssl.Alerts.getSSLException(Alerts.java:208)
at sun.security.ssl.SSLEngineImpl.fatal(SSLEngineImpl.java:1639)
at sun.security.ssl.SSLEngineImpl.fatal(SSLEngineImpl.java:1607)
at sun.security.ssl.SSLEngineImpl.readRecord(SSLEngineImpl.java:979)
at sun.security.ssl.SSLEngineImpl.readNetRecord(SSLEngineImpl.java:884)
at sun.security.ssl.SSLEngineImpl.unwrap(SSLEngineImpl.java:758)
at javax.net.ssl.SSLEngine.unwrap(SSLEngine.java:624)
at org.eclipse.jetty.io.nio.SslConnection.unwrap(SslConnection.java:524)
at org.eclipse.jetty.io.nio.SslConnection.process(SslConnection.java:359)
at org.eclipse.jetty.io.nio.SslConnection.access$900(SslConnection.java:48)
at org.eclipse.jetty.io.nio.SslConnection$SslEndPoint.fill(SslConnection.java:666)
at org.eclipse.jetty.http.HttpParser.fill(HttpParser.java:1035)
at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:280)
at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:235)
at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)
at org.eclipse.jetty.io.nio.SslConnection.handle(SslConnection.java:196)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:628)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:52)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
at java.lang.Thread.run(Thread.java:722)
2013-01-15 10:26:06,463 qtp9902580-25 DEBUG org.eclipse.jetty.io.nio.ChannelEndPoint - close SCEP@1dac071{l(/127.0.0.1:65084)<->r(/127.0.0.1:8444),d=true,open=true,ishut=false,oshut=false,rb=false,wb=false,w=true,i=1!}-{SslConnection@906
3ac SSL NEED_WRAP i/o/u=245/0/0 ishut=false oshut=false {AsyncHttpConnection@17fc2ee,g=HttpGenerator{s=0,h=-1,b=-1,c=-1},p=HttpParser{s=-14,l=0,c=0},r=0}}
2013-01-15 10:26:06,469 qtp9902580-25 DEBUG org.eclipse.jetty.http.HttpParser -
javax.net.ssl.SSLException: bad record MAC
at sun.security.ssl.Alerts.getSSLException(Alerts.java:208)
at sun.security.ssl.SSLEngineImpl.fatal(SSLEngineImpl.java:1639)
at sun.security.ssl.SSLEngineImpl.fatal(SSLEngineImpl.java:1607)
at sun.security.ssl.SSLEngineImpl.readRecord(SSLEngineImpl.java:979)
at sun.security.ssl.SSLEngineImpl.readNetRecord(SSLEngineImpl.java:884)
at sun.security.ssl.SSLEngineImpl.unwrap(SSLEngineImpl.java:758)
at javax.net.ssl.SSLEngine.unwrap(SSLEngine.java:624)
at org.eclipse.jetty.io.nio.SslConnection.unwrap(SslConnection.java:524)
at org.eclipse.jetty.io.nio.SslConnection.process(SslConnection.java:359)
at org.eclipse.jetty.io.nio.SslConnection.access$900(SslConnection.java:48)
at org.eclipse.jetty.io.nio.SslConnection$SslEndPoint.fill(SslConnection.java:666)
at org.eclipse.jetty.http.HttpParser.fill(HttpParser.java:1035)
at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:280)
at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:235)
at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)
at org.eclipse.jetty.io.nio.SslConnection.handle(SslConnection.java:196)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:628)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:52)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
at java.lang.Thread.run(Thread.java:722)
2013-01-15 10:26:06,506 qtp9902580-25 DEBUG org.eclipse.jetty.http.HttpParser - HttpParser{s=-14,l=0,c=0}
org.eclipse.jetty.io.EofException
at org.eclipse.jetty.http.HttpParser.fill(HttpParser.java:1041)
at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:280)
at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:235)
at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)
at org.eclipse.jetty.io.nio.SslConnection.handle(SslConnection.java:196)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:628)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:52)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
at java.lang.Thread.run(Thread.java:722)
Caused by: javax.net.ssl.SSLException: bad record MAC
at sun.security.ssl.Alerts.getSSLException(Alerts.java:208)
at sun.security.ssl.SSLEngineImpl.fatal(SSLEngineImpl.java:1639)
at sun.security.ssl.SSLEngineImpl.fatal(SSLEngineImpl.java:1607)
at sun.security.ssl.SSLEngineImpl.readRecord(SSLEngineImpl.java:979)
at sun.security.ssl.SSLEngineImpl.readNetRecord(SSLEngineImpl.java:884)
at sun.security.ssl.SSLEngineImpl.unwrap(SSLEngineImpl.java:758)
at javax.net.ssl.SSLEngine.unwrap(SSLEngine.java:624)
at org.eclipse.jetty.io.nio.SslConnection.unwrap(SslConnection.java:524)
at org.eclipse.jetty.io.nio.SslConnection.process(SslConnection.java:359)
at org.eclipse.jetty.io.nio.SslConnection.access$900(SslConnection.java:48)
at org.eclipse.jetty.io.nio.SslConnection$SslEndPoint.fill(SslConnection.java:666)
at org.eclipse.jetty.http.HttpParser.fill(HttpParser.java:1035)
... 9 more
2013-01-15 10:26:06,470 qtp9902580-23 Selector0 DEBUG org.eclipse.jetty.io.nio - destroyEndPoint SCEP@1dac071{l(null)<->r(0.0.0.0/0.0.0.0:8444),d=true,open=false,ishut=true,oshut=true,rb=false,wb=false,w=true,i=1!}-{SslConnection@9063ac
SSL NEED_WRAP i/o/u=245/0/0 ishut=false oshut=false {AsyncHttpConnection@17fc2ee,g=HttpGenerator{s=0,h=-1,b=-1,c=-1},p=HttpParser{s=-14,l=0,c=0},r=0}}
2013-01-15 10:26:06,555 qtp9902580-25 DEBUG org.eclipse.jetty.server.AsyncHttpConnection - Disabled read interest while writing response SSL NEED_WRAP i/o/u=245/0/0 ishut=false oshut=false {AsyncHttpConnection@17fc2ee,g=HttpGenerator{s=0
,h=-1,b=-1,c=-1},p=HttpParser{s=0,l=0,c=0},r=0}
2013-01-15 10:26:06,559 qtp9902580-23 Selector0 DEBUG org.eclipse.jetty.server.AbstractHttpConnection - closed AsyncHttpConnection@17fc2ee,g=HttpGenerator{s=0,h=-1,b=-1,c=-1},p=HttpParser{s=0,l=0,c=0},r=0
2013-01-15 10:26:06,560 qtp9902580-25 DEBUG org.eclipse.jetty.io.nio - EOF
org.eclipse.jetty.io.EofException
at org.eclipse.jetty.http.HttpParser.fill(HttpParser.java:1041)
at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:280)
at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:235)
at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)
at org.eclipse.jetty.io.nio.SslConnection.handle(SslConnection.java:196)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:628)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:52)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
at java.lang.Thread.run(Thread.java:722)
Caused by: javax.net.ssl.SSLException: bad record MAC
at sun.security.ssl.Alerts.getSSLException(Alerts.java:208)
at sun.security.ssl.SSLEngineImpl.fatal(SSLEngineImpl.java:1639)
at sun.security.ssl.SSLEngineImpl.fatal(SSLEngineImpl.java:1607)
at sun.security.ssl.SSLEngineImpl.readRecord(SSLEngineImpl.java:979)
at sun.security.ssl.SSLEngineImpl.readNetRecord(SSLEngineImpl.java:884)
at sun.security.ssl.SSLEngineImpl.unwrap(SSLEngineImpl.java:758)
at javax.net.ssl.SSLEngine.unwrap(SSLEngine.java:624)
at org.eclipse.jetty.io.nio.SslConnection.unwrap(SslConnection.java:524)
at org.eclipse.jetty.io.nio.SslConnection.process(SslConnection.java:359)
at org.eclipse.jetty.io.nio.SslConnection.access$900(SslConnection.java:48)
at org.eclipse.jetty.io.nio.SslConnection$SslEndPoint.fill(SslConnection.java:666)
at org.eclipse.jetty.http.HttpParser.fill(HttpParser.java:1035)
... 9 more
2013-01-15 10:26:06,623 qtp9902580-25 DEBUG org.eclipse.jetty.io.nio.ChannelEndPoint - close SCEP@1dac071{l(null)<->r(0.0.0.0/0.0.0.0:8444),d=true,open=false,ishut=true,oshut=true,rb=false,wb=false,w=true,i=1-}-{SslConnection@9063ac SSL
NEED_WRAP i/o/u=245/0/0 ishut=false oshut=false {AsyncHttpConnection@17fc2ee,g=HttpGenerator{s=0,h=-1,b=-1,c=-1},p=HttpParser{s=0,l=0,c=0},r=0}}
最佳答案
我也尝试使用 Jetty 9.0.3,但得到了与 Jetty - SSL Websocket Client 相同的异常
因为 jetty websocket 客户端似乎有其他人没有的问题,我切换到 async http client ,这对我来说很完美:
@Test
public void testNingWebSockets() throws Exception {
logger.debug("START testNingWebSockets()");
String wsUrl = "ws://localhost:8081/websocket";
String wssUrl = "wss://localhost:8444/websocket";
AsyncHttpClient client = new AsyncHttpClient();
WebSocketUpgradeHandler handler = new WebSocketUpgradeHandler.Builder().addWebSocketListener(new ClientWebSocket()).build();
WebSocket websocket = client.prepareGet(wssUrl).execute(handler).get();
Assert.assertNotNull("No connection!", websocket);
logger.debug("Connection made: " + websocket.isOpen());
websocket.sendMessage("TestMessage".getBytes());
Thread.sleep(1000);
websocket.close();
logger.debug("END testNingWebSockets()");
}
关于java - 通过 ssl 的 Jetty WebSocketClient,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14334821/
我在 Cloudflare 的域名服务器上有一个域名 example.com。该域指向我的专用服务器的 IP 地址,该服务器运行 CentOS/WHM/cPanel。该站点可访问 - 一切都很好。 我
我正在努力将 SSL 支持添加到我们现有的应用程序中,并已开始考虑向后兼容性。 与我读过的其他帖子不同的一个特殊情况是服务器可能不一定使用 SSL 代码更新。所以我将有一个 SSL 客户端连接到一个对
我有几个 https://*.rest-service.mydomain.com。随着服务数量的增加,我觉得管理 SSL 证书的成本很高。我为 *.mydomain.com 购买了通配符证书。 新添加
我的客户要求我在他的网站上做反向 ssl。但我是这个学期的新手。谁能帮我解决这个问题。 请描述或引用如何做。 最佳答案 查看 this wiki article . In the case of se
关闭。这个问题是opinion-based .它目前不接受答案。 想改进这个问题?更新问题,以便 editing this post 可以用事实和引用来回答它. 去年关闭。 Improve this
我连接到我的网络服务器上的存储库,但是当我尝试推送我的更改时,它显示:“错误 403:需要 ssl”,但在我的存储库设置中我已经激活了 ssl 选项。 有什么建议吗? 最佳答案 当您连接到存储库时,您
抱歉,如果这听起来像是转储问题,我已经阅读了很多关于 SSL 握手和 SSL 工作原理的文章和文档。我对一件事感到困惑,如果有人能澄清我就太好了。 我知道私钥要保密。但是我已经看到通过在请求中指定私钥
随着物联网越来越主流,越来越需要从硬件发送http请求。 一个主要问题是硬件微 Controller 无法发送 ssl 请求,但大多数服务器/网站/服务都在使用 ssl。 所以,问题是,有没有桥(一个
我有一个 ssl 页面,它还从非 ssl 站点下载头像。我能做些什么来隔离该内容,以便浏览器不会警告用户混合内容吗? 最佳答案 只是一个想法 - 或者: 尝试在头像网站上使用 ssl url,如有必要
我在 Digital Ocean droplet(使用 nginx)上设置了两个域。我已经在其中一个(domain1)中安装了一个 SSL 证书,并且那个证书一切正常。第二个域 (domain2) 不
我收到这个错误: Error frontend: 502 Bad gateway 99.110.244:443 2017/09/28 13:03:51 [error] 34080#34080: *10
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎与 help center 中定义的范围内的编程无关。 . 关闭 6 年前。 Improve
我遇到了一个问题,我正在构建一个 nginx 反向代理以定向到不同 url 路径上的多个微服务。 该系统完全基于 docker,因此开发和生产使用相同的环境。这在安装 SSL 时给我带来了问题,因为
所以我知道要求 SSL 证书和接受之间的根本区别,一个意味着您必须拥有 SSL 证书,另一个意味着您不需要。 在某个网页的 IIS 管理器中,我有以下设置: 我遇到的问题是,当我设置需要 SSL 证书
我今天才发现 .app 域名需要 SSL 证书。我购买它是为了将 DNS 重定向到已经设置了 SSL 证书的站点,所以我的问题是是否可以设置它? 我正在使用 Google Domains,在将合成临时
堆栈 : react ,NGINX 1.14.0,GUnicorn,Django 2.2.8,Python 3.6.9 错误 : 在浏览器:当 React 调用 Django API(当然是在请求头中
假设我在计算机上编辑主机文件以使 google.com 指向我的 VPS 服务器 IP,并且服务器具有通过 Apache 或 Nginx 配置的 google.com 的虚拟主机/服务器 block
我有一个场景,我正在处理用于 URL 路由的 IIS 网站配置。我已添加网站并在服务器上导入所需的证书。 我的情况是(我有多个网站 URL 和两个 SSL 证书 - 如下所示): qatest1.ab
我知道服务器发送的证书无法伪造(仍然存在 MD5 冲突,但成本高昂),但是伪造客户端又如何呢?在中间人攻击中:我们不能告诉服务器我们是合法客户端并从该服务器获取数据并对其进行操作,然后使用合法客户端公
我已通读相关问题,但无法完全找到我要查找的内容。我设置了一个名为“domain.com”的域,并创建了两个子域“client.domain.com”和“client-intern.domain.com
我是一名优秀的程序员,十分优秀!