@Override protected void channelRead0(ChannelHandlerContext ctx, FullHttpResponse msg) throws Exception { // Remove ourself and do the actual handshake ctx.pipeline().remove(this); try { finishHandshake(channel, msg); promise.setSuccess(); } catch (Throwable cause) { promise.setFailure(cause); } }
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { if (!(msg instanceof FullHttpResponse)) { ctx.fireChannelRead(msg); return; } FullHttpResponse response = (FullHttpResponse) msg; try { if (!handshaker.isHandshakeComplete()) { handshaker.finishHandshake(ctx.channel(), response); ctx.fireUserEventTriggered( WebSocketClientProtocolHandler.ClientHandshakeStateEvent.HANDSHAKE_COMPLETE); ctx.pipeline().remove(this); return; } throw new IllegalStateException("WebSocketClientHandshaker should have been non finished yet"); } finally { response.release(); } } }
@Override public void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception { Channel ch = ctx.channel(); if (!handshaker.isHandshakeComplete()) { handshaker.finishHandshake(ch, (FullHttpResponse) msg); LOGGER.debug("WebSocket Client connected!"); handshakeFuture.setSuccess(); return; } if (msg instanceof FullHttpResponse) { FullHttpResponse response = (FullHttpResponse) msg; throw new IllegalStateException("Unexpected FullHttpResponse (getStatus=" + response.status() + ", content=" + response.content().toString(CharsetUtil.UTF_8) + ')'); } WebSocketFrame frame = (WebSocketFrame) msg; if (frame instanceof TextWebSocketFrame) { TextWebSocketFrame textFrame = (TextWebSocketFrame) frame; LOGGER.debug("WebSocket Client received text message: " + textFrame.text()); String textReceived = textFrame.text(); callback.call(textReceived); } else if (frame instanceof CloseWebSocketFrame) { isConnected = false; LOGGER.debug("WebSocket Client received closing"); ch.close(); } }
private void handshakeComplete(ChannelHandlerContext ctx, FullHttpResponse response) { handshaking = false; ChannelHandler handler = ctx.pipeline().get(HttpContentDecompressor.class); if (handler != null) { // remove decompressor as its not needed anymore once connection was upgraded to websockets ctx.pipeline().remove(handler); } WebSocketImpl webSocket = new WebSocketImpl(vertx, Http1xClientConnection.this, supportsContinuation, options.getMaxWebsocketFrameSize(), options.getMaxWebsocketMessageSize()); ws = webSocket; handshaker.finishHandshake(chctx.channel(), response); ws.subProtocol(handshaker.actualSubprotocol()); context.executeFromIO(v -> { log.debug("WebSocket handshake complete"); if (metrics != null ) { webSocket.setMetric(metrics.connected(endpointMetric, metric(), webSocket)); } webSocket.registerHandler(vertx.eventBus()); wsConnect.handle(webSocket); }); } }
@Override public void channelRead0(ChannelHandlerContext ctx, Object msg) { Channel ch = ctx.channel(); if (msg instanceof FullHttpResponse) { FullHttpResponse httpResponse = (FullHttpResponse) msg; final SettableFuture<String> registrationFuture = ch.attr(REGISTRATION_FUTURE).get(); if (httpResponse.headers().contains(UPGRADE, WEBSOCKET, true) && !handshaker.isHandshakeComplete()) { handshaker.finishHandshake(ch, httpResponse); final String clientRegistrationId = httpResponse.headers().get("X-CLIENT-REGISTRATION-ID"); registrationFuture.set(clientRegistrationId); mockServerLogger.trace("web socket client " + clientRegistrationId + " connected!"); } else if (httpResponse.status().equals(HttpResponseStatus.NOT_IMPLEMENTED)) { String message = readRequestBody(httpResponse); registrationFuture.setException(new WebSocketException(message)); mockServerLogger.warn(message); } else { registrationFuture.setException(new WebSocketException("Unsupported web socket message " + new FullHttpResponseToMockServerResponse().mapMockServerResponseToFullHttpResponse(httpResponse))); } } else if (msg instanceof WebSocketFrame) { WebSocketFrame frame = (WebSocketFrame) msg; if (frame instanceof TextWebSocketFrame) { webSocketClient.receivedTextWebSocketFrame((TextWebSocketFrame) frame); } else if (frame instanceof PingWebSocketFrame) { ctx.write(new PongWebSocketFrame(frame.content().retain())); } else if (frame instanceof CloseWebSocketFrame) { mockServerLogger.trace("web socket client received request to close"); ch.close(); } } }
if (response instanceof FullHttpResponse) { try { finishHandshake(channel, (FullHttpResponse) response); promise.setSuccess(); } catch (Throwable cause) {
handshaker.finishHandshake(ch, res); handshakeFuture.setSuccess();
@Override protected void channelRead0(final ChannelHandlerContext ctx, final Object msg) throws Exception { final Channel ch = ctx.channel(); if (!handshaker.isHandshakeComplete()) { // web socket client connected handshaker.finishHandshake(ch, (FullHttpResponse) msg); handshakeFuture.setSuccess(); return; } if (msg instanceof FullHttpResponse) { final FullHttpResponse response = (FullHttpResponse) msg; throw new Exception("Unexpected FullHttpResponse (getStatus=" + response.status() + ", content=" + response.content().toString(CharsetUtil.UTF_8) + ')'); } // a close frame doesn't mean much here. errors raised from closed channels will mark the host as dead final WebSocketFrame frame = (WebSocketFrame) msg; if (frame instanceof TextWebSocketFrame) { ctx.fireChannelRead(frame.retain(2)); } else if (frame instanceof PingWebSocketFrame) { ctx.writeAndFlush(new PongWebSocketFrame()); }else if (frame instanceof PongWebSocketFrame) { logger.debug("Received response from keep-alive request"); } else if (frame instanceof BinaryWebSocketFrame) { ctx.fireChannelRead(frame.retain(2)); } else if (frame instanceof CloseWebSocketFrame) ch.close(); }
private void handshakeComplete(ChannelHandlerContext ctx, FullHttpResponse response) { handshaking = false; ChannelHandler handler = ctx.pipeline().get(HttpContentDecompressor.class); if (handler != null) { // remove decompressor as its not needed anymore once connection was upgraded to websockets ctx.pipeline().remove(handler); } WebSocketImpl webSocket = new WebSocketImpl(vertx, Http1xClientConnection.this, supportsContinuation, options.getMaxWebsocketFrameSize(), options.getMaxWebsocketMessageSize()); ws = webSocket; handshaker.finishHandshake(chctx.channel(), response); ws.subProtocol(handshaker.actualSubprotocol()); context.executeFromIO(v -> { log.debug("WebSocket handshake complete"); if (metrics != null ) { webSocket.setMetric(metrics.connected(endpointMetric, metric(), webSocket)); } webSocket.registerHandler(vertx.eventBus()); wsConnect.handle(webSocket); }); } }
@Override protected void channelRead0(ChannelHandlerContext ctx, FullHttpResponse msg) throws Exception { // Remove ourself and do the actual handshake ctx.pipeline().remove(this); try { finishHandshake(channel, msg); promise.setSuccess(); } catch (Throwable cause) { promise.setFailure(cause); } }
@Override protected void channelRead0(ChannelHandlerContext ctx, FullHttpResponse msg) throws Exception { // Remove ourself and do the actual handshake ctx.pipeline().remove(this); try { finishHandshake(channel, msg); promise.setSuccess(); } catch (Throwable cause) { promise.setFailure(cause); } }
@Override protected void channelRead0(ChannelHandlerContext ctx, FullHttpResponse msg) throws Exception { // Remove ourself and do the actual handshake ctx.pipeline().remove(this); try { finishHandshake(channel, msg); promise.setSuccess(); } catch (Throwable cause) { promise.setFailure(cause); } }
@Override protected void channelRead0(ChannelHandlerContext ctx, FullHttpResponse msg) throws Exception { // Remove ourself and do the actual handshake ctx.pipeline().remove(this); try { finishHandshake(channel, msg); promise.setSuccess(); } catch (Throwable cause) { promise.setFailure(cause); } }
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { if (!(msg instanceof FullHttpResponse)) { ctx.fireChannelRead(msg); return; } FullHttpResponse response = (FullHttpResponse) msg; try { if (!handshaker.isHandshakeComplete()) { handshaker.finishHandshake(ctx.channel(), response); ctx.fireUserEventTriggered( WebSocketClientProtocolHandler.ClientHandshakeStateEvent.HANDSHAKE_COMPLETE); ctx.pipeline().remove(this); return; } throw new IllegalStateException("WebSocketClientHandshaker should have been non finished yet"); } finally { response.release(); } } }
@Override public void channelRead0(ChannelHandlerContext ctx, Object msg) { System.out.println("client channelRead0 "+ctx); Channel ch = ctx.channel(); if (!handshaker.isHandshakeComplete()) { handshaker.finishHandshake(ch, (FullHttpResponse) msg); System.out.println("WebSocket Client connected!"); handshakeFuture.setSuccess(); } if(msg instanceof WebSocketFrame){ WebSocketFrame frame = (WebSocketFrame)msg; if(frame instanceof BinaryWebSocketFrame){ handleWebSocketFrame(ctx, frame); } } }
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { if (!(msg instanceof FullHttpResponse)) { ctx.fireChannelRead(msg); return; } FullHttpResponse response = (FullHttpResponse) msg; try { if (!handshaker.isHandshakeComplete()) { handshaker.finishHandshake(ctx.channel(), response); ctx.fireUserEventTriggered( WebSocketClientProtocolHandler.ClientHandshakeStateEvent.HANDSHAKE_COMPLETE); ctx.pipeline().remove(this); return; } throw new IllegalStateException("WebSocketClientHandshaker should have been non finished yet"); } finally { response.release(); } } }
@Override public void channelRead0(ChannelHandlerContext ctx, Object msg) { System.out.println("client channelRead0 "+ctx); Channel ch = ctx.channel(); if (!handshaker.isHandshakeComplete()) { handshaker.finishHandshake(ch, (FullHttpResponse) msg); System.out.println("WebSocket Client connected!"); handshakeFuture.setSuccess(); } if(msg instanceof WebSocketFrame){ WebSocketFrame frame = (WebSocketFrame)msg; if(frame instanceof BinaryWebSocketFrame){ handleWebSocketFrame(frame); } return; } sendRealTimeMessageTest(ctx); }
protected boolean completeHandshake(ChannelHandlerContext ctx) { if (!handshaker.isHandshakeComplete()) { if (response != null && response.getStatus().code() > 299) { for (WebSocketEventListener l : listensers) { l.onError(ctx, null, response); } return true; } handshaker.finishHandshake(ctx.channel(), response); handshakeFuture.setSuccess(); for (WebSocketEventListener l : listensers) { l.onConnect(ctx); } return true; } return false; }
protected boolean completeHandshake(ChannelHandlerContext ctx) { if (!handshaker.isHandshakeComplete()) { if (response != null && response.getStatus().code() > 299) { for (WebSocketEventListener l : listensers) { l.onError(ctx, null, response); } return true; } handshaker.finishHandshake(ctx.channel(), response); handshakeFuture.setSuccess(); for (WebSocketEventListener l : listensers) { l.onConnect(ctx); } return true; } return false; }
@Override public void channelRead0(ChannelHandlerContext context, Object message) { Channel channel = context.channel(); if (message instanceof FullHttpResponse) { checkState(!handshaker.isHandshakeComplete()); try { handshaker.finishHandshake(channel, (FullHttpResponse) message); delegate.onOpen(); } catch (WebSocketHandshakeException e) { delegate.onError(e); } } else if (message instanceof TextWebSocketFrame) { delegate.onMessage(((TextWebSocketFrame) message).text()); } else { checkState(message instanceof CloseWebSocketFrame); delegate.onClose(); } }