Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jetty-users] Can I call multiple websocketservlets at the same base url?

Hi,

I am new to using Jetty websockets API. I already posted my question on stackoverflow, but no response yet.  


I'm using jetty 8.1.4, and this application I'm working on originally supports one WebSocketServlet url path. The URL for the server is something like:

URL1: ws://localhost:8081/user/1/feeda?x=1&y=2

Now I want to have another websocket path which will share a lot of the same framework code.

URL2: ws://localhost:8081/user/1/feedb?z=1

First of all, please correct me if I'm wrong in my understanding, and I can't have more than one websocket per server.

Current code:

public class FeedAServlet extends WebSocketServlet {
}

public class HealthServlet extends HttpServlet {
}

public class MyWebSocketServer extends Thread {
 .
 .

        ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
        context.setContextPath("/user");
        getSocketServer().setHandler(context);

        context.addServlet(new ServletHolder(new FeedAServlet()), "/");
        context.addServlet(new ServletHolder(new HealthServlet()), "/status");


        startPubSub();
        getSocketServer().start();
        getSocketServer().join();
 .
 .

}

My changes to add the new WebSocketServlet FeedBServlet. Here, I want to explicitly specify my two url paths unlike use of "/" earlier:

public class FeedBServlet extends WebSocketServlet {
}


public class MyWebSocketServer extends Thread {
 .
 .
        context.addServlet(new ServletHolder(new FeedAServlet()), "/feeda");
        context.addServlet(new ServletHolder(new FeedBServlet()), "/feedb");
        context.addServlet(new ServletHolder(new HealthServlet()), "/status");
 .
 .
}

However, now both my URL1 and URL2 are not working. Please tell me what I might be missing.

Alternative:

Now I am wondering if there is any solution for this, or if upgrading to jetty 9 will let me create a new websocket depending on the matching url. Similar to your example code in MyAdvancedEchoServlet, will I be able to conditionally direct the current request to the appropriate socket?


Please HELP!!! 

Thanks in advance.
L

Back to the top