2013-07-30 231 views
1

我跟着用户指南可用here:我加入这在我的POM:Tyrus websocket服务器握手问题?

<dependency> 
    <groupId>org.glassfish.tyrus</groupId> 
    <artifactId>tyrus-server</artifactId> 
    <version>1.2</version> 
</dependency> 
<dependency> 
    <groupId>org.glassfish.tyrus</groupId> 
    <artifactId>tyrus-container-grizzly</artifactId> 
    <version>1.2</version> 
</dependency> 

我写这在我的主类:

Server server = new Server("localhost", 8624, "/", EchoEndPoint.class); 
try 
    { 
    server.start(); 
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); 
    System.out.print("Please press a key to stop the server."); 
    reader.readLine(); 
    } 
catch(Exception ex) { ex.printStackTrace(); } 
finally 
    { 
    server.stop(); 
    } 

我EchoEndPoint类的内容是一样的描述in the guide

我试着用HTML5的WebSocket连接到此:

var ws = new WebSocket("ws://localhost:8624/echo"); 

看来,浏览器端,它不连接(它直接调用的OnClose回调)。而且,服务器端,我在控制台中看到这一点:

Grave: Invalid Connection header returned: 'keep-alive' 
org.glassfish.tyrus.websockets.HandshakeException: Invalid Connection header returned: 'keep-alive' 
    at org.glassfish.tyrus.websockets.HandShake.validate(HandShake.java:254) 
    at org.glassfish.tyrus.websockets.HandShake.checkForHeader(HandShake.java:246) 
    at org.glassfish.tyrus.websockets.HandShake.<init>(HandShake.java:97) 
    at org.glassfish.tyrus.websockets.draft06.HandShake06.<init>(HandShake06.java:63) 
    [...] 
org.glassfish.grizzly.filterchain.DefaultFilterChain execute 
Avertissement: Exception during FilterChain execution 
java.lang.ClassCastException: org.glassfish.grizzly.http.HttpContent cannot be cast to org.glassfish.tyrus.websockets.DataFrame 
    at org.glassfish.tyrus.container.grizzly.WebSocketFilter.handleWrite(WebSocketFilter.java:330) 

如果它的任何帮助,我复制补时浏览器检查的请求头:

GET /echo HTTP/1.1 
Host: localhost:8624 
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:22.0) Gecko/20100101 Firefox/22.0 FirePHP/0.7.2 
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 
Accept-Language: fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3 
Accept-Encoding: gzip, deflate 
DNT: 1 
Sec-WebSocket-Version: 13 
Origin: null 
Sec-WebSocket-Key: yhGPwJ26c5fYEZ5/abvtqw== 
x-insight: activate 
Connection: keep-alive, Upgrade 
Pragma: no-cache 
Cache-Control: no-cache 
Upgrade: websocket 

这是一个握手的问题?

编辑:我试过Chrome(28.0.1500.72),它的工作。也许这个问题来自于Firefox构建头文件时?

回答

0

Tyrus抱怨Connection: keep-alive, Upgrade标题。

Firefox在这里没有做错任何事情。

Tyrus的限制性太强,不遵循WebSocket规范(RFC-6455)关于如何处理Connection头。

Section 4.1的RFC状态:

6. The request MUST contain a |Connection| header field whose value 
     MUST include the "Upgrade" token. 

3. If the response lacks a |Connection| header field or the 
     |Connection| header field doesn't contain a token that is an 
     ASCII case-insensitive match for the value "Upgrade", the client 
     MUST _Fail the WebSocket Connection_. 

这似乎是在泰鲁斯的错误。

+0

感谢您的回答(我读了一点晚)。我认为这个“升级”标记的东西被纠正了[那里](https://java.net/jira/browse/TYRUS-55)。也许不会 ? – bloofi

+0

固定在Tyrus 1.2.1 –

+0

好吧,我会改变我的POM,并试试看。 我想[这个问题](https://java.net/jira/browse/TYRUS-222)是一个相关的? – bloofi