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().preferredSubprotocols(Arrays.asList("sp3"))
.build(), new URI("ws://localhost:" + getPort()
+ SubProtocolsEndpoint.PATH_BASIC));
Assert.assertTrue(wsSession.isOpen());
if (wsSession.getNegotiatedSubprotocol() != null) {
Assert.assertTrue(wsSession.getNegotiatedSubprotocol().isEmpty());
}
wsSession.close();
wsSession = wsContainer.connectToServer(
TesterProgrammaticEndpoint.class, ClientEndpointConfig.Builder
.create().preferredSubprotocols(Arrays.asList("sp2"))
.build(), new URI("ws://localhost:" + getPort()
+ SubProtocolsEndpoint.PATH_BASIC));