javax.websocket.ClientEndpointConfig.Builder Java Examples
The following examples show how to use
javax.websocket.ClientEndpointConfig.Builder.
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: TestConnectionLimit.java From Tomcat8-Source-Read with MIT License | 6 votes |
@Override public void run() { WebSocketContainer wsContainer = ContainerProvider.getWebSocketContainer(); int count = 0; try { while (true) { wsContainer.connectToServer(TesterProgrammaticEndpoint.class, Builder.create().build(), uri); count = counter.incrementAndGet(); if (count % 100 == 0) { System.out.println(count + " and counting..."); } } } catch (IOException | DeploymentException ioe) { // Let thread die } }
Example #2
Source File: WebsocketClient.java From lams with GNU General Public License v2.0 | 6 votes |
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); } }