Class WebSocketClientHandshaker

    • Field Detail

      • DEFAULT_FORCE_CLOSE_TIMEOUT_MILLIS

        protected static final int DEFAULT_FORCE_CLOSE_TIMEOUT_MILLIS
        See Also:
        Constant Field Values
      • customHeaders

        protected final HttpHeaders customHeaders
      • generateOriginHeader

        protected final boolean generateOriginHeader
    • Constructor Detail

      • WebSocketClientHandshaker

        protected WebSocketClientHandshaker​(URI uri,
                                            WebSocketVersion version,
                                            String subprotocol,
                                            HttpHeaders customHeaders,
                                            int maxFramePayloadLength)
        Base constructor
        Parameters:
        uri - URL for web socket communications. e.g "ws://myhost.com/mypath". Subsequent web socket frames will be sent to this URL.
        version - Version of web socket specification to use to connect to the server
        subprotocol - Sub protocol request sent to the server.
        customHeaders - Map of custom headers to add to the client request
        maxFramePayloadLength - Maximum length of a frame's payload
      • WebSocketClientHandshaker

        protected WebSocketClientHandshaker​(URI uri,
                                            WebSocketVersion version,
                                            String subprotocol,
                                            HttpHeaders customHeaders,
                                            int maxFramePayloadLength,
                                            long forceCloseTimeoutMillis)
        Base constructor
        Parameters:
        uri - URL for web socket communications. e.g "ws://myhost.com/mypath". Subsequent web socket frames will be sent to this URL.
        version - Version of web socket specification to use to connect to the server
        subprotocol - Sub protocol request sent to the server.
        customHeaders - Map of custom headers to add to the client request
        maxFramePayloadLength - Maximum length of a frame's payload
        forceCloseTimeoutMillis - Close the connection if it was not closed by the server after timeout specified
      • WebSocketClientHandshaker

        protected WebSocketClientHandshaker​(URI uri,
                                            WebSocketVersion version,
                                            String subprotocol,
                                            HttpHeaders customHeaders,
                                            int maxFramePayloadLength,
                                            long forceCloseTimeoutMillis,
                                            boolean absoluteUpgradeUrl)
        Base constructor
        Parameters:
        uri - URL for web socket communications. e.g "ws://myhost.com/mypath". Subsequent web socket frames will be sent to this URL.
        version - Version of web socket specification to use to connect to the server
        subprotocol - Sub protocol request sent to the server.
        customHeaders - Map of custom headers to add to the client request
        maxFramePayloadLength - Maximum length of a frame's payload
        forceCloseTimeoutMillis - Close the connection if it was not closed by the server after timeout specified
        absoluteUpgradeUrl - Use an absolute url for the Upgrade request, typically when connecting through an HTTP proxy over clear HTTP
      • WebSocketClientHandshaker

        protected WebSocketClientHandshaker​(URI uri,
                                            WebSocketVersion version,
                                            String subprotocol,
                                            HttpHeaders customHeaders,
                                            int maxFramePayloadLength,
                                            long forceCloseTimeoutMillis,
                                            boolean absoluteUpgradeUrl,
                                            boolean generateOriginHeader)
        Base constructor
        Parameters:
        uri - URL for web socket communications. e.g "ws://myhost.com/mypath". Subsequent web socket frames will be sent to this URL.
        version - Version of web socket specification to use to connect to the server
        subprotocol - Sub protocol request sent to the server.
        customHeaders - Map of custom headers to add to the client request
        maxFramePayloadLength - Maximum length of a frame's payload
        forceCloseTimeoutMillis - Close the connection if it was not closed by the server after timeout specified
        absoluteUpgradeUrl - Use an absolute url for the Upgrade request, typically when connecting through an HTTP proxy over clear HTTP
        generateOriginHeader - Allows to generate the `Origin`|`Sec-WebSocket-Origin` header value for handshake request according to the given webSocketURL
    • Method Detail

      • uri

        public URI uri()
        Returns the URI to the web socket. e.g. "ws://myhost.com/path"
      • version

        public WebSocketVersion version()
        Version of the web socket specification that is being used
      • maxFramePayloadLength

        public int maxFramePayloadLength()
        Returns the max length for any frame's payload
      • isHandshakeComplete

        public boolean isHandshakeComplete()
        Flag to indicate if the opening handshake is complete
      • expectedSubprotocol

        public String expectedSubprotocol()
        Returns the CSV of requested subprotocol(s) sent to the server as specified in the constructor
      • actualSubprotocol

        public String actualSubprotocol()
        Returns the subprotocol response sent by the server. Only available after end of handshake. Null if no subprotocol was requested or confirmed by the server.
      • forceCloseTimeoutMillis

        public long forceCloseTimeoutMillis()
      • isForceCloseComplete

        protected boolean isForceCloseComplete()
        Flag to indicate if the closing handshake was initiated because of timeout. For testing only.
      • setForceCloseTimeoutMillis

        public WebSocketClientHandshaker setForceCloseTimeoutMillis​(long forceCloseTimeoutMillis)
        Sets timeout to close the connection if it was not closed by the server.
        Parameters:
        forceCloseTimeoutMillis - Close the connection if it was not closed by the server after timeout specified
      • handshake

        public io.netty.channel.ChannelFuture handshake​(io.netty.channel.Channel channel)
        Begins the opening handshake
        Parameters:
        channel - Channel
      • handshake

        public final io.netty.channel.ChannelFuture handshake​(io.netty.channel.Channel channel,
                                                              io.netty.channel.ChannelPromise promise)
        Begins the opening handshake
        Parameters:
        channel - Channel
        promise - the ChannelPromise to be notified when the opening handshake is sent
      • newHandshakeRequest

        protected abstract FullHttpRequest newHandshakeRequest()
        Returns a new {@link FullHttpRequest) which will be used for the handshake.
      • finishHandshake

        public final void finishHandshake​(io.netty.channel.Channel channel,
                                          FullHttpResponse response)
        Validates and finishes the opening handshake initiated by handshake(io.netty.channel.Channel)}.
        Parameters:
        channel - Channel
        response - HTTP response containing the closing handshake details
      • processHandshake

        public final io.netty.channel.ChannelFuture processHandshake​(io.netty.channel.Channel channel,
                                                                     HttpResponse response)
        Process the opening handshake initiated by handshake(io.netty.channel.Channel)}.
        Parameters:
        channel - Channel
        response - HTTP response containing the closing handshake details
        Returns:
        future the ChannelFuture which is notified once the handshake completes.
      • processHandshake

        public final io.netty.channel.ChannelFuture processHandshake​(io.netty.channel.Channel channel,
                                                                     HttpResponse response,
                                                                     io.netty.channel.ChannelPromise promise)
        Process the opening handshake initiated by handshake(io.netty.channel.Channel)}.
        Parameters:
        channel - Channel
        response - HTTP response containing the closing handshake details
        promise - the ChannelPromise to notify once the handshake completes.
        Returns:
        future the ChannelFuture which is notified once the handshake completes.
      • newWebsocketDecoder

        protected abstract WebSocketFrameDecoder newWebsocketDecoder()
        Returns the decoder to use after handshake is complete.
      • newWebSocketEncoder

        protected abstract WebSocketFrameEncoder newWebSocketEncoder()
        Returns the encoder to use after the handshake is complete.
      • close

        public io.netty.channel.ChannelFuture close​(io.netty.channel.Channel channel,
                                                    CloseWebSocketFrame frame)
        Performs the closing handshake. When called from within a ChannelHandler you most likely want to use close(ChannelHandlerContext, CloseWebSocketFrame).
        Parameters:
        channel - Channel
        frame - Closing Frame that was received
      • close

        public io.netty.channel.ChannelFuture close​(io.netty.channel.Channel channel,
                                                    CloseWebSocketFrame frame,
                                                    io.netty.channel.ChannelPromise promise)
        Performs the closing handshake When called from within a ChannelHandler you most likely want to use close(ChannelHandlerContext, CloseWebSocketFrame, ChannelPromise).
        Parameters:
        channel - Channel
        frame - Closing Frame that was received
        promise - the ChannelPromise to be notified when the closing handshake is done
      • close

        public io.netty.channel.ChannelFuture close​(io.netty.channel.ChannelHandlerContext ctx,
                                                    CloseWebSocketFrame frame)
        Performs the closing handshake
        Parameters:
        ctx - the ChannelHandlerContext to use.
        frame - Closing Frame that was received
      • close

        public io.netty.channel.ChannelFuture close​(io.netty.channel.ChannelHandlerContext ctx,
                                                    CloseWebSocketFrame frame,
                                                    io.netty.channel.ChannelPromise promise)
        Performs the closing handshake
        Parameters:
        ctx - the ChannelHandlerContext to use.
        frame - Closing Frame that was received
        promise - the ChannelPromise to be notified when the closing handshake is done
      • upgradeUrl

        protected String upgradeUrl​(URI wsURL)
        Return the constructed raw path for the give URI.