WebSocket connection to ... failed: Error during WebSocket handshake: Unexpected response code: 200
<p>I am trying to create websocket connection between Chrome Browser and Glassfish 4.1.1 server. Unfortunately, I get HTTP 200 message instead of 101. </p>

<p>Chrome DevTool log:</p>

<pre><code>"WebSocket connection to 'ws://DOMAIN_NAME:8080/serverendpointdemo/' failed: 
Error during WebSocket handshake: Unexpected response code: 200"
</code></pre>

<p>Client side code:</p>

<pre><code>var ws = new WebSocket ("ws://" + document.location.host + "/serverendpointdemo/");
</code></pre>

<p>Server side code:</p>

<pre><code>package com.za.tutorial.websocket;

import javax.websocket.OnClose;
import javax.websocket.OnError;
import javax.websocket.OnMessage;
import javax.websocket.OnOpen;
import javax.websocket.server.ServerEndpoint;

@ServerEndpoint("/home/USER_NAME/glassfish4/glassfish/domains/domain1/applications/serverendpointdemo")
public class ServerEndpointDemo {
    @OnOpen
    public void handleOpen() {
        System.out.println("Client is now connected...");
    }

    @OnMessage
    public String handleMessage (String message) {
       return null;
    }

    @OnClose
    public void handleClose () {
    }

    @OnError
    public void handleError (Throwable t) {
        t.printStackTrace();
    }
}
</code></pre>