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 static ClientEndpointConfig getDefaultConfig() { Builder b = ClientEndpointConfig.Builder.create(); return b.build(); }