2 Replies Latest reply on Jun 16, 2013 10:21 AM by cs02rm0

    Websockets

    cs02rm0

      Is the following sufficient to deploy a ServerEndpoint?

       

      [code]import javax.websocket.EndpointConfig;

      import javax.websocket.OnMessage;

      import javax.websocket.OnOpen;

      import javax.websocket.Session;

      import javax.websocket.server.PathParam;

      import javax.websocket.server.ServerEndpoint;

       

      @ServerEndpoint(value="/websocket/{name}")

      public class UpdateWebSocketServlet {

       

      @OnMessage

      public String echo(final String message, @PathParam("name") String name) {

        System.out.println("echo: " +message +" " +name);

        return name;

                }

       

      @OnOpen

      public void open(final Session session, final EndpointConfig endpoint) {

        System.out.println("open");

                }

      }[/code]

       

      I've tried testing it with the page at http://www.websocket.org/echo.html and a URI of ws://host:port/webapp/websocket/test but while it connects the response isn't a String but a Javascript object with little of interest on it and the stdout logging I'd expect if it was getting into the endpoint is absent.

       

      ETA: Sorry, can't figure out the code formatting for the life of me either.

        • 1. Re: Websockets
          swd847

          That should be all that is needed, there were some known bugs in Websockets in the Alpha1 release, however I don't think any of them would affect this endpoint.

           

          There is not special config that is needed to enable endpoints, as long as you are using the Undertow subsystem and not JBoss Web. Are you sure websocket.org test page can resolve your endpoint?

          • 2. Re: Websockets
            cs02rm0

            Thanks. Not sure quite what resolving an endpoint is? I can see in the Chrome dev tools that there's a connection with status 101 switching protocols and then it sends the default text they use. Little else though.