e.printStackTrace(); } catch (DeploymentException e) { e.printStackTrace();
@WebListener public class MyApplication implements ServletContextListener { private final static String SERVER_CONTAINER_ATTRIBUTE = "javax.websocket.server.ServerContainer"; @Override public void contextInitialized(ServletContextEvent sce) { ServletContext container = sce.getServletContext(); final ServerContainer serverContainer = (ServerContainer) container.getAttribute(SERVER_CONTAINER_ATTRIBUTE); try { serverContainer.addEndpoint(new MyEndpointConfig(MyEndpoint.class, "/wstest")); } catch (DeploymentException e) { e.printStackTrace(); } } }
private void connect(String url, String clentid) { WebSocketContainer container = ContainerProvider.getWebSocketContainer(); if (!url.endsWith("/")) { url += "/" + clentid; } else { url += clentid; } logger.info("Connecting to " + url); try { clientid = clentid; session = container.connectToServer(MessageClient.class, URI.create(url)); } catch (DeploymentException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
public static void main(String[] args) { if (args.length < 4) { System.out.println( "Please provide: (<hostname>, <port>, <websockets root path>, <;-sep fully qualfied classnames of" + " your bean>) in the command line"); System.out.println("e.g. localhost 8021 /websockets/myapp myapp.Bean1;myapp.Bean2"); System.exit(1); } Set<Class<?>> beanClasses = getClassesFromString(args[3]); int port = Integer.parseInt(args[1]); String hostname = args[0]; String wsroot = args[2]; Server server = new Server(hostname, port, wsroot, null, beanClasses); try { server.start(); System.out.println("Press any key to stop the WebSocket server..."); //noinspection ResultOfMethodCallIgnored System.in.read(); } catch (IOException ioe) { System.err.println("IOException during server run"); ioe.printStackTrace(); } catch (DeploymentException de) { de.printStackTrace(); } finally { server.stop(); } }
public static void main(String[] args) { if (args.length < 4) { System.out.println( "Please provide: (<hostname>, <port>, <websockets root path>, <;-sep fully qualfied classnames of" + " your bean>) in the command line"); System.out.println("e.g. localhost 8021 /websockets/myapp myapp.Bean1;myapp.Bean2"); System.exit(1); } Set<Class<?>> beanClasses = getClassesFromString(args[3]); int port = Integer.parseInt(args[1]); String hostname = args[0]; String wsroot = args[2]; Server server = new Server(hostname, port, wsroot, null, beanClasses); try { server.start(); System.out.println("Press any key to stop the WebSocket server..."); //noinspection ResultOfMethodCallIgnored System.in.read(); } catch (IOException ioe) { System.err.println("IOException during server run"); ioe.printStackTrace(); } catch (DeploymentException de) { de.printStackTrace(); } finally { server.stop(); } }