Better handshaker naming / Remove deprecated example / Hide UTF8 classes from users

This commit is contained in:
Trustin Lee 2011-12-09 14:58:36 +09:00
parent 82aa0969e2
commit 07f2c2e7da
14 changed files with 28 additions and 28 deletions

View File

@ -76,7 +76,7 @@ public class WebSocketServerHandler extends SimpleChannelUpstreamHandler {
if (this.handshaker == null) { if (this.handshaker == null) {
wsFactory.sendUnsupportedWebSocketVersionResponse(ctx); wsFactory.sendUnsupportedWebSocketVersionResponse(ctx);
} else { } 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())); .format("Channel %s received %s", ctx.getChannel().getId(), frame.getClass().getSimpleName()));
if (frame instanceof CloseWebSocketFrame) { if (frame instanceof CloseWebSocketFrame) {
this.handshaker.executeClosingHandshake(ctx, (CloseWebSocketFrame) frame); this.handshaker.performClosingHandshake(ctx, (CloseWebSocketFrame) frame);
} else if (frame instanceof PingWebSocketFrame) { } else if (frame instanceof PingWebSocketFrame) {
ctx.getChannel().write( ctx.getChannel().write(
new PongWebSocketFrame(frame.isFinalFragment(), frame.getRsv(), frame.getBinaryData())); new PongWebSocketFrame(frame.isFinalFragment(), frame.getRsv(), frame.getBinaryData()));

View File

@ -66,7 +66,7 @@ public class WebSocketClientHandler extends SimpleChannelUpstreamHandler impleme
public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception { public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
channel = e.getChannel(); channel = e.getChannel();
this.handshaker = new WebSocketClientHandshakerFactory().newHandshaker(url, version, null, false); this.handshaker = new WebSocketClientHandshakerFactory().newHandshaker(url, version, null, false);
handshaker.beginOpeningHandshake(ctx, channel); handshaker.performOpeningHandshake(ctx, channel);
} }
@Override @Override
@ -77,7 +77,7 @@ public class WebSocketClientHandler extends SimpleChannelUpstreamHandler impleme
@Override @Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
if (!handshaker.isOpeningHandshakeCompleted()) { if (!handshaker.isOpeningHandshakeCompleted()) {
handshaker.endOpeningHandshake(ctx, (HttpResponse) e.getMessage()); handshaker.performClosingHandshake(ctx, (HttpResponse) e.getMessage());
callback.onConnect(this); callback.onConnect(this);
return; return;
} }

View File

@ -96,7 +96,7 @@ public class WebSocketServerHandler extends SimpleChannelUpstreamHandler {
if (this.handshaker == null) { if (this.handshaker == null) {
wsFactory.sendUnsupportedWebSocketVersionResponse(ctx); wsFactory.sendUnsupportedWebSocketVersionResponse(ctx);
} else { } else {
this.handshaker.executeOpeningHandshake(ctx, req); this.handshaker.performOpeningHandshake(ctx, req);
} }
} }
@ -104,7 +104,7 @@ public class WebSocketServerHandler extends SimpleChannelUpstreamHandler {
// Check for closing frame // Check for closing frame
if (frame instanceof CloseWebSocketFrame) { if (frame instanceof CloseWebSocketFrame) {
this.handshaker.executeClosingHandshake(ctx, (CloseWebSocketFrame) frame); this.handshaker.performClosingHandshake(ctx, (CloseWebSocketFrame) frame);
return; return;
} else if (frame instanceof PingWebSocketFrame) { } else if (frame instanceof PingWebSocketFrame) {
ctx.getChannel().write(new PongWebSocketFrame(frame.getBinaryData())); ctx.getChannel().write(new PongWebSocketFrame(frame.getBinaryData()));

View File

@ -96,7 +96,7 @@ public class WebSocketSslServerHandler extends SimpleChannelUpstreamHandler {
if (this.handshaker == null) { if (this.handshaker == null) {
wsFactory.sendUnsupportedWebSocketVersionResponse(ctx); wsFactory.sendUnsupportedWebSocketVersionResponse(ctx);
} else { } else {
this.handshaker.executeOpeningHandshake(ctx, req); this.handshaker.performOpeningHandshake(ctx, req);
} }
} }
@ -104,7 +104,7 @@ public class WebSocketSslServerHandler extends SimpleChannelUpstreamHandler {
// Check for closing frame // Check for closing frame
if (frame instanceof CloseWebSocketFrame) { if (frame instanceof CloseWebSocketFrame) {
this.handshaker.executeClosingHandshake(ctx, (CloseWebSocketFrame) frame); this.handshaker.performClosingHandshake(ctx, (CloseWebSocketFrame) frame);
return; return;
} else if (frame instanceof PingWebSocketFrame) { } else if (frame instanceof PingWebSocketFrame) {
ctx.getChannel().write(new PongWebSocketFrame(frame.getBinaryData())); ctx.getChannel().write(new PongWebSocketFrame(frame.getBinaryData()));

View File

@ -22,10 +22,10 @@ package io.netty.handler.codec.http.websocketx;
/** /**
* Invalid UTF8 bytes encountered * Invalid UTF8 bytes encountered
*/ */
public class UTF8Exception extends RuntimeException { final class UTF8Exception extends RuntimeException {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
public UTF8Exception(String reason) { UTF8Exception(String reason) {
super(reason); super(reason);
} }
} }

View File

@ -22,7 +22,7 @@ package io.netty.handler.codec.http.websocketx;
/** /**
* Checks UTF8 bytes for validity before converting it into a string * 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_ACCEPT = 0;
private static final int UTF8_REJECT = 12; private static final int UTF8_REJECT = 12;
@ -38,7 +38,7 @@ public class UTF8Output {
private final StringBuilder stringBuilder; private final StringBuilder stringBuilder;
public UTF8Output(byte[] bytes) { UTF8Output(byte[] bytes) {
stringBuilder = new StringBuilder(bytes.length); stringBuilder = new StringBuilder(bytes.length);
write(bytes); write(bytes);
} }

View File

@ -119,7 +119,7 @@ public abstract class WebSocketClientHandshaker {
* @param channel * @param channel
* Channel * Channel
*/ */
public abstract void beginOpeningHandshake(ChannelHandlerContext ctx, Channel channel); public abstract void performOpeningHandshake(ChannelHandlerContext ctx, Channel channel);
/** /**
* Performs the closing handshake * Performs the closing handshake
@ -129,7 +129,7 @@ public abstract class WebSocketClientHandshaker {
* @param response * @param response
* HTTP response containing the closing handshake details * 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 * Performs an MD5 hash

View File

@ -87,7 +87,7 @@ public class WebSocketClientHandshaker00 extends WebSocketClientHandshaker {
* Channel into which we can write our request * Channel into which we can write our request
*/ */
@Override @Override
public void beginOpeningHandshake(ChannelHandlerContext ctx, Channel channel) { public void performOpeningHandshake(ChannelHandlerContext ctx, Channel channel) {
// Make keys // Make keys
int spaces1 = createRandomNumber(1, 12); int spaces1 = createRandomNumber(1, 12);
int spaces2 = createRandomNumber(1, 12); int spaces2 = createRandomNumber(1, 12);
@ -174,7 +174,7 @@ public class WebSocketClientHandshaker00 extends WebSocketClientHandshaker {
* @throws WebSocketHandshakeException * @throws WebSocketHandshakeException
*/ */
@Override @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"); final HttpResponseStatus status = new HttpResponseStatus(101, "WebSocket Protocol Handshake");
if (!response.getStatus().equals(status)) { if (!response.getStatus().equals(status)) {

View File

@ -96,7 +96,7 @@ public class WebSocketClientHandshaker10 extends WebSocketClientHandshaker {
* Channel into which we can write our request * Channel into which we can write our request
*/ */
@Override @Override
public void beginOpeningHandshake(ChannelHandlerContext ctx, Channel channel) { public void performOpeningHandshake(ChannelHandlerContext ctx, Channel channel) {
// Get path // Get path
URI wsURL = this.getWebSocketURL(); URI wsURL = this.getWebSocketURL();
String path = wsURL.getPath(); String path = wsURL.getPath();
@ -154,7 +154,7 @@ public class WebSocketClientHandshaker10 extends WebSocketClientHandshaker {
* @throws WebSocketHandshakeException * @throws WebSocketHandshakeException
*/ */
@Override @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"); final HttpResponseStatus status = new HttpResponseStatus(101, "Switching Protocols");
if (!response.getStatus().equals(status)) { if (!response.getStatus().equals(status)) {

View File

@ -96,7 +96,7 @@ public class WebSocketClientHandshaker17 extends WebSocketClientHandshaker {
* Channel into which we can write our request * Channel into which we can write our request
*/ */
@Override @Override
public void beginOpeningHandshake(ChannelHandlerContext ctx, Channel channel) { public void performOpeningHandshake(ChannelHandlerContext ctx, Channel channel) {
// Get path // Get path
URI wsURL = this.getWebSocketURL(); URI wsURL = this.getWebSocketURL();
String path = wsURL.getPath(); String path = wsURL.getPath();
@ -154,7 +154,7 @@ public class WebSocketClientHandshaker17 extends WebSocketClientHandshaker {
* @throws WebSocketHandshakeException * @throws WebSocketHandshakeException
*/ */
@Override @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"); final HttpResponseStatus status = new HttpResponseStatus(101, "Switching Protocols");
if (!response.getStatus().equals(status)) { if (!response.getStatus().equals(status)) {

View File

@ -103,7 +103,7 @@ public abstract class WebSocketServerHandshaker {
* HTTP Request * HTTP Request
* @throws NoSuchAlgorithmException * @throws NoSuchAlgorithmException
*/ */
public abstract void executeOpeningHandshake(ChannelHandlerContext ctx, HttpRequest req); public abstract void performOpeningHandshake(ChannelHandlerContext ctx, HttpRequest req);
/** /**
* Performs the closing handshake * Performs the closing handshake
@ -113,7 +113,7 @@ public abstract class WebSocketServerHandshaker {
* @param frame * @param frame
* Closing Frame that was received * 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 * Performs an MD5 hash

View File

@ -121,7 +121,7 @@ public class WebSocketServerHandshaker00 extends WebSocketServerHandshaker {
* @throws NoSuchAlgorithmException * @throws NoSuchAlgorithmException
*/ */
@Override @Override
public void executeOpeningHandshake(ChannelHandlerContext ctx, HttpRequest req) { public void performOpeningHandshake(ChannelHandlerContext ctx, HttpRequest req) {
if (logger.isDebugEnabled()) { 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", ctx.getChannel().getId()));
@ -192,7 +192,7 @@ public class WebSocketServerHandshaker00 extends WebSocketServerHandshaker {
* Web Socket frame that was received * Web Socket frame that was received
*/ */
@Override @Override
public void executeClosingHandshake(ChannelHandlerContext ctx, CloseWebSocketFrame frame) { public void performClosingHandshake(ChannelHandlerContext ctx, CloseWebSocketFrame frame) {
ctx.getChannel().write(frame); ctx.getChannel().write(frame);
} }
} }

View File

@ -108,7 +108,7 @@ public class WebSocketServerHandshaker10 extends WebSocketServerHandshaker {
* @throws NoSuchAlgorithmException * @throws NoSuchAlgorithmException
*/ */
@Override @Override
public void executeOpeningHandshake(ChannelHandlerContext ctx, HttpRequest req) { public void performOpeningHandshake(ChannelHandlerContext ctx, HttpRequest req) {
if (logger.isDebugEnabled()) { 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", ctx.getChannel().getId()));
@ -158,7 +158,7 @@ public class WebSocketServerHandshaker10 extends WebSocketServerHandshaker {
* Web Socket frame that was received * Web Socket frame that was received
*/ */
@Override @Override
public void executeClosingHandshake(ChannelHandlerContext ctx, CloseWebSocketFrame frame) { public void performClosingHandshake(ChannelHandlerContext ctx, CloseWebSocketFrame frame) {
ChannelFuture f = ctx.getChannel().write(frame); ChannelFuture f = ctx.getChannel().write(frame);
f.addListener(ChannelFutureListener.CLOSE); f.addListener(ChannelFutureListener.CLOSE);
} }

View File

@ -108,7 +108,7 @@ public class WebSocketServerHandshaker17 extends WebSocketServerHandshaker {
* @throws NoSuchAlgorithmException * @throws NoSuchAlgorithmException
*/ */
@Override @Override
public void executeOpeningHandshake(ChannelHandlerContext ctx, HttpRequest req) { public void performOpeningHandshake(ChannelHandlerContext ctx, HttpRequest req) {
if (logger.isDebugEnabled()) { 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", ctx.getChannel().getId()));
@ -158,7 +158,7 @@ public class WebSocketServerHandshaker17 extends WebSocketServerHandshaker {
* Web Socket frame that was received * Web Socket frame that was received
*/ */
@Override @Override
public void executeClosingHandshake(ChannelHandlerContext ctx, CloseWebSocketFrame frame) { public void performClosingHandshake(ChannelHandlerContext ctx, CloseWebSocketFrame frame) {
ChannelFuture f = ctx.getChannel().write(frame); ChannelFuture f = ctx.getChannel().write(frame);
f.addListener(ChannelFutureListener.CLOSE); f.addListener(ChannelFutureListener.CLOSE);
} }