From 6e49e107d422c032075043abc016607004b59c53 Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Fri, 9 Dec 2011 14:56:24 +0900 Subject: [PATCH] Better handshaker naming / Remove deprecated example / Hide UTF8 classes from users --- .../http/websocket/WebSocketServer.java | 46 ----- .../websocket/WebSocketServerHandler.java | 182 ------------------ .../websocket/WebSocketServerIndexPage.java | 62 ------ .../WebSocketServerPipelineFactory.java | 38 ---- .../autobahn/WebSocketServerHandler.java | 4 +- .../client/WebSocketClientHandler.java | 4 +- .../server/WebSocketServerHandler.java | 4 +- .../sslserver/WebSocketSslServerHandler.java | 4 +- .../codec/http/websocketx/UTF8Exception.java | 4 +- .../codec/http/websocketx/UTF8Output.java | 4 +- .../websocketx/WebSocketClientHandshaker.java | 4 +- .../WebSocketClientHandshaker00.java | 4 +- .../WebSocketClientHandshaker10.java | 4 +- .../WebSocketClientHandshaker17.java | 4 +- .../websocketx/WebSocketServerHandshaker.java | 4 +- .../WebSocketServerHandshaker00.java | 4 +- .../WebSocketServerHandshaker10.java | 4 +- .../WebSocketServerHandshaker17.java | 4 +- 18 files changed, 28 insertions(+), 356 deletions(-) delete mode 100644 src/main/java/org/jboss/netty/example/http/websocket/WebSocketServer.java delete mode 100644 src/main/java/org/jboss/netty/example/http/websocket/WebSocketServerHandler.java delete mode 100644 src/main/java/org/jboss/netty/example/http/websocket/WebSocketServerIndexPage.java delete mode 100644 src/main/java/org/jboss/netty/example/http/websocket/WebSocketServerPipelineFactory.java diff --git a/src/main/java/org/jboss/netty/example/http/websocket/WebSocketServer.java b/src/main/java/org/jboss/netty/example/http/websocket/WebSocketServer.java deleted file mode 100644 index ce5e8a5c7a..0000000000 --- a/src/main/java/org/jboss/netty/example/http/websocket/WebSocketServer.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package org.jboss.netty.example.http.websocket; - -import java.net.InetSocketAddress; -import java.util.concurrent.Executors; - -import org.jboss.netty.bootstrap.ServerBootstrap; -import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory; - -/** - * An HTTP server which serves Web Socket requests at: - * - * http://localhost:8080/websocket - * - * Open your browser at http://localhost:8080/, then the demo page will be - * loaded and a Web Socket connection will be made automatically. - */ -public class WebSocketServer { - public static void main(String[] args) { - // Configure the server. - ServerBootstrap bootstrap = new ServerBootstrap( - new NioServerSocketChannelFactory( - Executors.newCachedThreadPool(), - Executors.newCachedThreadPool())); - - // Set up the event pipeline factory. - bootstrap.setPipelineFactory(new WebSocketServerPipelineFactory()); - - // Bind and start to accept incoming connections. - bootstrap.bind(new InetSocketAddress(8080)); - } -} diff --git a/src/main/java/org/jboss/netty/example/http/websocket/WebSocketServerHandler.java b/src/main/java/org/jboss/netty/example/http/websocket/WebSocketServerHandler.java deleted file mode 100644 index 09a4426361..0000000000 --- a/src/main/java/org/jboss/netty/example/http/websocket/WebSocketServerHandler.java +++ /dev/null @@ -1,182 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package org.jboss.netty.example.http.websocket; - -import static org.jboss.netty.handler.codec.http.HttpHeaders.*; -import static org.jboss.netty.handler.codec.http.HttpHeaders.Names.*; -import static org.jboss.netty.handler.codec.http.HttpHeaders.Values.*; -import static org.jboss.netty.handler.codec.http.HttpMethod.*; -import static org.jboss.netty.handler.codec.http.HttpResponseStatus.*; -import static org.jboss.netty.handler.codec.http.HttpVersion.*; - -import java.security.MessageDigest; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.jboss.netty.buffer.ChannelBuffers; -import org.jboss.netty.channel.ChannelFuture; -import org.jboss.netty.channel.ChannelFutureListener; -import org.jboss.netty.channel.ChannelHandlerContext; -import org.jboss.netty.channel.ChannelPipeline; -import org.jboss.netty.channel.ExceptionEvent; -import org.jboss.netty.channel.MessageEvent; -import org.jboss.netty.channel.SimpleChannelUpstreamHandler; -import org.jboss.netty.handler.codec.http.DefaultHttpResponse; -import org.jboss.netty.handler.codec.http.HttpHeaders; -import org.jboss.netty.handler.codec.http.HttpRequest; -import org.jboss.netty.handler.codec.http.HttpResponse; -import org.jboss.netty.handler.codec.http.HttpResponseStatus; -import org.jboss.netty.handler.codec.http.HttpHeaders.Names; -import org.jboss.netty.handler.codec.http.HttpHeaders.Values; -import org.jboss.netty.handler.codec.http.websocket.DefaultWebSocketFrame; -import org.jboss.netty.handler.codec.http.websocket.WebSocketFrame; -import org.jboss.netty.handler.codec.http.websocket.WebSocketFrameDecoder; -import org.jboss.netty.handler.codec.http.websocket.WebSocketFrameEncoder; -import org.jboss.netty.util.CharsetUtil; - -/** - */ -public class WebSocketServerHandler extends SimpleChannelUpstreamHandler { - - private static final String WEBSOCKET_PATH = "/websocket"; - - @Override - public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { - Object msg = e.getMessage(); - if (msg instanceof HttpRequest) { - handleHttpRequest(ctx, (HttpRequest) msg); - } else if (msg instanceof WebSocketFrame) { - handleWebSocketFrame(ctx, (WebSocketFrame) msg); - } - } - - private void handleHttpRequest(ChannelHandlerContext ctx, HttpRequest req) throws Exception { - // Allow only GET methods. - if (req.getMethod() != GET) { - sendHttpResponse( - ctx, req, new DefaultHttpResponse(HTTP_1_1, FORBIDDEN)); - return; - } - - // Send the demo page. - if (req.getUri().equals("/")) { - HttpResponse res = new DefaultHttpResponse(HTTP_1_1, OK); - - ChannelBuffer content = - WebSocketServerIndexPage.getContent(getWebSocketLocation(req)); - - res.setHeader(CONTENT_TYPE, "text/html; charset=UTF-8"); - setContentLength(res, content.readableBytes()); - - res.setContent(content); - sendHttpResponse(ctx, req, res); - return; - } - - // Serve the WebSocket handshake request. - if (req.getUri().equals(WEBSOCKET_PATH) && - Values.UPGRADE.equalsIgnoreCase(req.getHeader(CONNECTION)) && - WEBSOCKET.equalsIgnoreCase(req.getHeader(Names.UPGRADE))) { - - // Create the WebSocket handshake response. - HttpResponse res = new DefaultHttpResponse( - HTTP_1_1, - new HttpResponseStatus(101, "Web Socket Protocol Handshake")); - res.addHeader(Names.UPGRADE, WEBSOCKET); - res.addHeader(CONNECTION, Values.UPGRADE); - - // Fill in the headers and contents depending on handshake method. - if (req.containsHeader(SEC_WEBSOCKET_KEY1) && - req.containsHeader(SEC_WEBSOCKET_KEY2)) { - // New handshake method with a challenge: - res.addHeader(SEC_WEBSOCKET_ORIGIN, req.getHeader(ORIGIN)); - res.addHeader(SEC_WEBSOCKET_LOCATION, getWebSocketLocation(req)); - String protocol = req.getHeader(SEC_WEBSOCKET_PROTOCOL); - if (protocol != null) { - res.addHeader(SEC_WEBSOCKET_PROTOCOL, protocol); - } - - // Calculate the answer of the challenge. - String key1 = req.getHeader(SEC_WEBSOCKET_KEY1); - String key2 = req.getHeader(SEC_WEBSOCKET_KEY2); - int a = (int) (Long.parseLong(key1.replaceAll("[^0-9]", "")) / key1.replaceAll("[^ ]", "").length()); - int b = (int) (Long.parseLong(key2.replaceAll("[^0-9]", "")) / key2.replaceAll("[^ ]", "").length()); - long c = req.getContent().readLong(); - ChannelBuffer input = ChannelBuffers.buffer(16); - input.writeInt(a); - input.writeInt(b); - input.writeLong(c); - ChannelBuffer output = ChannelBuffers.wrappedBuffer( - MessageDigest.getInstance("MD5").digest(input.array())); - res.setContent(output); - } else { - // Old handshake method with no challenge: - res.addHeader(WEBSOCKET_ORIGIN, req.getHeader(ORIGIN)); - res.addHeader(WEBSOCKET_LOCATION, getWebSocketLocation(req)); - String protocol = req.getHeader(WEBSOCKET_PROTOCOL); - if (protocol != null) { - res.addHeader(WEBSOCKET_PROTOCOL, protocol); - } - } - - // Upgrade the connection and send the handshake response. - ChannelPipeline p = ctx.getChannel().getPipeline(); - p.remove("aggregator"); - p.replace("decoder", "wsdecoder", new WebSocketFrameDecoder()); - - ctx.getChannel().write(res); - - p.replace("encoder", "wsencoder", new WebSocketFrameEncoder()); - return; - } - - // Send an error page otherwise. - sendHttpResponse( - ctx, req, new DefaultHttpResponse(HTTP_1_1, FORBIDDEN)); - } - - private void handleWebSocketFrame(ChannelHandlerContext ctx, WebSocketFrame frame) { - // Send the uppercased string back. - ctx.getChannel().write( - new DefaultWebSocketFrame(frame.getTextData().toUpperCase())); - } - - private void sendHttpResponse(ChannelHandlerContext ctx, HttpRequest req, HttpResponse res) { - // Generate an error page if response status code is not OK (200). - if (res.getStatus().getCode() != 200) { - res.setContent( - ChannelBuffers.copiedBuffer( - res.getStatus().toString(), CharsetUtil.UTF_8)); - setContentLength(res, res.getContent().readableBytes()); - } - - // Send the response and close the connection if necessary. - ChannelFuture f = ctx.getChannel().write(res); - if (!isKeepAlive(req) || res.getStatus().getCode() != 200) { - f.addListener(ChannelFutureListener.CLOSE); - } - } - - @Override - public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) - throws Exception { - e.getCause().printStackTrace(); - e.getChannel().close(); - } - - private String getWebSocketLocation(HttpRequest req) { - return "ws://" + req.getHeader(HttpHeaders.Names.HOST) + WEBSOCKET_PATH; - } -} diff --git a/src/main/java/org/jboss/netty/example/http/websocket/WebSocketServerIndexPage.java b/src/main/java/org/jboss/netty/example/http/websocket/WebSocketServerIndexPage.java deleted file mode 100644 index 47f5ab4a83..0000000000 --- a/src/main/java/org/jboss/netty/example/http/websocket/WebSocketServerIndexPage.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package org.jboss.netty.example.http.websocket; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.jboss.netty.buffer.ChannelBuffers; -import org.jboss.netty.util.CharsetUtil; - - -/** - * Generates the demo HTML page which is served at http://localhost:8080/ - */ -public class WebSocketServerIndexPage { - - private static final String NEWLINE = "\r\n"; - - public static ChannelBuffer getContent(String webSocketLocation) { - return ChannelBuffers.copiedBuffer( - "Web Socket Test" + NEWLINE + - "" + NEWLINE + - "" + NEWLINE + - "
" + NEWLINE + - "" + - "" + NEWLINE + - "
" + NEWLINE + - "" + NEWLINE + - "" + NEWLINE, - CharsetUtil.US_ASCII); - } -} diff --git a/src/main/java/org/jboss/netty/example/http/websocket/WebSocketServerPipelineFactory.java b/src/main/java/org/jboss/netty/example/http/websocket/WebSocketServerPipelineFactory.java deleted file mode 100644 index 591f5d1ee7..0000000000 --- a/src/main/java/org/jboss/netty/example/http/websocket/WebSocketServerPipelineFactory.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2011 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package org.jboss.netty.example.http.websocket; - -import static org.jboss.netty.channel.Channels.*; - -import org.jboss.netty.channel.ChannelPipeline; -import org.jboss.netty.channel.ChannelPipelineFactory; -import org.jboss.netty.handler.codec.http.HttpChunkAggregator; -import org.jboss.netty.handler.codec.http.HttpRequestDecoder; -import org.jboss.netty.handler.codec.http.HttpResponseEncoder; - -/** - */ -public class WebSocketServerPipelineFactory implements ChannelPipelineFactory { - public ChannelPipeline getPipeline() throws Exception { - // Create a default pipeline implementation. - ChannelPipeline pipeline = pipeline(); - pipeline.addLast("decoder", new HttpRequestDecoder()); - pipeline.addLast("aggregator", new HttpChunkAggregator(65536)); - pipeline.addLast("encoder", new HttpResponseEncoder()); - pipeline.addLast("handler", new WebSocketServerHandler()); - return pipeline; - } -} diff --git a/src/main/java/org/jboss/netty/example/http/websocketx/autobahn/WebSocketServerHandler.java b/src/main/java/org/jboss/netty/example/http/websocketx/autobahn/WebSocketServerHandler.java index 4d4b51e540..952dc2537d 100644 --- a/src/main/java/org/jboss/netty/example/http/websocketx/autobahn/WebSocketServerHandler.java +++ b/src/main/java/org/jboss/netty/example/http/websocketx/autobahn/WebSocketServerHandler.java @@ -76,7 +76,7 @@ public class WebSocketServerHandler extends SimpleChannelUpstreamHandler { if (this.handshaker == null) { wsFactory.sendUnsupportedWebSocketVersionResponse(ctx); } else { - this.handshaker.executeOpeningHandshake(ctx, req); + this.handshaker.performOpeningHandshake(ctx, req); } } @@ -85,7 +85,7 @@ public class WebSocketServerHandler extends SimpleChannelUpstreamHandler { .format("Channel %s received %s", ctx.getChannel().getId(), frame.getClass().getSimpleName())); if (frame instanceof CloseWebSocketFrame) { - this.handshaker.executeClosingHandshake(ctx, (CloseWebSocketFrame) frame); + this.handshaker.performClosingHandshake(ctx, (CloseWebSocketFrame) frame); } else if (frame instanceof PingWebSocketFrame) { ctx.getChannel().write( new PongWebSocketFrame(frame.isFinalFragment(), frame.getRsv(), frame.getBinaryData())); diff --git a/src/main/java/org/jboss/netty/example/http/websocketx/client/WebSocketClientHandler.java b/src/main/java/org/jboss/netty/example/http/websocketx/client/WebSocketClientHandler.java index 29688b5d73..f2dcd4cab0 100644 --- a/src/main/java/org/jboss/netty/example/http/websocketx/client/WebSocketClientHandler.java +++ b/src/main/java/org/jboss/netty/example/http/websocketx/client/WebSocketClientHandler.java @@ -66,7 +66,7 @@ public class WebSocketClientHandler extends SimpleChannelUpstreamHandler impleme public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception { channel = e.getChannel(); this.handshaker = new WebSocketClientHandshakerFactory().newHandshaker(url, version, null, false); - handshaker.beginOpeningHandshake(ctx, channel); + handshaker.performOpeningHandshake(ctx, channel); } @Override @@ -77,7 +77,7 @@ public class WebSocketClientHandler extends SimpleChannelUpstreamHandler impleme @Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { if (!handshaker.isOpeningHandshakeCompleted()) { - handshaker.endOpeningHandshake(ctx, (HttpResponse) e.getMessage()); + handshaker.performClosingHandshake(ctx, (HttpResponse) e.getMessage()); callback.onConnect(this); return; } diff --git a/src/main/java/org/jboss/netty/example/http/websocketx/server/WebSocketServerHandler.java b/src/main/java/org/jboss/netty/example/http/websocketx/server/WebSocketServerHandler.java index b60ef94cca..a0761c685c 100644 --- a/src/main/java/org/jboss/netty/example/http/websocketx/server/WebSocketServerHandler.java +++ b/src/main/java/org/jboss/netty/example/http/websocketx/server/WebSocketServerHandler.java @@ -96,7 +96,7 @@ public class WebSocketServerHandler extends SimpleChannelUpstreamHandler { if (this.handshaker == null) { wsFactory.sendUnsupportedWebSocketVersionResponse(ctx); } else { - this.handshaker.executeOpeningHandshake(ctx, req); + this.handshaker.performOpeningHandshake(ctx, req); } } @@ -104,7 +104,7 @@ public class WebSocketServerHandler extends SimpleChannelUpstreamHandler { // Check for closing frame if (frame instanceof CloseWebSocketFrame) { - this.handshaker.executeClosingHandshake(ctx, (CloseWebSocketFrame) frame); + this.handshaker.performClosingHandshake(ctx, (CloseWebSocketFrame) frame); return; } else if (frame instanceof PingWebSocketFrame) { ctx.getChannel().write(new PongWebSocketFrame(frame.getBinaryData())); diff --git a/src/main/java/org/jboss/netty/example/http/websocketx/sslserver/WebSocketSslServerHandler.java b/src/main/java/org/jboss/netty/example/http/websocketx/sslserver/WebSocketSslServerHandler.java index fc4bcf3a14..05198dc859 100644 --- a/src/main/java/org/jboss/netty/example/http/websocketx/sslserver/WebSocketSslServerHandler.java +++ b/src/main/java/org/jboss/netty/example/http/websocketx/sslserver/WebSocketSslServerHandler.java @@ -96,7 +96,7 @@ public class WebSocketSslServerHandler extends SimpleChannelUpstreamHandler { if (this.handshaker == null) { wsFactory.sendUnsupportedWebSocketVersionResponse(ctx); } else { - this.handshaker.executeOpeningHandshake(ctx, req); + this.handshaker.performOpeningHandshake(ctx, req); } } @@ -104,7 +104,7 @@ public class WebSocketSslServerHandler extends SimpleChannelUpstreamHandler { // Check for closing frame if (frame instanceof CloseWebSocketFrame) { - this.handshaker.executeClosingHandshake(ctx, (CloseWebSocketFrame) frame); + this.handshaker.performClosingHandshake(ctx, (CloseWebSocketFrame) frame); return; } else if (frame instanceof PingWebSocketFrame) { ctx.getChannel().write(new PongWebSocketFrame(frame.getBinaryData())); diff --git a/src/main/java/org/jboss/netty/handler/codec/http/websocketx/UTF8Exception.java b/src/main/java/org/jboss/netty/handler/codec/http/websocketx/UTF8Exception.java index fa62482537..2cae22e0fd 100644 --- a/src/main/java/org/jboss/netty/handler/codec/http/websocketx/UTF8Exception.java +++ b/src/main/java/org/jboss/netty/handler/codec/http/websocketx/UTF8Exception.java @@ -22,10 +22,10 @@ package org.jboss.netty.handler.codec.http.websocketx; /** * Invalid UTF8 bytes encountered */ -public class UTF8Exception extends RuntimeException { +final class UTF8Exception extends RuntimeException { private static final long serialVersionUID = 1L; - public UTF8Exception(String reason) { + UTF8Exception(String reason) { super(reason); } } diff --git a/src/main/java/org/jboss/netty/handler/codec/http/websocketx/UTF8Output.java b/src/main/java/org/jboss/netty/handler/codec/http/websocketx/UTF8Output.java index 987be86969..4001463f23 100644 --- a/src/main/java/org/jboss/netty/handler/codec/http/websocketx/UTF8Output.java +++ b/src/main/java/org/jboss/netty/handler/codec/http/websocketx/UTF8Output.java @@ -22,7 +22,7 @@ package org.jboss.netty.handler.codec.http.websocketx; /** * Checks UTF8 bytes for validity before converting it into a string */ -public class UTF8Output { +final class UTF8Output { private static final int UTF8_ACCEPT = 0; private static final int UTF8_REJECT = 12; @@ -38,7 +38,7 @@ public class UTF8Output { private final StringBuilder stringBuilder; - public UTF8Output(byte[] bytes) { + UTF8Output(byte[] bytes) { stringBuilder = new StringBuilder(bytes.length); write(bytes); } diff --git a/src/main/java/org/jboss/netty/handler/codec/http/websocketx/WebSocketClientHandshaker.java b/src/main/java/org/jboss/netty/handler/codec/http/websocketx/WebSocketClientHandshaker.java index 2530981808..f4920fbe72 100644 --- a/src/main/java/org/jboss/netty/handler/codec/http/websocketx/WebSocketClientHandshaker.java +++ b/src/main/java/org/jboss/netty/handler/codec/http/websocketx/WebSocketClientHandshaker.java @@ -119,7 +119,7 @@ public abstract class WebSocketClientHandshaker { * @param channel * Channel */ - public abstract void beginOpeningHandshake(ChannelHandlerContext ctx, Channel channel); + public abstract void performOpeningHandshake(ChannelHandlerContext ctx, Channel channel); /** * Performs the closing handshake @@ -129,7 +129,7 @@ public abstract class WebSocketClientHandshaker { * @param response * HTTP response containing the closing handshake details */ - public abstract void endOpeningHandshake(ChannelHandlerContext ctx, HttpResponse response) throws WebSocketHandshakeException; + public abstract void performClosingHandshake(ChannelHandlerContext ctx, HttpResponse response) throws WebSocketHandshakeException; /** * Performs an MD5 hash diff --git a/src/main/java/org/jboss/netty/handler/codec/http/websocketx/WebSocketClientHandshaker00.java b/src/main/java/org/jboss/netty/handler/codec/http/websocketx/WebSocketClientHandshaker00.java index 3eca6b7625..f790e5ac5e 100644 --- a/src/main/java/org/jboss/netty/handler/codec/http/websocketx/WebSocketClientHandshaker00.java +++ b/src/main/java/org/jboss/netty/handler/codec/http/websocketx/WebSocketClientHandshaker00.java @@ -87,7 +87,7 @@ public class WebSocketClientHandshaker00 extends WebSocketClientHandshaker { * Channel into which we can write our request */ @Override - public void beginOpeningHandshake(ChannelHandlerContext ctx, Channel channel) { + public void performOpeningHandshake(ChannelHandlerContext ctx, Channel channel) { // Make keys int spaces1 = createRandomNumber(1, 12); int spaces2 = createRandomNumber(1, 12); @@ -174,7 +174,7 @@ public class WebSocketClientHandshaker00 extends WebSocketClientHandshaker { * @throws WebSocketHandshakeException */ @Override - public void endOpeningHandshake(ChannelHandlerContext ctx, HttpResponse response) throws WebSocketHandshakeException { + public void performClosingHandshake(ChannelHandlerContext ctx, HttpResponse response) throws WebSocketHandshakeException { final HttpResponseStatus status = new HttpResponseStatus(101, "WebSocket Protocol Handshake"); if (!response.getStatus().equals(status)) { diff --git a/src/main/java/org/jboss/netty/handler/codec/http/websocketx/WebSocketClientHandshaker10.java b/src/main/java/org/jboss/netty/handler/codec/http/websocketx/WebSocketClientHandshaker10.java index 434cee4317..d35abaabed 100644 --- a/src/main/java/org/jboss/netty/handler/codec/http/websocketx/WebSocketClientHandshaker10.java +++ b/src/main/java/org/jboss/netty/handler/codec/http/websocketx/WebSocketClientHandshaker10.java @@ -96,7 +96,7 @@ public class WebSocketClientHandshaker10 extends WebSocketClientHandshaker { * Channel into which we can write our request */ @Override - public void beginOpeningHandshake(ChannelHandlerContext ctx, Channel channel) { + public void performOpeningHandshake(ChannelHandlerContext ctx, Channel channel) { // Get path URI wsURL = this.getWebSocketURL(); String path = wsURL.getPath(); @@ -154,7 +154,7 @@ public class WebSocketClientHandshaker10 extends WebSocketClientHandshaker { * @throws WebSocketHandshakeException */ @Override - public void endOpeningHandshake(ChannelHandlerContext ctx, HttpResponse response) throws WebSocketHandshakeException { + public void performClosingHandshake(ChannelHandlerContext ctx, HttpResponse response) throws WebSocketHandshakeException { final HttpResponseStatus status = new HttpResponseStatus(101, "Switching Protocols"); if (!response.getStatus().equals(status)) { diff --git a/src/main/java/org/jboss/netty/handler/codec/http/websocketx/WebSocketClientHandshaker17.java b/src/main/java/org/jboss/netty/handler/codec/http/websocketx/WebSocketClientHandshaker17.java index 3133d9447a..b3c69d3671 100644 --- a/src/main/java/org/jboss/netty/handler/codec/http/websocketx/WebSocketClientHandshaker17.java +++ b/src/main/java/org/jboss/netty/handler/codec/http/websocketx/WebSocketClientHandshaker17.java @@ -96,7 +96,7 @@ public class WebSocketClientHandshaker17 extends WebSocketClientHandshaker { * Channel into which we can write our request */ @Override - public void beginOpeningHandshake(ChannelHandlerContext ctx, Channel channel) { + public void performOpeningHandshake(ChannelHandlerContext ctx, Channel channel) { // Get path URI wsURL = this.getWebSocketURL(); String path = wsURL.getPath(); @@ -154,7 +154,7 @@ public class WebSocketClientHandshaker17 extends WebSocketClientHandshaker { * @throws WebSocketHandshakeException */ @Override - public void endOpeningHandshake(ChannelHandlerContext ctx, HttpResponse response) throws WebSocketHandshakeException { + public void performClosingHandshake(ChannelHandlerContext ctx, HttpResponse response) throws WebSocketHandshakeException { final HttpResponseStatus status = new HttpResponseStatus(101, "Switching Protocols"); if (!response.getStatus().equals(status)) { diff --git a/src/main/java/org/jboss/netty/handler/codec/http/websocketx/WebSocketServerHandshaker.java b/src/main/java/org/jboss/netty/handler/codec/http/websocketx/WebSocketServerHandshaker.java index bd87da83a0..8ac8083078 100644 --- a/src/main/java/org/jboss/netty/handler/codec/http/websocketx/WebSocketServerHandshaker.java +++ b/src/main/java/org/jboss/netty/handler/codec/http/websocketx/WebSocketServerHandshaker.java @@ -103,7 +103,7 @@ public abstract class WebSocketServerHandshaker { * HTTP Request * @throws NoSuchAlgorithmException */ - public abstract void executeOpeningHandshake(ChannelHandlerContext ctx, HttpRequest req); + public abstract void performOpeningHandshake(ChannelHandlerContext ctx, HttpRequest req); /** * Performs the closing handshake @@ -113,7 +113,7 @@ public abstract class WebSocketServerHandshaker { * @param frame * Closing Frame that was received */ - public abstract void executeClosingHandshake(ChannelHandlerContext ctx, CloseWebSocketFrame frame); + public abstract void performClosingHandshake(ChannelHandlerContext ctx, CloseWebSocketFrame frame); /** * Performs an MD5 hash diff --git a/src/main/java/org/jboss/netty/handler/codec/http/websocketx/WebSocketServerHandshaker00.java b/src/main/java/org/jboss/netty/handler/codec/http/websocketx/WebSocketServerHandshaker00.java index 4679aa4cc2..9c697d7d15 100644 --- a/src/main/java/org/jboss/netty/handler/codec/http/websocketx/WebSocketServerHandshaker00.java +++ b/src/main/java/org/jboss/netty/handler/codec/http/websocketx/WebSocketServerHandshaker00.java @@ -121,7 +121,7 @@ public class WebSocketServerHandshaker00 extends WebSocketServerHandshaker { * @throws NoSuchAlgorithmException */ @Override - public void executeOpeningHandshake(ChannelHandlerContext ctx, HttpRequest req) { + public void performOpeningHandshake(ChannelHandlerContext ctx, HttpRequest req) { if (logger.isDebugEnabled()) { logger.debug(String.format("Channel %s web socket spec version 00 handshake", ctx.getChannel().getId())); @@ -192,7 +192,7 @@ public class WebSocketServerHandshaker00 extends WebSocketServerHandshaker { * Web Socket frame that was received */ @Override - public void executeClosingHandshake(ChannelHandlerContext ctx, CloseWebSocketFrame frame) { + public void performClosingHandshake(ChannelHandlerContext ctx, CloseWebSocketFrame frame) { ctx.getChannel().write(frame); } } diff --git a/src/main/java/org/jboss/netty/handler/codec/http/websocketx/WebSocketServerHandshaker10.java b/src/main/java/org/jboss/netty/handler/codec/http/websocketx/WebSocketServerHandshaker10.java index 01d1e11d24..bc4c9c178d 100644 --- a/src/main/java/org/jboss/netty/handler/codec/http/websocketx/WebSocketServerHandshaker10.java +++ b/src/main/java/org/jboss/netty/handler/codec/http/websocketx/WebSocketServerHandshaker10.java @@ -108,7 +108,7 @@ public class WebSocketServerHandshaker10 extends WebSocketServerHandshaker { * @throws NoSuchAlgorithmException */ @Override - public void executeOpeningHandshake(ChannelHandlerContext ctx, HttpRequest req) { + public void performOpeningHandshake(ChannelHandlerContext ctx, HttpRequest req) { if (logger.isDebugEnabled()) { logger.debug(String.format("Channel %s web socket spec version 10 handshake", ctx.getChannel().getId())); @@ -158,7 +158,7 @@ public class WebSocketServerHandshaker10 extends WebSocketServerHandshaker { * Web Socket frame that was received */ @Override - public void executeClosingHandshake(ChannelHandlerContext ctx, CloseWebSocketFrame frame) { + public void performClosingHandshake(ChannelHandlerContext ctx, CloseWebSocketFrame frame) { ChannelFuture f = ctx.getChannel().write(frame); f.addListener(ChannelFutureListener.CLOSE); } diff --git a/src/main/java/org/jboss/netty/handler/codec/http/websocketx/WebSocketServerHandshaker17.java b/src/main/java/org/jboss/netty/handler/codec/http/websocketx/WebSocketServerHandshaker17.java index 5920b1f4cb..fcbc6e2047 100644 --- a/src/main/java/org/jboss/netty/handler/codec/http/websocketx/WebSocketServerHandshaker17.java +++ b/src/main/java/org/jboss/netty/handler/codec/http/websocketx/WebSocketServerHandshaker17.java @@ -108,7 +108,7 @@ public class WebSocketServerHandshaker17 extends WebSocketServerHandshaker { * @throws NoSuchAlgorithmException */ @Override - public void executeOpeningHandshake(ChannelHandlerContext ctx, HttpRequest req) { + public void performOpeningHandshake(ChannelHandlerContext ctx, HttpRequest req) { if (logger.isDebugEnabled()) { logger.debug(String.format("Channel %s web socket spec version 17 handshake", ctx.getChannel().getId())); @@ -158,7 +158,7 @@ public class WebSocketServerHandshaker17 extends WebSocketServerHandshaker { * Web Socket frame that was received */ @Override - public void executeClosingHandshake(ChannelHandlerContext ctx, CloseWebSocketFrame frame) { + public void performClosingHandshake(ChannelHandlerContext ctx, CloseWebSocketFrame frame) { ChannelFuture f = ctx.getChannel().write(frame); f.addListener(ChannelFutureListener.CLOSE); }