use of org.eclipse.jetty.websocket.servlet.WebSocketCreator in project joynr by bmwcarit.
the class WebSocketJettyServer method start.
@Override
public void start() {
if (server != null && server.isRunning()) {
return;
}
server = new Server();
ServerConnector connector;
if (address.getProtocol().equals(WebSocketProtocol.WSS)) {
SslContextFactory sslContextFactory = new SslContextFactory();
SslConnectionFactory sslConnectionFactory = new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString());
connector = new ServerConnector(server, sslConnectionFactory);
} else {
connector = new ServerConnector(server);
}
connector.setPort(address.getPort());
server.addConnector(connector);
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/");
server.setHandler(context);
ServletHolder holderEvents = new ServletHolder("ws-events", new WebSocketServlet() {
private static final long serialVersionUID = 1L;
@Override
public void configure(WebSocketServletFactory webSocketServletFactory) {
webSocketServletFactory.getPolicy().setMaxBinaryMessageSize(maxMessageSize);
webSocketServletFactory.getPolicy().setMaxTextMessageSize(maxMessageSize);
webSocketServletFactory.setCreator(new WebSocketCreator() {
@Override
public Object createWebSocket(ServletUpgradeRequest servletUpgradeRequest, ServletUpgradeResponse servletUpgradeResponse) {
CCWebSocketMessagingSkeletonSocket socket = new CCWebSocketMessagingSkeletonSocket(WebSocketJettyServer.this);
openSockets.add(socket);
return socket;
}
});
}
});
context.addServlet(holderEvents, address.getPath());
try {
server.start();
} catch (Exception t) {
logger.error("Error while starting websocket server: ", t);
}
}
Aggregations