title: WebSocket failed: Error during WebSocket handshake: Unexpected response code: 403
body: <p>I'm working on wildfly 8.2. if I run a WebSocket connection to  </p>
  
  <pre><code>var wsUrl = 'ws://' + window.location.host 
  
  var ws = new WebSocket(wsUrl + '/testwebservlet') 
  </code></pre>
  
  <p>On my server I have this msg in my console:</p>
  
  <pre><code>WebSocket connection to 'ws://localhost:8282/testwebservlet' failed:
      Error during WebSocket handshake: Unexpected response code: 403
  </code></pre>
  
  <p>My xhtml code is like below !!</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
  
  &lt;meta charset="UTF-8" /&gt;
  &lt;title&gt;WebSocket Client&lt;/title&gt;
  &lt;script type="text/javascript"&gt;      
   var wsUrl = 'ws://' + window.location.host 
   var ws = new WebSocket(wsUrl + '/testwebservlet')
  
       ws.onopen = function()
       {
          alert("Web Socket is connected!!");                 
       };
       ws.onmessage = function (evt) 
       {                  
          var msg = evt.data;
          alert("Message received:" +  msg);
       };
       ws.onclose = function()
       { 
          alert("Connection is closed..."); 
       };
  
    &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>java code:</p>
  
  <pre><code>package testwebservlet;
  import javax.annotation.Resource;
  import javax.ejb.Stateless;
  import javax.enterprise.concurrent.ManagedExecutorService;
  import javax.websocket.CloseReason;
  import javax.websocket.OnClose;
  import javax.websocket.OnMessage;
  import javax.websocket.OnOpen;
  import javax.websocket.Session;
  import javax.websocket.server.ServerEndpoint;
  import org.jboss.logging.Logger;
  
  @ServerEndpoint("/testwebservlet")
  public class WSEndpoint {
      Logger log = Logger.getLogger(this.getClass());
  
      @OnMessage
      public void receiveMessage(String message, Session session) {
          log.info("Received : "+ message + ", session:" + session.getId());
      }
  
      @OnOpen
      public void open(Session session) {
          log.info("Open session:" + session.getId());         
      }
  
      @OnClose
      public void close(Session session, CloseReason c) {
          log.info("Closing:" + session.getId());
      }
  }
  </code></pre>
  
  <p>Any suggestion?</p>