3

I'm working on wildfly 8.2. if I run a WebSocket connection to

var wsUrl = 'ws://' + window.location.host 

var ws = new WebSocket(wsUrl + '/testwebservlet') 

On my server I have this msg in my console:

WebSocket connection to 'ws://localhost:8282/testwebservlet' failed:
    Error during WebSocket handshake: Unexpected response code: 403

My xhtml code is like below !!

<!DOCTYPE html>
<html>
<head>

<meta charset="UTF-8" />
<title>WebSocket Client</title>
<script type="text/javascript">      
 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..."); 
     };

  </script>
</head>
<body>

</body>
</html>

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

Any suggestion?

Tiny
  • 27,221
  • 105
  • 339
  • 599
steve.vai
  • 49
  • 1
  • 6
  • so it works on wildfly 9? – Kukeltje Jan 14 '16 at 15:13
  • So it is not a specific wildfly-8 problem like your tag suggests? – Kukeltje Jan 14 '16 at 15:15
  • You **know** what an http 403 is, right? http://stackoverflow.com/questions/3297048/403-forbidden-vs-401-unauthorized-http-responses – Kukeltje Jan 14 '16 at 17:22
  • @Kukeltje : WildFly is another headache lacking several rudimentary functionalities. 403 is constantly encountered on public WebSockets endpoints in WildFly 10.0.0 final. – Tiny Feb 08 '16 at 06:11
  • @Tiny: I never have this 403 on wildfly 8.2. But what functionalities are missing in 10? Can't seem to find a link to/about this – Kukeltje Feb 08 '16 at 07:34
  • steve, are you using any authentication framework? By the way, "webservlet" is an awkward name for an endpoint which would only confuse yourself and others. @Tiny: I never faced this kind of 403 problem during developing/testing on WF 8/9/10 (both Eclipse-managed and standalone, even in production). – BalusC Feb 08 '16 at 08:35

0 Answers0