Question

I followed the User Guide available here : i added this in my pom :

<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>

I wrote this in my main class :

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();
  }

The content of my EchoEndPoint class is the same as described in the guide.

I tried to connect to this with a HTML5 websocket :

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

It seems that, browser side, it doesn't connect (it calls the onClose callback directly). And, server side, i get this in the console :

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)

If it's of any help, i copy the request header caught with the browser inspector :

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

Is this a handshake problem ?

EDIT : i've tried in Chrome (28.0.1500.72) and it's working. Maybe the issue comes from Firefox when it builds the header ?

Était-ce utile?

La solution

Tyrus is complaining about the Connection: keep-alive, Upgrade header.

Firefox isn't doing anything wrong here.

Tyrus is being too restrictive and not following the WebSocket Spec (RFC-6455) with regards to how to handle the Connection header.

The RFC states in Section 4.1:

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

and

   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_.

This seems like a bug in Tyrus.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top