org.apache.tomcat.websocket.pojo.TesterUtil.SimpleClient Java Examples
The following examples show how to use
org.apache.tomcat.websocket.pojo.TesterUtil.SimpleClient.
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: TestWsRemoteEndpointImplServer.java From Tomcat8-Source-Read with MIT License | 6 votes |
@Test public void testClientDropsConnection() throws Exception { Tomcat tomcat = getTomcatInstance(); // No file system docBase required Context ctx = tomcat.addContext("", null); ctx.addApplicationListener(Bug58624Config.class.getName()); Tomcat.addServlet(ctx, "default", new DefaultServlet()); ctx.addServletMappingDecoded("/", "default"); WebSocketContainer wsContainer = ContainerProvider.getWebSocketContainer(); tomcat.start(); SimpleClient client = new SimpleClient(); URI uri = new URI("ws://localhost:" + getPort() + Bug58624Config.PATH); Session session = wsContainer.connectToServer(client, uri); // Break point A required on following line session.close(); }
Example #2
Source File: TestWsRemoteEndpointImplServer.java From Tomcat7.0.67 with Apache License 2.0 | 6 votes |
@Test public void testClientDropsConnection() throws Exception { Tomcat tomcat = getTomcatInstance(); // No file system docBase required Context ctx = tomcat.addContext("", null); ctx.addApplicationListener(Bug58624Config.class.getName()); Tomcat.addServlet(ctx, "default", new DefaultServlet()); ctx.addServletMapping("/", "default"); WebSocketContainer wsContainer = ContainerProvider.getWebSocketContainer(); tomcat.start(); SimpleClient client = new SimpleClient(); URI uri = new URI("ws://localhost:" + getPort() + Bug58624Config.PATH); Session session = wsContainer.connectToServer(client, uri); // Break point A required on following line session.close(); }
Example #3
Source File: TestWsRemoteEndpointImplServer.java From tomcatsrc with Apache License 2.0 | 6 votes |
@Test public void testClientDropsConnection() throws Exception { Tomcat tomcat = getTomcatInstance(); // No file system docBase required Context ctx = tomcat.addContext("", null); ctx.addApplicationListener(Bug58624Config.class.getName()); Tomcat.addServlet(ctx, "default", new DefaultServlet()); ctx.addServletMapping("/", "default"); WebSocketContainer wsContainer = ContainerProvider.getWebSocketContainer(); tomcat.start(); SimpleClient client = new SimpleClient(); URI uri = new URI("ws://localhost:" + getPort() + Bug58624Config.PATH); Session session = wsContainer.connectToServer(client, uri); // Break point A required on following line session.close(); }
Example #4
Source File: TestWsServerContainer.java From Tomcat8-Source-Read with MIT License | 5 votes |
@Test public void testBug58232() throws Exception { Tomcat tomcat = getTomcatInstance(); // No file system docBase required Context ctx = tomcat.addContext("", null); ctx.addApplicationListener(Bug54807Config.class.getName()); Tomcat.addServlet(ctx, "default", new DefaultServlet()); ctx.addServletMappingDecoded("/", "default"); WebSocketContainer wsContainer = ContainerProvider.getWebSocketContainer(); tomcat.start(); Assert.assertEquals(LifecycleState.STARTED, ctx.getState()); SimpleClient client = new SimpleClient(); URI uri = new URI("ws://localhost:" + getPort() + "/echoBasic"); try (Session session = wsContainer.connectToServer(client, uri);) { CountDownLatch latch = new CountDownLatch(1); BasicText handler = new BasicText(latch); session.addMessageHandler(handler); session.getBasicRemote().sendText("echoBasic"); boolean latchResult = handler.getLatch().await(10, TimeUnit.SECONDS); Assert.assertTrue(latchResult); Queue<String> messages = handler.getMessages(); Assert.assertEquals(1, messages.size()); for (String message : messages) { Assert.assertEquals("echoBasic", message); } } }
Example #5
Source File: TestPojoMethodMapping.java From Tomcat8-Source-Read with MIT License | 4 votes |
@Test public void test() throws Exception { // Set up utility classes Server server = new Server(); SingletonConfigurator.setInstance(server); ServerConfigListener.setPojoClazz(Server.class); Tomcat tomcat = getTomcatInstance(); // No file system docBase required Context ctx = tomcat.addContext("", null); ctx.addApplicationListener(ServerConfigListener.class.getName()); Tomcat.addServlet(ctx, "default", new DefaultServlet()); ctx.addServletMappingDecoded("/", "default"); WebSocketContainer wsContainer = ContainerProvider.getWebSocketContainer(); tomcat.start(); SimpleClient client = new SimpleClient(); URI uri = new URI("ws://localhost:" + getPort() + "/" + PARAM_ONE + "/" + PARAM_TWO + "/" + PARAM_THREE); Session session = wsContainer.connectToServer(client, uri); session.getBasicRemote().sendText("NO-OP"); session.close(); // Give server 20s to close. 5s should be plenty but the Gump VM is slow int count = 0; while (count < 200) { if (server.isClosed()) { break; } count++; Thread.sleep(100); } if (count == 50) { Assert.fail("Server did not process an onClose event within 5 " + "seconds of the client sending a close message"); } // Check no errors List<String> errors = server.getErrors(); for (String error : errors) { System.err.println(error); } Assert.assertEquals("Found errors", 0, errors.size()); }
Example #6
Source File: TestPojoMethodMapping.java From Tomcat7.0.67 with Apache License 2.0 | 4 votes |
@Test public void test() throws Exception { // Set up utility classes Server server = new Server(); SingletonConfigurator.setInstance(server); ServerConfigListener.setPojoClazz(Server.class); Tomcat tomcat = getTomcatInstance(); // No file system docBase required Context ctx = tomcat.addContext("", null); ctx.addApplicationListener(ServerConfigListener.class.getName()); Tomcat.addServlet(ctx, "default", new DefaultServlet()); ctx.addServletMapping("/", "default"); WebSocketContainer wsContainer = ContainerProvider.getWebSocketContainer(); tomcat.start(); SimpleClient client = new SimpleClient(); URI uri = new URI("ws://localhost:" + getPort() + "/" + PARAM_ONE + "/" + PARAM_TWO + "/" + PARAM_THREE); Session session = wsContainer.connectToServer(client, uri); session.getBasicRemote().sendText("NO-OP"); session.close(); // Give server 20s to close. 5s should be plenty but the Gump VM is slow int count = 0; while (count < 200) { if (server.isClosed()) { break; } count++; Thread.sleep(100); } if (count == 50) { Assert.fail("Server did not process an onClose event within 5 " + "seconds of the client sending a close message"); } // Check no errors List<String> errors = server.getErrors(); for (String error : errors) { System.err.println(error); } Assert.assertEquals("Found errors", 0, errors.size()); }
Example #7
Source File: TestWsServerContainer.java From Tomcat7.0.67 with Apache License 2.0 | 4 votes |
@Test public void testBug58232() throws Exception { Tomcat tomcat = getTomcatInstance(); // No file system docBase required Context ctx = tomcat.addContext("", null); ctx.addApplicationListener(Bug54807Config.class.getName()); Tomcat.addServlet(ctx, "default", new DefaultServlet()); ctx.addServletMapping("/", "default"); WebSocketContainer wsContainer = ContainerProvider.getWebSocketContainer(); tomcat.start(); Assert.assertEquals(LifecycleState.STARTED, ctx.getState()); SimpleClient client = new SimpleClient(); URI uri = new URI("ws://localhost:" + getPort() + "/echoBasic"); Session session = null; try { session = wsContainer.connectToServer(client, uri); CountDownLatch latch = new CountDownLatch(1); BasicText handler = new BasicText(latch); session.addMessageHandler(handler); session.getBasicRemote().sendText("echoBasic"); boolean latchResult = handler.getLatch().await(10, TimeUnit.SECONDS); Assert.assertTrue(latchResult); Queue<String> messages = handler.getMessages(); Assert.assertEquals(1, messages.size()); for (String message : messages) { Assert.assertEquals("echoBasic", message); } } finally { if (session != null) { session.close(); } } }
Example #8
Source File: TestPojoMethodMapping.java From tomcatsrc with Apache License 2.0 | 4 votes |
@Test public void test() throws Exception { // Set up utility classes Server server = new Server(); SingletonConfigurator.setInstance(server); ServerConfigListener.setPojoClazz(Server.class); Tomcat tomcat = getTomcatInstance(); // No file system docBase required Context ctx = tomcat.addContext("", null); ctx.addApplicationListener(ServerConfigListener.class.getName()); Tomcat.addServlet(ctx, "default", new DefaultServlet()); ctx.addServletMapping("/", "default"); WebSocketContainer wsContainer = ContainerProvider.getWebSocketContainer(); tomcat.start(); SimpleClient client = new SimpleClient(); URI uri = new URI("ws://localhost:" + getPort() + "/" + PARAM_ONE + "/" + PARAM_TWO + "/" + PARAM_THREE); Session session = wsContainer.connectToServer(client, uri); session.getBasicRemote().sendText("NO-OP"); session.close(); // Give server 20s to close. 5s should be plenty but the Gump VM is slow int count = 0; while (count < 200) { if (server.isClosed()) { break; } count++; Thread.sleep(100); } if (count == 50) { Assert.fail("Server did not process an onClose event within 5 " + "seconds of the client sending a close message"); } // Check no errors List<String> errors = server.getErrors(); for (String error : errors) { System.err.println(error); } Assert.assertEquals("Found errors", 0, errors.size()); }
Example #9
Source File: TestWsServerContainer.java From tomcatsrc with Apache License 2.0 | 4 votes |
@Test public void testBug58232() throws Exception { Tomcat tomcat = getTomcatInstance(); // No file system docBase required Context ctx = tomcat.addContext("", null); ctx.addApplicationListener(Bug54807Config.class.getName()); Tomcat.addServlet(ctx, "default", new DefaultServlet()); ctx.addServletMapping("/", "default"); WebSocketContainer wsContainer = ContainerProvider.getWebSocketContainer(); tomcat.start(); Assert.assertEquals(LifecycleState.STARTED, ctx.getState()); SimpleClient client = new SimpleClient(); URI uri = new URI("ws://localhost:" + getPort() + "/echoBasic"); Session session = null; try { session = wsContainer.connectToServer(client, uri); CountDownLatch latch = new CountDownLatch(1); BasicText handler = new BasicText(latch); session.addMessageHandler(handler); session.getBasicRemote().sendText("echoBasic"); boolean latchResult = handler.getLatch().await(10, TimeUnit.SECONDS); Assert.assertTrue(latchResult); Queue<String> messages = handler.getMessages(); Assert.assertEquals(1, messages.size()); for (String message : messages) { Assert.assertEquals("echoBasic", message); } } finally { if (session != null) { session.close(); } } }