title: How to get a websocket in glassfish 4 and jsf working?
body: <p>Here's my code I get the js ws working but when y try to send a message to the websocket :glassfish returns:</p>
  
  <pre><code>INFO:   Error : SessionImpl{uri=/Formosa2/endpoint, id='b821d249-6435-45fe-812d- 577bc5fc8fca', endpoint=EndpointWrapper{endpointClass=null, endpoint=org.glassfish.tyrus.core.AnnotatedEndpoint@1602760, uri='/Formosa2/endpoint', contextPath='/Formosa2'}}
  
  @ServerEndpoint(value = "/endpoint")
  @Singleton
  public class websocket {
  private static Set&lt;Session&gt; peers = Collections.synchronizedSet(new HashSet&lt;Session&gt;());
  
  @OnMessage
  public void onMessage(String message) {
          String filteredMessage = String.format("%s: %s", message.toString());
          broadcast(filteredMessage);
          System.out.println(message);
  }
  
  @OnOpen
  public void onOpen(Session peer){
      peers.add(peer);
      String message = String.format("* %s %s", "User has joined.");
      broadcast(message);
  }
  
  @OnClose
  public void onClose(Session peer){
      peers.remove(peer);
  }
  
  @OnError
  public void onError(Session aclientSession, Throwable aThrowable) {
      System.out.println("Error : " + aclientSession);
  }
  
  private void broadcast(String message) {
          for (Session peer : peers) {
              try {
                  CharBuffer buffer = CharBuffer.wrap(message);
                  peer.getBasicRemote().sendText(buffer.toString());
              } catch (IOException ignore) {
                  // Ignore
              }
          }
      }
  }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>        &lt;script type="text/javascript"&gt;
  
              ws = new WebSocket('ws://' + window.location.host + '/Formosa2/endpoint');  //Annotation
  
      ws.onopen = function(event) {
               Console.log('Info: WebSocket connection opened.');
                      document.getElementById('chat').onkeydown = function(event) {
                          if (event.keyCode == 13) {
                              sendMessage();
                          }
                      };
      };
  
      ws.onmessage = function(event) {
                  sendMessage(event);
      };
  
      ws.onclose = function(event) {
                      document.getElementById('chat').onkeydown = null;
                      Console.log('Info: WebSocket closed.');
      };
  
      ws.onerror = function(event){
          alert("Error :  " + event.data);
                      Console.log(message.data);
      };
  
  
              function sendMessage (event) {
                  var text = document.getElementById('form:texto').value;
                  var select = document.getElementById('form:empresaidEmpresa');
                  var text2 = document.getElementById('inicio_input').value;
  
                  var name = select.options[select.selectedIndex].text;
                      ws.send(texto +', '+ name +',' + text2);
                      document.getElementById('chat').value = '';
              }
  
              var Console = {};
  
              Console.log = (function(message) {
                  var console = document.getElementById('console');
                  var p = document.createElement('p');
                  p.style.wordWrap = 'break-word';
                  p.innerHTML = message;
                  console.appendChild(p);
                  while (console.childNodes.length &gt; 25) {
                      console.removeChild(console.firstChild);
                  }
                  console.scrollTop = console.scrollHeight;
              });
  
     //         Chat.initialize();
  
          &lt;/script&gt;
  </code></pre>