我一直在尝试使用cometd版本3.1.2和jetty 9.4.6.v20170531,使用cometd文档中的代码,获得一个非常简单的cometd java服务器和客户端设置。
HttpClient httpClient = new HttpClient();
httpClient.start();
Map<String, Object> options = new HashMap<String, Object>();
ClientTransport transport = new LongPollingTransport(options, httpClient);
BayeuxClient client = new BayeuxClient("http://localhost:9025/mycontext/cometd/", transport);
client.handshake();
boolean handshaken = client.waitFor(5000, BayeuxClient.State.CONNECTED);
if (handshaken) {
System.out.println("Yes");
// Here handshake is successful
}
System.out.println("Done");服务器设置才是我真正感兴趣的,它是一个spring注入的嵌入式jetty服务器,带有cometd servlet。无论我尝试过什么,客户端都不会握手。我终于能够证明服务器是正确的设置和通过邮递员发送此请求可用…
发布http://localhost:9025/mycontext/cometd
[{
"version": "1.0",
"minimumVersion": "0.9",
"channel": "/meta/handshake",
"supportedConnectionTypes": [
"long-polling",
"callback-polling"
],
"advice": {
"timeout": 60000,
"interval": 0
},
"id": "1"
}]...which返回一个200...
[
{
"minimumVersion": "1.0",
"clientId": "11jlmrekgqnu9v1i4w1b8rgiq3c",
"supportedConnectionTypes": [
"long-polling",
"websocket"
],
"advice": {
"interval": 0,
"timeout": 60000,
"reconnect": "retry"
},
"channel": "/meta/handshake",
"id": "1",
"version": "1.0",
"successful": true
}
]...so,很明显,服务器设置是正常的。我已经设置了断点,并使用tcpflow来查找流量,据我所知,使用cometd自己的库的最简单的客户端根本不会发送任何请求。无tcp流量。有人知道我错过了什么吗?感谢您的帮助。
发布于 2017-08-19 01:28:22
你一定有别的事要做。
您的代码是正确的,CometD测试套件将该代码用于数百个测试,并且运行良好。
请阅读CometD documentation的troubleshooting section。
作为建议,为org.cometd类别启用调试日志记录级别,并查看您获得的日志:问题应该很明显。
如果您仍然有问题,请随时将日志附加到CometD Issue Tracker上的问题。
https://stackoverflow.com/questions/45761275
复制相似问题