@Test public void clientEndpointConfigWithUserProperties() throws Exception { Map<String,Object> userProperties = Collections.singletonMap("foo", "bar"); URI uri = new URI("ws://localhost/abc"); this.wsClient.setUserProperties(userProperties); this.wsClient.doHandshake(this.wsHandler, this.headers, uri).get(); ArgumentCaptor<ClientEndpointConfig> captor = ArgumentCaptor.forClass(ClientEndpointConfig.class); verify(this.wsContainer).connectToServer(any(Endpoint.class), captor.capture(), any(URI.class)); ClientEndpointConfig endpointConfig = captor.getValue(); assertEquals(userProperties, endpointConfig.getUserProperties()); }
@Test public void standardWebSocketClientConfiguratorInsertsHandshakeHeaders() throws Exception { URI uri = new URI("ws://localhost/abc"); this.headers.add("foo", "bar"); this.wsClient.doHandshake(this.wsHandler, this.headers, uri).get(); ArgumentCaptor<ClientEndpointConfig> captor = ArgumentCaptor.forClass(ClientEndpointConfig.class); verify(this.wsContainer).connectToServer(any(Endpoint.class), captor.capture(), any(URI.class)); ClientEndpointConfig endpointConfig = captor.getValue(); Map<String, List<String>> headers = new HashMap<>(); endpointConfig.getConfigurator().beforeRequest(headers); assertEquals(1, headers.size()); }
@Test public void clientEndpointConfig() throws Exception { URI uri = new URI("ws://localhost/abc"); List<String> protocols = Collections.singletonList("abc"); this.headers.setSecWebSocketProtocol(protocols); this.wsClient.doHandshake(this.wsHandler, this.headers, uri).get(); ArgumentCaptor<ClientEndpointConfig> captor = ArgumentCaptor.forClass(ClientEndpointConfig.class); verify(this.wsContainer).connectToServer(any(Endpoint.class), captor.capture(), any(URI.class)); ClientEndpointConfig endpointConfig = captor.getValue(); assertEquals(protocols, endpointConfig.getPreferredSubprotocols()); }
clientEndpointConfiguration.getPreferredSubprotocols(), clientEndpointConfiguration.getExtensions()); clientEndpointConfiguration.getConfigurator(). beforeRequest(reqHeaders); if (secure) { SSLEngine sslEngine = createSSLEngine( clientEndpointConfiguration.getUserProperties()); channel = new AsyncChannelWrapperSecure(socketChannel, sslEngine); } else { String timeoutValue = (String) clientEndpointConfiguration.getUserProperties().get( IO_TIMEOUT_MS_PROPERTY); if (timeoutValue != null) { clientEndpointConfiguration.getConfigurator(). afterResponse(handshakeResponse);
List<Extension> extensions = clientEndpointConfiguration.getExtensions(); List<String> subProtocols = clientEndpointConfiguration.getPreferredSubprotocols(); Map<String, Object> userProperties = clientEndpointConfiguration.getUserProperties();
clientEndpointConfiguration.getConfigurator().beforeRequest(reqHeaders); if (Constants.DEFAULT_ORIGIN_HEADER_VALUE != null && !reqHeaders.containsKey(Constants.ORIGIN_HEADER_NAME)) { Map<String,Object> userProperties = clientEndpointConfiguration.getUserProperties(); clientEndpointConfiguration.getConfigurator().afterResponse(handshakeResponse);
private void prepareHandshake(HandShake handshake) { List<Extension> grizzlyExtensions = new ArrayList<Extension>(); for (javax.websocket.Extension e : configuration.getExtensions()) { final Extension grizzlyExtension = new Extension(e.getName()); for (javax.websocket.Extension.Parameter p : e.getParameters()) { grizzlyExtension.getParameters().add(new Extension.Parameter(p.getName(), p.getValue())); } grizzlyExtensions.add(grizzlyExtension); } handshake.setExtensions(grizzlyExtensions); handshake.setSubProtocols(configuration.getPreferredSubprotocols()); handshake.setResponseListener(new HandShake.HandShakeResponseListener() { @Override public void onResponseHeaders(final Map<String, String> originalHeaders) { String value = originalHeaders.get(WebSocketEngine.SEC_WS_EXTENSIONS_HEADER); if (value != null) { responseExtensions.addAll(TyrusExtension.fromString(Arrays.asList(value))); } listener.onResponseHeaders(originalHeaders); } @Override public void onError(HandshakeException exception) { listener.onError(exception); onConnectLatch.countDown(); } }); handshake.prepareRequest(); configuration.getConfigurator().beforeRequest(handshake.getRequest().getHeaders()); }
.getExtensions()) { final String responseExtensionName = responseExtension.getName(); if (responseExtensionName != null && responseExtensionName.equals(installedExtension.getName())) { extensions, debugContext); ((ClientEndpointConfig) endpointWrapper.getEndpointConfig()).getConfigurator().afterResponse(upgradeResponse);
clientEndpointConfiguration.getPreferredSubprotocols(), clientEndpointConfiguration.getExtensions()); clientEndpointConfiguration.getConfigurator(). beforeRequest(reqHeaders); if (secure) { SSLEngine sslEngine = createSSLEngine( clientEndpointConfiguration.getUserProperties()); channel = new AsyncChannelWrapperSecure(socketChannel, sslEngine); } else { String timeoutValue = (String) clientEndpointConfiguration.getUserProperties().get( IO_TIMEOUT_MS_PROPERTY); if (timeoutValue != null) { clientEndpointConfiguration.getConfigurator(). afterResponse(handshakeResponse);
List<Extension> extensions = clientEndpointConfiguration.getExtensions(); List<String> subProtocols = clientEndpointConfiguration.getPreferredSubprotocols(); Map<String, Object> userProperties = clientEndpointConfiguration.getUserProperties();
clientEndpointConfiguration.getConfigurator().beforeRequest(reqHeaders); if (Constants.DEFAULT_ORIGIN_HEADER_VALUE != null && !reqHeaders.containsKey(Constants.ORIGIN_HEADER_NAME)) { Map<String,Object> userProperties = clientEndpointConfiguration.getUserProperties(); clientEndpointConfiguration.getConfigurator().afterResponse(handshakeResponse);
RequestContext.Builder.create().requestURI(connectToServerUriParam) .secure("wss".equals(connectToServerUriParam.getScheme())).build()); clientHandShake.setExtensions(config.getExtensions()); clientHandShake.setSubProtocols(config.getPreferredSubprotocols()); clientHandShake.prepareRequest(); config.getConfigurator().beforeRequest(upgradeRequest.getHeaders());
.getExtensions()) { final String responseExtensionName = responseExtension.getName(); if (responseExtensionName != null && responseExtensionName.equals(installedExtension.getName())) { extensions, debugContext); ((ClientEndpointConfig) endpointWrapper.getEndpointConfig()).getConfigurator().afterResponse(upgradeResponse);
@Override protected ListenableFuture<WebSocketSession> doHandshakeInternal(WebSocketHandler webSocketHandler, HttpHeaders headers, final URI uri, List<String> protocols, List<WebSocketExtension> extensions, Map<String, Object> attributes) { int port = getPort(uri); InetSocketAddress localAddress = new InetSocketAddress(getLocalHost(), port); InetSocketAddress remoteAddress = new InetSocketAddress(uri.getHost(), port); final StandardWebSocketSession session = new StandardWebSocketSession(headers, attributes, localAddress, remoteAddress); final ClientEndpointConfig endpointConfig = ClientEndpointConfig.Builder.create() .configurator(new StandardWebSocketClientConfigurator(headers)) .preferredSubprotocols(protocols) .extensions(adaptExtensions(extensions)).build(); endpointConfig.getUserProperties().putAll(getUserProperties()); final Endpoint endpoint = new StandardWebSocketHandlerAdapter(webSocketHandler, session); Callable<WebSocketSession> connectTask = () -> { this.webSocketContainer.connectToServer(endpoint, endpointConfig, uri); return session; }; if (this.taskExecutor != null) { return this.taskExecutor.submitListenable(connectTask); } else { ListenableFutureTask<WebSocketSession> task = new ListenableFutureTask<>(connectTask); task.run(); return task; } }
List<Extension> extensions = clientEndpointConfiguration.getExtensions(); List<String> subProtocols = clientEndpointConfiguration.getPreferredSubprotocols(); Map<String, Object> userProperties = clientEndpointConfiguration.getUserProperties();
clientEndpointConfiguration.getConfigurator().beforeRequest(reqHeaders); if (Constants.DEFAULT_ORIGIN_HEADER_VALUE != null && !reqHeaders.containsKey(Constants.ORIGIN_HEADER_NAME)) { Map<String,Object> userProperties = clientEndpointConfiguration.getUserProperties(); clientEndpointConfiguration.getConfigurator().afterResponse(handshakeResponse);
RequestContext.Builder.create().requestURI(connectToServerUriParam) .secure("wss".equals(connectToServerUriParam.getScheme())).build()); clientHandShake.setExtensions(config.getExtensions()); clientHandShake.setSubProtocols(config.getPreferredSubprotocols()); clientHandShake.prepareRequest(); config.getConfigurator().beforeRequest(upgradeRequest.getHeaders());
private ServerApplicationConfig getServerApplicationConfig(ClientEndpointConfig clientEndpointConfig) throws DeploymentException { final Object o = clientEndpointConfig.getUserProperties().get(SERVER_CONFIG); if (o != null && o instanceof ServerApplicationConfig) { return (ServerApplicationConfig) o; } throw new DeploymentException("ServerApplicationConfig not present."); }
@Override public void onOpen(Session session, EndpointConfig endpointConfig) { // set timeout long oldMaxIdleTimeout = session.getMaxIdleTimeout(); long newMaxIdleTimeout = 0; session.setMaxIdleTimeout(newMaxIdleTimeout); if (log.isDebugEnabled()) log.debug("Changed max idle timeout of session " + session.getId() + " from " + oldMaxIdleTimeout + " to " + newMaxIdleTimeout); // read properties ClientEndpointConfig clientEndpointConfig = (ClientEndpointConfig) endpointConfig; URI xdiWebSocketEndpointUri = (URI) clientEndpointConfig.getUserProperties().get("xdiWebSocketEndpointUri"); // init message handler WebSocketClientMessageHandler webSocketMessageHandler = new WebSocketClientMessageHandler(session); // init session log.info("WebSocket session " + session.getId() + " opened (" + xdiWebSocketEndpointUri + ")."); session.addMessageHandler(webSocketMessageHandler); session.getUserProperties().putAll(clientEndpointConfig.getUserProperties()); }
private ClientEndpointConfig buildClientConfig(ClientEndpointConfig.Configurator configurator) { ClientEndpointConfig config = ClientEndpointConfig.Builder.create().configurator(configurator).build(); if (trustSelfSignedCerts) { SSLContext sslContext = buildSslContext(); Map<String, Object> userProperties = config.getUserProperties(); userProperties.put(WsWebSocketContainer.SSL_CONTEXT_PROPERTY, sslContext); } return config; }