Class WebSocketClientHandshaker

    • Field Detail

      • webSocketUrl

        private final java.net.URI webSocketUrl
      • handshakeComplete

        private volatile boolean handshakeComplete
      • expectedSubprotocol

        private final java.lang.String expectedSubprotocol
      • actualSubprotocol

        private volatile java.lang.String actualSubprotocol
      • customHeaders

        protected final java.util.Map<java.lang.String,​java.lang.String> customHeaders
      • maxFramePayloadLength

        private final long maxFramePayloadLength
    • Constructor Detail

      • WebSocketClientHandshaker

        protected WebSocketClientHandshaker​(java.net.URI webSocketUrl,
                                            WebSocketVersion version,
                                            java.lang.String subprotocol,
                                            java.util.Map<java.lang.String,​java.lang.String> customHeaders)
        Base constructor with default values
        Parameters:
        webSocketUrl - 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
      • WebSocketClientHandshaker

        protected WebSocketClientHandshaker​(java.net.URI webSocketUrl,
                                            WebSocketVersion version,
                                            java.lang.String subprotocol,
                                            java.util.Map<java.lang.String,​java.lang.String> customHeaders,
                                            long maxFramePayloadLength)
        Base constructor
        Parameters:
        webSocketUrl - 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 - CSV of requested subprotocol(s) sent to the server.
        customHeaders - Map of custom headers to add to the client request
        maxFramePayloadLength - Maximum length of a frame's payload
    • Method Detail

      • getWebSocketUrl

        public java.net.URI getWebSocketUrl()
        Returns the URI to the web socket. e.g. "ws://myhost.com/path"
      • getVersion

        public WebSocketVersion getVersion()
        Version of the web socket specification that is being used
      • getMaxFramePayloadLength

        public long getMaxFramePayloadLength()
        Returns the max length for any frame's payload
      • isHandshakeComplete

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

        protected void setHandshakeComplete()
      • getExpectedSubprotocol

        public java.lang.String getExpectedSubprotocol()
        Returns the CSV of requested subprotocol(s) sent to the server as specified in the constructor
      • getActualSubprotocol

        public java.lang.String getActualSubprotocol()
        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.
      • setActualSubprotocol

        protected void setActualSubprotocol​(java.lang.String actualSubprotocol)
      • handshake

        public abstract ChannelFuture handshake​(Channel channel)
                                         throws java.lang.Exception
        Begins the opening handshake
        Parameters:
        channel - Channel
        Throws:
        java.lang.Exception
      • replaceDecoder

        static void replaceDecoder​(Channel channel,
                                   ChannelHandler wsDecoder)
        Replace the HTTP decoder with a new Web Socket decoder. Note that we do not use ChannelPipeline.replace(String, String, ChannelHandler), because the server might have sent the first frame immediately after the upgrade response. In such a case, the HTTP decoder might have the first frame in its cumulation buffer and the HTTP decoder will forward it to the next handler. The Web Socket decoder will not receive it if we simply replaced it. For more information, refer to HttpResponseDecoder and its unit tests.