use of org.eclipse.jetty.websocket.server.pathmap.ServletPathSpec in project spark by perwendel.
the class WebSocketServletContextHandlerFactory method create.
/**
* Creates a new websocket servlet context handler.
*
* @param webSocketHandlers webSocketHandlers
* @param webSocketIdleTimeoutMillis webSocketIdleTimeoutMillis
* @return a new websocket servlet context handler or 'null' if creation failed.
*/
public static ServletContextHandler create(Map<String, WebSocketHandlerWrapper> webSocketHandlers, Optional<Integer> webSocketIdleTimeoutMillis) {
ServletContextHandler webSocketServletContextHandler = null;
if (webSocketHandlers != null) {
try {
webSocketServletContextHandler = new ServletContextHandler(null, "/", true, false);
WebSocketUpgradeFilter webSocketUpgradeFilter = WebSocketUpgradeFilter.configureContext(webSocketServletContextHandler);
if (webSocketIdleTimeoutMillis.isPresent()) {
webSocketUpgradeFilter.getFactory().getPolicy().setIdleTimeout(webSocketIdleTimeoutMillis.get());
}
for (String path : webSocketHandlers.keySet()) {
WebSocketCreator webSocketCreator = WebSocketCreatorFactory.create(webSocketHandlers.get(path));
webSocketUpgradeFilter.addMapping(new ServletPathSpec(path), webSocketCreator);
}
} catch (Exception ex) {
logger.error("creation of websocket context handler failed.", ex);
webSocketServletContextHandler = null;
}
}
return webSocketServletContextHandler;
}
Aggregations