From a225fdeea5a087b30628ca4916b41ad460da150c Mon Sep 17 00:00:00 2001
From: Ngoc Dao
* Browser request to the server: *
- * + * ** GET /demo HTTP/1.1 * Upgrade: WebSocket @@ -95,14 +95,14 @@ public class WebSocketServerHandshaker00 extends WebSocketServerHandshaker { * Origin: http://example.com * Sec-WebSocket-Key1: 4 @1 46546xW%0l 1 5 * Sec-WebSocket-Key2: 12998 5 Y3 1 .P00 - * + * * ^n:ds[4U *- * + * *
* Server response: *
- * + * ** HTTP/1.1 101 WebSocket Protocol Handshake * Upgrade: WebSocket @@ -110,21 +110,21 @@ public class WebSocketServerHandshaker00 extends WebSocketServerHandshaker { * Sec-WebSocket-Origin: http://example.com * Sec-WebSocket-Location: ws://example.com/demo * Sec-WebSocket-Protocol: sample - * + * * 8jKS'y:G*Co,Wxa- *- * - * @param ctx - * Channel context + * + * @param channel + * Channel * @param req * HTTP request * @throws NoSuchAlgorithmException */ @Override - public void performOpeningHandshake(ChannelHandlerContext ctx, HttpRequest req) { + public void performOpeningHandshake(Channel channel, HttpRequest req) { if (logger.isDebugEnabled()) { - logger.debug(String.format("Channel %s web socket spec version 00 handshake", ctx.getChannel().getId())); + logger.debug(String.format("Channel %s web socket spec version 00 handshake", channel.getId())); } this.setVersion(WebSocketSpecificationVersion.V00); @@ -174,25 +174,25 @@ public class WebSocketServerHandshaker00 extends WebSocketServerHandshaker { } // Upgrade the connection and send the handshake response. - ChannelPipeline p = ctx.getChannel().getPipeline(); + ChannelPipeline p = channel.getPipeline(); p.remove("aggregator"); p.replace("decoder", "wsdecoder", new WebSocket00FrameDecoder()); - ctx.getChannel().write(res); + channel.write(res); p.replace("encoder", "wsencoder", new WebSocket00FrameEncoder()); } /** * Echo back the closing frame - * - * @param ctx - * Channel context + * + * @param channel + * Channel * @param frame * Web Socket frame that was received */ @Override - public void performClosingHandshake(ChannelHandlerContext ctx, CloseWebSocketFrame frame) { - ctx.getChannel().write(frame); + public void performClosingHandshake(Channel channel, CloseWebSocketFrame frame) { + channel.write(frame); } } diff --git a/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketServerHandshaker10.java b/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketServerHandshaker10.java index c3b895a832..fd4f2d5d1e 100644 --- a/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketServerHandshaker10.java +++ b/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketServerHandshaker10.java @@ -20,9 +20,9 @@ import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1; import java.security.NoSuchAlgorithmException; +import io.netty.channel.Channel; import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFutureListener; -import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelPipeline; import io.netty.handler.codec.http.DefaultHttpResponse; import io.netty.handler.codec.http.HttpRequest; @@ -51,7 +51,7 @@ public class WebSocketServerHandshaker10 extends WebSocketServerHandshaker { /** * Constructor specifying the destination web socket location - * + * * @param webSocketURL * URL for web socket communications. e.g * "ws://myhost.com/mypath". Subsequent web socket frames will be @@ -73,11 +73,11 @@ public class WebSocketServerHandshaker10 extends WebSocketServerHandshaker { * "http://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-08">HyBi * version 8 to 10. Version 8, 9 and 10 share the same wire protocol. * - * + * *
* Browser request to the server: *
- * + * ** GET /chat HTTP/1.1 * Host: server.example.com @@ -88,11 +88,11 @@ public class WebSocketServerHandshaker10 extends WebSocketServerHandshaker { * Sec-WebSocket-Protocol: chat, superchat * Sec-WebSocket-Version: 8 *- * + * *
* Server response: *
- * + * ** HTTP/1.1 101 Switching Protocols * Upgrade: websocket @@ -100,18 +100,18 @@ public class WebSocketServerHandshaker10 extends WebSocketServerHandshaker { * Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo= * Sec-WebSocket-Protocol: chat *- * - * @param ctx - * Channel context + * + * @param channel + * Channel * @param req * HTTP request * @throws NoSuchAlgorithmException */ @Override - public void performOpeningHandshake(ChannelHandlerContext ctx, HttpRequest req) { + public void performOpeningHandshake(Channel channel, HttpRequest req) { if (logger.isDebugEnabled()) { - logger.debug(String.format("Channel %s web socket spec version 10 handshake", ctx.getChannel().getId())); + logger.debug(String.format("Channel %s web socket spec version 10 handshake", channel.getId())); } HttpResponse res = new DefaultHttpResponse(HTTP_1_1, new HttpResponseStatus(101, "Switching Protocols")); @@ -139,10 +139,10 @@ public class WebSocketServerHandshaker10 extends WebSocketServerHandshaker { res.addHeader(Names.SEC_WEBSOCKET_PROTOCOL, this.selectSubProtocol(protocol)); } - ctx.getChannel().write(res); + channel.write(res); // Upgrade the connection and send the handshake response. - ChannelPipeline p = ctx.getChannel().getPipeline(); + ChannelPipeline p = channel.getPipeline(); p.remove("aggregator"); p.replace("decoder", "wsdecoder", new WebSocket08FrameDecoder(true, this.allowExtensions)); p.replace("encoder", "wsencoder", new WebSocket08FrameEncoder(false)); @@ -151,15 +151,15 @@ public class WebSocketServerHandshaker10 extends WebSocketServerHandshaker { /** * Echo back the closing frame and close the connection - * - * @param ctx - * Channel context + * + * @param channel + * Channel * @param frame * Web Socket frame that was received */ @Override - public void performClosingHandshake(ChannelHandlerContext ctx, CloseWebSocketFrame frame) { - ChannelFuture f = ctx.getChannel().write(frame); + public void performClosingHandshake(Channel channel, CloseWebSocketFrame frame) { + ChannelFuture f = channel.write(frame); f.addListener(ChannelFutureListener.CLOSE); } diff --git a/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketServerHandshaker17.java b/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketServerHandshaker17.java index 68d82bf40a..fedb3e01b5 100644 --- a/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketServerHandshaker17.java +++ b/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketServerHandshaker17.java @@ -20,9 +20,9 @@ import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1; import java.security.NoSuchAlgorithmException; +import io.netty.channel.Channel; import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFutureListener; -import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelPipeline; import io.netty.handler.codec.http.DefaultHttpResponse; import io.netty.handler.codec.http.HttpRequest; @@ -51,7 +51,7 @@ public class WebSocketServerHandshaker17 extends WebSocketServerHandshaker { /** * Constructor specifying the destination web socket location - * + * * @param webSocketURL * URL for web socket communications. e.g * "ws://myhost.com/mypath". Subsequent web socket frames will be @@ -73,11 +73,11 @@ public class WebSocketServerHandshaker17 extends WebSocketServerHandshaker { * "http://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-17">HyBi * versions 13-17. Versions 13-17 share the same wire protocol. * - * + * *
* Browser request to the server: *
- * + * ** GET /chat HTTP/1.1 * Host: server.example.com @@ -88,11 +88,11 @@ public class WebSocketServerHandshaker17 extends WebSocketServerHandshaker { * Sec-WebSocket-Protocol: chat, superchat * Sec-WebSocket-Version: 13 *- * + * *
* Server response: *
- * + * ** HTTP/1.1 101 Switching Protocols * Upgrade: websocket @@ -100,18 +100,18 @@ public class WebSocketServerHandshaker17 extends WebSocketServerHandshaker { * Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo= * Sec-WebSocket-Protocol: chat *- * - * @param ctx - * Channel context + * + * @param channel + * Channel * @param req * HTTP request * @throws NoSuchAlgorithmException */ @Override - public void performOpeningHandshake(ChannelHandlerContext ctx, HttpRequest req) { + public void performOpeningHandshake(Channel channel, HttpRequest req) { if (logger.isDebugEnabled()) { - logger.debug(String.format("Channel %s web socket spec version 17 handshake", ctx.getChannel().getId())); + logger.debug(String.format("Channel %s web socket spec version 17 handshake", channel.getId())); } HttpResponse res = new DefaultHttpResponse(HTTP_1_1, new HttpResponseStatus(101, "Switching Protocols")); @@ -139,10 +139,10 @@ public class WebSocketServerHandshaker17 extends WebSocketServerHandshaker { res.addHeader(Names.SEC_WEBSOCKET_PROTOCOL, this.selectSubProtocol(protocol)); } - ctx.getChannel().write(res); + channel.write(res); // Upgrade the connection and send the handshake response. - ChannelPipeline p = ctx.getChannel().getPipeline(); + ChannelPipeline p = channel.getPipeline(); p.remove("aggregator"); p.replace("decoder", "wsdecoder", new WebSocket13FrameDecoder(true, this.allowExtensions)); p.replace("encoder", "wsencoder", new WebSocket13FrameEncoder(false)); @@ -151,15 +151,15 @@ public class WebSocketServerHandshaker17 extends WebSocketServerHandshaker { /** * Echo back the closing frame and close the connection - * - * @param ctx - * Channel context + * + * @param channel + * Channel * @param frame * Web Socket frame that was received */ @Override - public void performClosingHandshake(ChannelHandlerContext ctx, CloseWebSocketFrame frame) { - ChannelFuture f = ctx.getChannel().write(frame); + public void performClosingHandshake(Channel channel, CloseWebSocketFrame frame) { + ChannelFuture f = channel.write(frame); f.addListener(ChannelFutureListener.CLOSE); } diff --git a/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketServerHandshakerFactory.java b/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketServerHandshakerFactory.java index 899408d653..de9aef2d69 100644 --- a/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketServerHandshakerFactory.java +++ b/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketServerHandshakerFactory.java @@ -15,7 +15,7 @@ */ package io.netty.handler.codec.http.websocketx; -import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.Channel; import io.netty.handler.codec.http.DefaultHttpResponse; import io.netty.handler.codec.http.HttpRequest; import io.netty.handler.codec.http.HttpResponse; @@ -36,7 +36,7 @@ public class WebSocketServerHandshakerFactory { /** * Constructor specifying the destination web socket location - * + * * @param webSocketURL * URL for web socket communications. e.g * "ws://myhost.com/mypath". Subsequent web socket frames will be @@ -56,11 +56,11 @@ public class WebSocketServerHandshakerFactory { /** * Instances a new handshaker - * + * * @return A new WebSocketServerHandshaker for the requested web socket * version. Null if web socket version is not supported. */ - public WebSocketServerHandshaker newHandshaker(ChannelHandlerContext ctx, HttpRequest req) { + public WebSocketServerHandshaker newHandshaker(HttpRequest req) { String version = req.getHeader(Names.SEC_WEBSOCKET_VERSION); if (version != null) { @@ -83,16 +83,16 @@ public class WebSocketServerHandshakerFactory { /** * Return that we need cannot not support the web socket version - * - * @param ctx - * Context + * + * @param channel + * Channel */ - public void sendUnsupportedWebSocketVersionResponse(ChannelHandlerContext ctx) { + public void sendUnsupportedWebSocketVersionResponse(Channel channel) { HttpResponse res = new DefaultHttpResponse(HttpVersion.HTTP_1_1, new HttpResponseStatus(101, "Switching Protocols")); res.setStatus(HttpResponseStatus.UPGRADE_REQUIRED); res.setHeader(Names.SEC_WEBSOCKET_VERSION, "13"); - ctx.getChannel().write(res); + channel.write(res); } }