is it possible to run WebSocketHandler and WebAppContext together? I'm using latest version 9.2.1.v20140609
. I tried configuration below, but on Websocket call to localhost:8080/
WebAppContext intercepts call. Here is my Launcher:
public static void main(String[] args) throws Exception
{
ServerConnector connector = new ServerConnector(server);
connector.setPort(8080);
server.addConnector(connector);
WebAppContext context = new WebAppContext("webapp", "/");
// Setting up browser caching. Binds params for org.eclipse.jetty.servlet.DefaultServlet.init()
context.getInitParams().put("org.eclipse.jetty.servlet.Default.etags", "true");
context.getInitParams().put("org.eclipse.jetty.servlet.Default.cacheControl", "public, max-age=0");
// Fix for Windows, so Jetty doesn't lock files
if (System.getProperty("os.name").toLowerCase().contains("windows")) {
context.getInitParams().put("org.eclipse.jetty.servlet.Default.useFileMappedBuffer", "false");
}
// Will throw an exception when will be unable to start server for some reason
context.setThrowUnavailableOnStartupException(true);
Broker broker = new Broker();
// Implementation of org.eclipse.jetty.websocket.server.WebSocketHandler
WebSocketHandler socketHandler = new com.namespace.websocket.Handler(broker);
HandlerCollection handlerCollection = new HandlerCollection();
handlerCollection.setHandlers(new Handler[] {context, socketHandler});
server.setHandler(handlerCollection);
// Remove Server:Jetty(9...) from Response Headers
removeServerVersionFromHeaders(server);
server.start();
}
I can run from launcher multiple jetty instances and just wire WebSocket handler to some 5555
port, but preferably i would like to keep one Jetty instance, and maybe use /ws
handler to manage WebSocket connections