@Override public Optional<String> getSubprotocol() { return Optional.ofNullable(handshaker.selectedSubprotocol()); }
@Override public void operationComplete(ChannelFuture future) throws Exception { if (!future.isSuccess()) { ctx.fireExceptionCaught(future.cause()); } else { // Kept for compatibility ctx.fireUserEventTriggered( WebSocketServerProtocolHandler.ServerHandshakeStateEvent.HANDSHAKE_COMPLETE); ctx.fireUserEventTriggered( new WebSocketServerProtocolHandler.HandshakeComplete( req.uri(), req.headers(), handshaker.selectedSubprotocol())); } } });
ServerWebSocketImpl createWebSocket(HttpServerRequestImpl request) { if (ws != null) { return ws; } if (!(request.getRequest() instanceof FullHttpRequest)) { throw new IllegalStateException(); } FullHttpRequest nettyReq = (FullHttpRequest) request.getRequest(); WebSocketServerHandshaker handshaker = createHandshaker(nettyReq); if (handshaker == null) { return null; } Function<ServerWebSocketImpl, String> f = ws -> { handshaker.handshake(chctx.channel(), nettyReq); // remove compressor as its not needed anymore once connection was upgraded to websockets ChannelHandler handler = chctx.pipeline().get(HttpChunkContentCompressor.class); if (handler != null) { chctx.pipeline().remove(handler); } ws.registerHandler(vertx.eventBus()); return handshaker.selectedSubprotocol(); }; ws = new ServerWebSocketImpl(vertx, request.uri(), request.path(), request.query(), request.headers(), this, handshaker.version() != WebSocketVersion.V00, f, options.getMaxWebsocketFrameSize(), options.getMaxWebsocketMessageSize()); if (METRICS_ENABLED && metrics != null) { ws.setMetric(metrics.connected(metric(), request.metric(), ws)); } return ws; }
ServerWebSocketImpl createWebSocket(HttpServerRequestImpl request) { if (ws != null) { return ws; } if (!(request.getRequest() instanceof FullHttpRequest)) { throw new IllegalStateException(); } FullHttpRequest nettyReq = (FullHttpRequest) request.getRequest(); WebSocketServerHandshaker handshaker = createHandshaker(nettyReq); if (handshaker == null) { return null; } Function<ServerWebSocketImpl, String> f = ws -> { handshaker.handshake(chctx.channel(), nettyReq); // remove compressor as its not needed anymore once connection was upgraded to websockets ChannelHandler handler = chctx.pipeline().get(HttpChunkContentCompressor.class); if (handler != null) { chctx.pipeline().remove(handler); } ws.registerHandler(vertx.eventBus()); return handshaker.selectedSubprotocol(); }; ws = new ServerWebSocketImpl(vertx, request.uri(), request.path(), request.query(), request.headers(), this, handshaker.version() != WebSocketVersion.V00, f, options.getMaxWebsocketFrameSize(), options.getMaxWebsocketMessageSize()); if (METRICS_ENABLED && metrics != null) { ws.setMetric(metrics.connected(metric(), request.metric(), ws)); } return ws; }
@Override public String selectedSubprotocol() { return handshaker.selectedSubprotocol(); }
@Override public String selectedSubprotocol() { return handshaker.selectedSubprotocol(); }
@Override public String selectedSubprotocol() { return handshaker.selectedSubprotocol(); }
@Override public void operationComplete(ChannelFuture future) throws Exception { if (!future.isSuccess()) { ctx.fireExceptionCaught(future.cause()); } else { // Kept for compatibility ctx.fireUserEventTriggered( WebSocketServerProtocolHandler.ServerHandshakeStateEvent.HANDSHAKE_COMPLETE); ctx.fireUserEventTriggered( new WebSocketServerProtocolHandler.HandshakeComplete( req.uri(), req.headers(), handshaker.selectedSubprotocol())); } } });
@Override public void operationComplete(ChannelFuture future) throws Exception { if (!future.isSuccess()) { ctx.fireExceptionCaught(future.cause()); } else { // Kept for compatibility ctx.fireUserEventTriggered( WebSocketServerProtocolHandler.ServerHandshakeStateEvent.HANDSHAKE_COMPLETE); ctx.fireUserEventTriggered( new WebSocketServerProtocolHandler.HandshakeComplete( req.uri(), req.headers(), handshaker.selectedSubprotocol())); } } });
@Override public void operationComplete(ChannelFuture future) throws Exception { if (!future.isSuccess()) { ctx.fireExceptionCaught(future.cause()); } else { // Kept for compatibility ctx.fireUserEventTriggered( WebSocketServerProtocolHandler.ServerHandshakeStateEvent.HANDSHAKE_COMPLETE); ctx.fireUserEventTriggered( new WebSocketServerProtocolHandler.HandshakeComplete( req.uri(), req.headers(), handshaker.selectedSubprotocol())); } } });
@Override public void operationComplete(ChannelFuture future) throws Exception { if (!future.isSuccess()) { ctx.fireExceptionCaught(future.cause()); } else { // Kept for compatibility ctx.fireUserEventTriggered( WebSocketServerProtocolHandler.ServerHandshakeStateEvent.HANDSHAKE_COMPLETE); ctx.fireUserEventTriggered( new WebSocketServerProtocolHandler.HandshakeComplete( req.uri(), req.headers(), handshaker.selectedSubprotocol())); } } });
if(subProtocol.equals(handshaker.selectedSubprotocol())){ NettyWebSocket webSocket = new NettyWebSocket(handshaker, subProtocol); ctx.pipeline().addLast("ws-aggregator", new WebSocketFrameAggregator(16 * 1024 * 1024));
@Override public void operationComplete(Future<? super Void> future) throws Exception { String selectedSubProtocol = handshaker.selectedSubprotocol(); webSocketSourceHandler.setNegotiatedSubProtocol(selectedSubProtocol); setSubProtocol(selectedSubProtocol); WebSocketSessionImpl session = (WebSocketSessionImpl) getChannelSession(); session.setIsOpen(true); session.setNegotiatedSubProtocol(selectedSubProtocol); //Replace HTTP handlers with new Handlers for WebSocket in the pipeline ChannelPipeline pipeline = ctx.pipeline(); if (idleTimeout > 0) { pipeline.replace(Constants.IDLE_STATE_HANDLER, Constants.IDLE_STATE_HANDLER, new IdleStateHandler(idleTimeout, idleTimeout, idleTimeout, TimeUnit.MILLISECONDS)); } else { pipeline.remove(Constants.IDLE_STATE_HANDLER); } pipeline.addLast(Constants.WEBSOCKET_SOURCE_HANDLER, webSocketSourceHandler); pipeline.remove(Constants.HTTP_SOURCE_HANDLER); setProperty(Constants.SRC_HANDLER, webSocketSourceHandler); handshakeFuture.notifySuccess(webSocketSourceHandler.getChannelSession()); } });
private ServerHandshakeFuture handleHandshake(WebSocketServerHandshaker handshaker, int idleTimeout, HttpHeaders headers) { DefaultServerHandshakeFuture handshakeFuture = new DefaultServerHandshakeFuture(); if (handshaker == null) { WebSocketServerHandshakerFactory.sendUnsupportedVersionResponse(ctx.channel()); handshakeFuture.notifyError(new UnsupportedOperationException("Unsupported WebSocket version")); return handshakeFuture; } if (cancelled) { Throwable e = new IllegalAccessException("Handshake is already cancelled."); handshakeFuture.notifyError(e); return handshakeFuture; } ChannelFuture channelFuture = handshaker.handshake(ctx.channel(), httpRequest, headers, ctx.channel().newPromise()); channelFuture.addListener(future -> { if (future.isSuccess() && future.cause() == null) { WebSocketInboundFrameHandler frameHandler = new WebSocketInboundFrameHandler(true, secureConnection, target, handshaker.selectedSubprotocol(), connectorFuture, new MessageQueueHandler()); configureFrameHandlingPipeline(idleTimeout, frameHandler); handshakeFuture.notifySuccess(frameHandler.getWebSocketConnection()); } else { handshakeFuture.notifyError(future.cause()); } }); handshakeStarted = true; return handshakeFuture; }
String actualProtocol = handshaker.selectedSubprotocol(); serialization = WampSerialization.fromString(actualProtocol);
String actualProtocol = handshaker.selectedSubprotocol(); serialization = WampSerialization.fromString(actualProtocol);
String actualProtocol = handshaker.selectedSubprotocol(); serialization = WampSerialization.fromString(actualProtocol);