I am trying to get a normal AbstractHandler and WebSocketAdapter to work at the same time.
jetty-version: jetty-9.4.8.v20171121,
I have a simple class Foo
that extends org.eclipse.jetty.server.handler.AbstractHandler
.
Also a class Bar
that extends org.eclipse.jetty.websocket.api.WebSocketAdapter
Glue-class:
@SuppressWarnings("serial")
public class Glue extends WebSocketServlet {
@Override
public void configure(WebSocketServletFactory factory) {
factory.register(Bar.class);
}
}
Now I try to make a server that uses both of these:
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/");
context.setHandler(new Foo());
ServletHolder holder = new ServletHolder("ws-events", Glue.class);
context.addServlet(holder, "/whatever/*");
Server server = new Server(80);
server.setHandler(context);
server.start();
This starts and when I go to localhost I see the content that Foo should display, but I can't connect to the websocket. It looks like all requests go to Foo.
When I remove the context.setHandler(new Foo());
line it obviously does not display the html-content anymore, but I can connect to the websocket.
I want both to work at the same time.