@Override public WebSocketClient build() throws Exception { SslContextFactory sslContextFactory = sslVerificationMode == SslVerificationMode.NONE ? new TrustAllSSLContextFactory() : new SslContextFactory(); sslContextFactory.setNeedClientAuth(true); sslContextFactory.setKeyStore(agentKeystore()); sslContextFactory.setKeyStorePassword(keystorePassword()); sslContextFactory.setKeyManagerPassword(keystorePassword()); if (rootCertFile != null) { sslContextFactory.setTrustStore(agentTruststore()); sslContextFactory.setTrustStorePassword(keystorePassword()); } if (sslVerificationMode == SslVerificationMode.NO_VERIFY_HOST) { sslContextFactory.setEndpointIdentificationAlgorithm(null); } WebSocketClient client = new WebSocketClient(sslContextFactory); client.setMaxIdleTimeout(systemEnvironment.getWebsocketMaxIdleTime()); return client; }
/** * {@inheritDoc} */ @Override public synchronized void connect() throws SerialException { if (!isConnected()) { try { if (client.isStopping() || client.isStopped()) { client.start(); } client.connect(this, new URI(wsUrl)); this.wait(DEFAULT_CONNECT_TIME); if (this.session == null) { client.stop(); throw new SerialException("Failed to connect to " + alias + " in " + (DEFAULT_CONNECT_TIME / 1000) + " seconds"); } // Setting the idle timeout for the client connection. client.setMaxIdleTimeout(CLIENT_MAX_IDLE_TIMEOUT); } catch (Throwable t) { throw new SerialException("Failed to establish the web socket connection.", t); } } else { logger.warn(alias + " is already connected"); } }
@Override public synchronized boolean start() { if (isStarted()) return true; log.info("Starting Jetty 9 WebSocketClient transport..."); try { if (sslContextFactory == null) webSocketClient = new WebSocketClient(); else { Constructor<WebSocketClient> c = WebSocketClient.class.getConstructor(SslContextFactory.class); webSocketClient = c.newInstance(sslContextFactory); } webSocketClient.setMaxIdleTimeout(getMaxIdleTime()); webSocketClient.setMaxTextMessageBufferSize(1024); webSocketClient.setMaxBinaryMessageBufferSize(getMaxMessageSize()); webSocketClient.setCookieStore(new HttpCookieStore()); webSocketClient.start(); log.info("Jetty 9 WebSocketClient transport started."); return true; } catch (Exception e) { webSocketClient = null; getStatusHandler().handleException(new TransportException("Could not start Jetty 9 WebSocketFactory", e)); log.error(e, "Jetty 9 WebSocketClient transport failed to start."); return false; } }
@Override public synchronized boolean start() { if (isStarted()) return true; log.info("Starting Jetty 9 WebSocketClient transport..."); try { if (sslContextFactory == null) webSocketClient = new WebSocketClient(); else { Constructor<WebSocketClient> c = WebSocketClient.class.getConstructor(SslContextFactory.class); webSocketClient = c.newInstance(sslContextFactory); } webSocketClient.setMaxIdleTimeout(getMaxIdleTime()); webSocketClient.setMaxTextMessageBufferSize(1024); webSocketClient.setMaxBinaryMessageBufferSize(getMaxMessageSize()); webSocketClient.setCookieStore(new HttpCookieStore()); webSocketClient.start(); log.info("Jetty 9 WebSocketClient transport started."); return true; } catch (Exception e) { webSocketClient = null; getStatusHandler().handleException(new TransportException("Could not start Jetty 9 WebSocketFactory", e)); log.error(e, "Jetty 9 WebSocketClient transport failed to start."); return false; } }