org.eclipse.jetty.websocket.server.WebSocketHandler Java Examples
The following examples show how to use
org.eclipse.jetty.websocket.server.WebSocketHandler.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MinicapJettyServer.java From android-uiconductor with Apache License 2.0 | 6 votes |
public void runServer() { if (server.isStarted()) { return; } System.out.println("server port: " + port); WebSocketHandler wsHandler = new WebSocketHandler() { @Override public void configure(WebSocketServletFactory factory) { factory.register(MinicapWebSocketHandler.class); } }; server.setHandler(wsHandler); try { server.start(); server.join(); } catch (Exception e) { logger.warning(e.getMessage()); } }
Example #2
Source File: Jetty9WebSocketDestination.java From cxf with Apache License 2.0 | 6 votes |
public synchronized WebSocketServletFactory getWebSocketFactory(Server server) { if (webSocketFactory == null) { webSockethandler = new WebSocketHandler() { @Override public void configure(WebSocketServletFactory factory) { } }; try { webSockethandler.setServer(server); webSockethandler.start(); } catch (Exception e) { e.printStackTrace(); } webSocketFactory = webSockethandler.getWebSocketFactory(); webSocketFactory.setCreator(new Creator()); } return webSocketFactory; }
Example #3
Source File: PHttpServer.java From jphp with Apache License 2.0 | 6 votes |
@Signature public void addWebSocket(Environment env, String path, ArrayMemory _handlers) { WebSocketParam param = _handlers.toBean(env, WebSocketParam.class); ContextHandler contextHandler = new ContextHandler(path); contextHandler.setHandler(new WebSocketHandler() { @Override public void configure(WebSocketServletFactory factory) { factory.setCreator(new WebSocketCreator() { @Override public Object createWebSocket(ServletUpgradeRequest req, ServletUpgradeResponse resp) { return new WebSocket(env, param); } }); } }); handlers.addHandler(contextHandler); }
Example #4
Source File: StartUpInit.java From android-uiconductor with Apache License 2.0 | 5 votes |
private void initLogServer() { if (logServerThread != null && logServerThread.isAlive()) { logServerThread.interrupt(); } if (logServer != null && logServer.isStarted()) { try { logServer.stop(); } catch (Exception e) { logger.warning(e.getMessage()); } } logServerThread = new Thread( () -> { logServer = new Server(8888); WebSocketHandler wsHandler = new WebSocketHandler() { @Override public void configure(WebSocketServletFactory factory) { factory.register(LogWebSocketHandler.class); } }; logServer.setHandler(wsHandler); try { logServer.start(); logServer.join(); } catch (Exception e) { logger.warning(e.getMessage()); } }); logServerThread.start(); }
Example #5
Source File: WebServer.java From tracing-framework with BSD 3-Clause "New" or "Revised" License | 5 votes |
private static Server setupServer() throws Exception { // String webDir = "target/classes/webui"; // String webDir = "src/main/resources/webui"; String webDir = WebServer.class.getClassLoader().getResource("webui").toExternalForm(); log.info("Base webdir is {}", webDir); int httpPort = ConfigFactory.load().getInt("resource-reporting.visualization.webui-port"); log.info("Resource reporting web ui port is ", httpPort); // Create Jetty server Server server = new Server(httpPort); ResourceHandler resource_handler = new ResourceHandler(); resource_handler.setDirectoriesListed(true); resource_handler.setWelcomeFiles(new String[] { "filter.html" }); resource_handler.setResourceBase(webDir); WebSocketHandler wsHandler = new WebSocketHandler.Simple(PubSubProxyWebSocket.class); ContextHandler context = new ContextHandler(); context.setContextPath("/ws"); context.setHandler(wsHandler); HandlerList handlers = new HandlerList(); handlers.setHandlers(new Handler[] { context, resource_handler, new DefaultHandler() }); server.setHandler(handlers); ClusterResources.subscribeToAll(callback); return server; }
Example #6
Source File: DataServer.java From dawnsci with Eclipse Public License 1.0 | 4 votes |
public void start(boolean block) throws Exception { this.server = new Server(); ServerConnector connector = new ServerConnector(server); connector.setPort(getPort()); connector.setReuseAddress(true); server.addConnector(connector); // We enable sessions on the server so that // we can cache LoaderFactories to a given session. // The loader factory therefore needs a non-global // data soft reference cache. ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); context.setContextPath("/"); server.setHandler(context); // Make individual servlets // Slicing (large data in binary http) ServletHolder holderSlice = new ServletHolder("slice", SliceServlet.class); context.addServlet(holderSlice, "/slice/*"); // Doing events, like data changing shape. // FIXME Should not be needed WebSocketHandler wsHandler = new WebSocketHandler() { @Override public void configure(WebSocketServletFactory factory) { factory.register(FileMonitorSocket.class); } }; context.setHandler(wsHandler); // FIXME End should not be needed. ServletHolder holderInfo = new ServletHolder("info", InfoServlet.class); context.addServlet(holderInfo, "/info/*"); ServletHolder holderTree = new ServletHolder("tree", TreeServlet.class); context.addServlet(holderTree, "/tree/*"); // Events json objects to notify of problems. ServletHolder holderEvent = new ServletHolder("event", EventServlet.class); context.addServlet(holderEvent, "/event/*"); server.start(); if (block) server.join(); }