private URI stringToUri(String endPoint) { try { return new URI(endPoint); } catch (URISyntaxException e) { throw new CloudException("Unable to parse Loggregator endpoint " + endPoint); } } }
public StreamingLogTokenImpl connectToLoggregator(String endpoint, String mode, UUID appId, ApplicationLogListener listener, ClientEndpointConfig.Configurator configurator) { URI loggregatorUri = loggregatorStreamUriTemplate.expand(endpoint, mode, appId); try { WebSocketContainer container = ContainerProvider.getWebSocketContainer(); ClientEndpointConfig config = buildClientConfig(configurator); Session session = container.connectToServer(new LoggregatorEndpoint(listener), config, loggregatorUri); return new StreamingLogTokenImpl(session); } catch (DeploymentException e) { throw new CloudException(e); } catch (IOException e) { throw new CloudException(e); } }
@Override public void onClose(Session session, CloseReason closeReason) { if (closeReason.getCloseCode() == CloseReason.CloseCodes.NORMAL_CLOSURE || closeReason.getCloseCode() == CloseReason.CloseCodes.GOING_AWAY) { listener.onComplete(); } else { listener.onError(new CloudException("Loggregrator connection closed unexpectedly " + closeReason)); } }
private SSLContext buildSslContext() { try { SSLContextBuilder contextBuilder = new SSLContextBuilder().useTLS() .loadTrustMaterial(null, new TrustSelfSignedStrategy()); return contextBuilder.build(); } catch (GeneralSecurityException e) { throw new CloudException(e); } }