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, 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(); } }
/** * Start embedded server unless "tyrus.test.host" system property is specified. * * @return new {@link Server} instance or {@code null} if "tyrus.test.host" system property is * set. */ private Server startServer() throws DeploymentException { final String host = System.getProperty("tyrus.test.host"); if (host == null) { final Server server = new Server(DEFAULT_HOST, DEFAULT_PORT, CONTEXT_PATH, null, endpointClasses); server.start(); return server; } else { return null; } }
/** * Start embedded server unless "tyrus.test.host" system property is specified. * * @return new {@link Server} instance or {@code null} if "tyrus.test.host" system property is * set. */ protected Server startServer(Class<?>... endpointClasses) throws DeploymentException { final String host = System.getProperty("tyrus.test.host"); if (host == null) { final Server server = new Server(defaultHost, defaultPort, contextPath, serverProperties, endpointClasses); server.start(); return server; } else { return null; } }
@Test public void testErrorOnClose() { Server server = new Server(OnCloseErrorTestEndpoint.class); try { server.start(); final ClientEndpointConfig cec = ClientEndpointConfig.Builder.create().build(); messageLatch = new CountDownLatch(1); ClientManager client = ClientManager.createClient(); final Session session = client.connectToServer( new TestEndpointAdapter() { @Override public EndpointConfig getEndpointConfig() { return cec; } @Override public void onOpen(Session session) { session.addMessageHandler(new TestTextMessageHandler(this)); } @Override public void onMessage(String message) { // do nothing } }, cec, new URI("ws://localhost:8025/websockets/tests/close")); // TODO: is this really needed? Cannot we somehow force underlying protocol impl to connect // immediately // TODO: after connectToServer call? messageLatch.await(1, TimeUnit.SECONDS); session.close(); // TODO: is this really needed? Cannot we somehow force underlying protocol impl to connect // immediately // TODO: after close call? messageLatch.await(1, TimeUnit.SECONDS); assertTrue(OnCloseErrorTestEndpoint.session != null); assertTrue(OnCloseErrorTestEndpoint.throwable != null); assertEquals("testException", OnCloseErrorTestEndpoint.throwable.getMessage()); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e.getMessage(), e); } finally { server.stop(); } }
@Test public void testErrorOnMessageProgrammatic() { Server server = new Server(OnMessageExceptionEndpointServerApplicationConfig.class); try { server.start(); final ClientEndpointConfig cec = ClientEndpointConfig.Builder.create().build(); messageLatch = new CountDownLatch(1); ClientManager client = ClientManager.createClient(); client.connectToServer( new TestEndpointAdapter() { @Override public EndpointConfig getEndpointConfig() { return cec; } @Override public void onOpen(Session session) { try { session.getBasicRemote().sendText("Do or do not, there is no try."); } catch (IOException e) { fail(); } } @Override public void onMessage(String message) { // nothing } }, cec, new URI("ws://localhost:8025/websockets/tests/open")); // TODO: is this really needed? Cannot we somehow force underlying protocol impl to connect // immediately // TODO: after connectToServer call? messageLatch.await(1, TimeUnit.SECONDS); assertTrue(OnMessageExceptionEndpoint.session != null); assertTrue(OnMessageExceptionEndpoint.throwable != null); assertEquals("testException", OnMessageExceptionEndpoint.throwable.getMessage()); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e.getMessage(), e); } finally { server.stop(); } }
public static void runServer() { Server server = new Server("localhost", 8025, "/websockets", null, ServerEndPoints.class); try { server.start(); BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); System.out.print("Please press a key to stop the server."); reader.readLine(); } catch (Exception e) { throw new RuntimeException(e); } finally { server.stop(); } }
@Before public void setup() throws DeploymentException { server = new Server( "localhost", 8025, "/websockets", new HashMap<String, Object>(), ElizaServerEndpoint.class); server.start(); }
private void stopServer(Server server) { if (server != null) { server.stop(); } }
@After public void close() { server.stop(); }
/** * Stop the server. * * @param server to be stopped. */ protected void stopServer(Server server) { if (server != null) { server.stop(); } }
@Test(expected = DeploymentException.class) public void testEquivalentPaths() throws DeploymentException { Server server = new Server(WSL1ParamServer.class, AEndpoint.class); server.start(); }