2 Replies Latest reply on Dec 9, 2013 6:32 PM by savvas.andreas

    Programmatic Endpoint issue in WildFly

    savvas.andreas

      Hello,

       

      I am trying to test the latest release of WildFly and have come across an issue with a programmatic endpoint. I am basically following the examples given in Danny Coward's book "Java WebSocket Programming" and in one of them a programmatic endpoint needs to be created similar to the following:

       

      import java.io.IOException;

      import java.util.logging.Level;

      import java.util.logging.Logger;

       

      import javax.websocket.CloseReason;

      import javax.websocket.Endpoint;

      import javax.websocket.EndpointConfig;

      import javax.websocket.MessageHandler;

      import javax.websocket.Session;

      import javax.websocket.server.ServerEndpoint;

       

      @ServerEndpoint("/programmatic-lights")

      public class ProgrammaticLifecycleEndpoint extends Endpoint {

       

          private static final String START_TIME_SESSION_KEY = "Start Time";

          private static final String ILLEGAL_SEQUENCE = "xxx";

          private static final String CLOSE_REQUEST_COMMAND = "close";

          private Logger logger = Logger.getLogger("ProgrammaticLifecycleEndpoint");

       

          private Session session;

       

         @Override

          public void onOpen(Session session, EndpointConfig endpConfig) {

              System.out.println("onOpen() invoked!");

       

              this.session = session;

              final Session mySession = session;

              this.session.addMessageHandler(new MessageHandler.Whole<String>() {

                  @Override

                  public void onMessage(String message) {

                      try {

                          validateMessage(message);

                          if (message.contains(CLOSE_REQUEST_COMMAND)) {

                              sendMessage("1:Server closing after "

                                      + getConnectionSeconds() + "seconds");

                              mySession.close();

                          } else {

                              sendMessage("3:Just processed a message");

                          }

                      } catch (IOException e) {

                          System.out.println();

                          e.printStackTrace();

                      }

                  }

              });

              session.getUserProperties().put(START_TIME_SESSION_KEY, System.currentTimeMillis());

              sendMessage("3:Just opened");

          }

       

       

          @Override

          public void onClose(Session session, CloseReason closeReason) {

              System.out.println("Connection closed!");

          }

       

          @Override

          public void onError(Session session, Throwable thr) {

              sendMessage("2:Error: " + thr.getMessage());

          }

       

      // more code here

       

      I am able to make a GET request to the above endpoint, meaning I am getting a 101 response, which means that the endpoint is being mapped, but the onOpen() method doesn't seem to be getting called at all (my sys out message isn't getting printed and the ui doesn't react as expected).

      The annotation equivalent of the above code is working ok.

       

      Any ideas?

       

      I am using version 8.0.0.Beta1

       

      Cheers,

      Savvas