@Override public void upgrade(ServerHttpRequest request, ServerHttpResponse response, @Nullable String selectedProtocol, List<WebSocketExtension> selectedExtensions, @Nullable Principal user, WebSocketHandler wsHandler, Map<String, Object> attrs) throws HandshakeFailureException { HttpHeaders headers = request.getHeaders(); InetSocketAddress localAddr = null; try { localAddr = request.getLocalAddress(); } catch (Exception ex) { // Ignore } InetSocketAddress remoteAddr = null; try { remoteAddr = request.getRemoteAddress(); } catch (Exception ex) { // Ignore } StandardWebSocketSession session = new StandardWebSocketSession(headers, attrs, localAddr, remoteAddr, user); StandardWebSocketHandlerAdapter endpoint = new StandardWebSocketHandlerAdapter(wsHandler, session); List<Extension> extensions = new ArrayList<>(); for (WebSocketExtension extension : selectedExtensions) { extensions.add(new WebSocketToStandardExtensionAdapter(extension)); } upgradeInternal(request, response, selectedProtocol, extensions, endpoint); }
@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; } }
@Before public void setup() { this.session = mock(Session.class); this.webSocketHandler = mock(WebSocketHandler.class); this.webSocketSession = new StandardWebSocketSession(null, null, null, null); this.adapter = new StandardWebSocketHandlerAdapter(this.webSocketHandler, this.webSocketSession); }
@Override public void upgrade(ServerHttpRequest request, ServerHttpResponse response, @Nullable String selectedProtocol, List<WebSocketExtension> selectedExtensions, @Nullable Principal user, WebSocketHandler wsHandler, Map<String, Object> attrs) throws HandshakeFailureException { HttpHeaders headers = request.getHeaders(); InetSocketAddress localAddr = null; try { localAddr = request.getLocalAddress(); } catch (Exception ex) { // Ignore } InetSocketAddress remoteAddr = null; try { remoteAddr = request.getRemoteAddress(); } catch (Exception ex) { // Ignore } StandardWebSocketSession session = new StandardWebSocketSession(headers, attrs, localAddr, remoteAddr, user); StandardWebSocketHandlerAdapter endpoint = new StandardWebSocketHandlerAdapter(wsHandler, session); List<Extension> extensions = new ArrayList<>(); for (WebSocketExtension extension : selectedExtensions) { extensions.add(new WebSocketToStandardExtensionAdapter(extension)); } upgradeInternal(request, response, selectedProtocol, extensions, endpoint); }
@Override public void upgrade(ServerHttpRequest request, ServerHttpResponse response, @Nullable String selectedProtocol, List<WebSocketExtension> selectedExtensions, @Nullable Principal user, WebSocketHandler wsHandler, Map<String, Object> attrs) throws HandshakeFailureException { HttpHeaders headers = request.getHeaders(); InetSocketAddress localAddr = null; try { localAddr = request.getLocalAddress(); } catch (Exception ex) { // Ignore } InetSocketAddress remoteAddr = null; try { remoteAddr = request.getRemoteAddress(); } catch (Exception ex) { // Ignore } StandardWebSocketSession session = new StandardWebSocketSession(headers, attrs, localAddr, remoteAddr, user); StandardWebSocketHandlerAdapter endpoint = new StandardWebSocketHandlerAdapter(wsHandler, session); List<Extension> extensions = new ArrayList<>(); for (WebSocketExtension extension : selectedExtensions) { extensions.add(new WebSocketToStandardExtensionAdapter(extension)); } upgradeInternal(request, response, selectedProtocol, extensions, endpoint); }
@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 = () -> { 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; } }
@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; } }