private void connect() throws Exception { while (sessionServer != null && !sessionServer.isOpen()) { break; } SSLContext context = createSSLContext(); SecureSocketClient endpoint = new SecureSocketClient(); Configurator configurator = new Configurator() { @Override public void beforeRequest(Map<String, List<String>> headers) { headers.put(SEC_WEB_SOCKET_PROTOCOL_STRING, singletonList("configured-proto")); } }; ClientEndpointConfig clientEndpointConfig = create().configurator(configurator) .preferredSubprotocols(asList(new String[] { "foo", "bar", "configured-proto" })).build(); clientEndpointConfig.getUserProperties().put(SSL_CONTEXT, context); final WebSocketContainer serverContainer = getWebSocketContainer(); URI uri = new URI("wss://127.0.0.1:8443/secure-test/session"); serverContainer.connectToServer(endpoint, clientEndpointConfig, uri); awake(); }
public WebsocketClient(String uri, final String sessionID, MessageHandler.Whole<String> messageHandler) throws IOException { // add session ID so the request gets through LAMS security Builder configBuilder = ClientEndpointConfig.Builder.create(); configBuilder.configurator(new Configurator() { @Override public void beforeRequest(Map<String, List<String>> headers) { headers.put("Cookie", Arrays.asList("JSESSIONID=" + sessionID)); } }); ClientEndpointConfig clientConfig = configBuilder.build(); this.websocketEndpoint = new WebsocketEndpoint(messageHandler); WebSocketContainer container = ContainerProvider.getWebSocketContainer(); try { container.connectToServer(websocketEndpoint, clientConfig, new URI(uri)); } catch (DeploymentException | URISyntaxException e) { throw new IOException("Error while connecting to websocket server", e); } }
public void setConfigurator(Configurator configurator) { this.configBuilder.configurator(configurator); }