org.apache.tomcat.websocket.TesterMessageCountClient.TesterEndpoint Java Examples
The following examples show how to use
org.apache.tomcat.websocket.TesterMessageCountClient.TesterEndpoint.
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: TestWsPingPongMessages.java From Tomcat8-Source-Read with MIT License | 5 votes |
@Test public void testPingPongMessages() throws Exception { Tomcat tomcat = getTomcatInstance(); // No file system docBase required Context ctx = tomcat.addContext("", null); ctx.addApplicationListener(TesterEchoServer.Config.class.getName()); Tomcat.addServlet(ctx, "default", new DefaultServlet()); ctx.addServletMappingDecoded("/", "default"); tomcat.start(); WebSocketContainer wsContainer = ContainerProvider .getWebSocketContainer(); Session wsSession = wsContainer.connectToServer( TesterProgrammaticEndpoint.class, ClientEndpointConfig.Builder .create().build(), new URI("ws://localhost:" + getPort() + TesterEchoServer.Config.PATH_ASYNC)); CountDownLatch latch = new CountDownLatch(1); TesterEndpoint tep = (TesterEndpoint) wsSession.getUserProperties() .get("endpoint"); tep.setLatch(latch); PongMessageHandler handler = new PongMessageHandler(latch); wsSession.addMessageHandler(handler); wsSession.getBasicRemote().sendPing(applicationData); boolean latchResult = handler.getLatch().await(10, TimeUnit.SECONDS); Assert.assertTrue(latchResult); Assert.assertArrayEquals(applicationData.array(), (handler.getMessages().peek()).getApplicationData().array()); }
Example #2
Source File: TestWsPingPongMessages.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
@Test public void testPingPongMessages() throws Exception { Tomcat tomcat = getTomcatInstance(); // No file system docBase required Context ctx = tomcat.addContext("", null); ctx.addApplicationListener(TesterEchoServer.Config.class.getName()); Tomcat.addServlet(ctx, "default", new DefaultServlet()); ctx.addServletMapping("/", "default"); tomcat.start(); WebSocketContainer wsContainer = ContainerProvider .getWebSocketContainer(); tomcat.start(); Session wsSession = wsContainer.connectToServer( TesterProgrammaticEndpoint.class, ClientEndpointConfig.Builder .create().build(), new URI("ws://localhost:" + getPort() + TesterEchoServer.Config.PATH_ASYNC)); CountDownLatch latch = new CountDownLatch(1); TesterEndpoint tep = (TesterEndpoint) wsSession.getUserProperties() .get("endpoint"); tep.setLatch(latch); PongMessageHandler handler = new PongMessageHandler(latch); wsSession.addMessageHandler(handler); wsSession.getBasicRemote().sendPing(applicationData); boolean latchResult = handler.getLatch().await(10, TimeUnit.SECONDS); Assert.assertTrue(latchResult); Assert.assertArrayEquals(applicationData.array(), (handler.getMessages().peek()).getApplicationData().array()); }
Example #3
Source File: TestWsPingPongMessages.java From tomcatsrc with Apache License 2.0 | 5 votes |
@Test public void testPingPongMessages() throws Exception { Tomcat tomcat = getTomcatInstance(); // No file system docBase required Context ctx = tomcat.addContext("", null); ctx.addApplicationListener(TesterEchoServer.Config.class.getName()); Tomcat.addServlet(ctx, "default", new DefaultServlet()); ctx.addServletMapping("/", "default"); tomcat.start(); WebSocketContainer wsContainer = ContainerProvider .getWebSocketContainer(); tomcat.start(); Session wsSession = wsContainer.connectToServer( TesterProgrammaticEndpoint.class, ClientEndpointConfig.Builder .create().build(), new URI("ws://localhost:" + getPort() + TesterEchoServer.Config.PATH_ASYNC)); CountDownLatch latch = new CountDownLatch(1); TesterEndpoint tep = (TesterEndpoint) wsSession.getUserProperties() .get("endpoint"); tep.setLatch(latch); PongMessageHandler handler = new PongMessageHandler(latch); wsSession.addMessageHandler(handler); wsSession.getBasicRemote().sendPing(applicationData); boolean latchResult = handler.getLatch().await(10, TimeUnit.SECONDS); Assert.assertTrue(latchResult); Assert.assertArrayEquals(applicationData.array(), (handler.getMessages().peek()).getApplicationData().array()); }