[#1515] Add WebSocketFrameEncoder and WebSocketFrameDecoder interfaces and let our impls implement it

This commit is contained in:
Norman Maurer 2013-07-04 06:41:22 +02:00
parent 998b408db3
commit f64a121de7
16 changed files with 79 additions and 44 deletions

View File

@ -27,7 +27,7 @@ import io.netty.handler.codec.TooLongFrameException;
* For the detailed instruction on adding add Web Socket support to your HTTP server, take a look into the
* <tt>WebSocketServer</tt> example located in the {@code io.netty.example.http.websocket} package.
*/
public class WebSocket00FrameDecoder extends ReplayingDecoder<Void> {
public class WebSocket00FrameDecoder extends ReplayingDecoder<Void> implements WebSocketFrameDecoder {
static final int DEFAULT_MAX_FRAME_SIZE = 16384;

View File

@ -27,7 +27,7 @@ import io.netty.handler.codec.MessageToByteEncoder;
* <tt>WebSocketServer</tt> example located in the {@code io.netty.example.http.websocket} package.
*/
@Sharable
public class WebSocket00FrameEncoder extends MessageToByteEncoder<WebSocketFrame> {
public class WebSocket00FrameEncoder extends MessageToByteEncoder<WebSocketFrame> implements WebSocketFrameEncoder {
@Override
protected void encode(ChannelHandlerContext ctx, WebSocketFrame msg, ByteBuf out) throws Exception {

View File

@ -68,7 +68,8 @@ import io.netty.util.internal.logging.InternalLoggerFactory;
* Decodes a web socket frame from wire protocol version 8 format. This code was forked from <a
* href="https://github.com/joewalnes/webbit">webbit</a> and modified.
*/
public class WebSocket08FrameDecoder extends ReplayingDecoder<WebSocket08FrameDecoder.State> {
public class WebSocket08FrameDecoder extends ReplayingDecoder<WebSocket08FrameDecoder.State>
implements WebSocketFrameDecoder {
private static final InternalLogger logger = InternalLoggerFactory.getInstance(WebSocket08FrameDecoder.class);

View File

@ -69,7 +69,7 @@ import java.nio.ByteBuffer;
* href="https://github.com/joewalnes/webbit">webbit</a> and modified.
* </p>
*/
public class WebSocket08FrameEncoder extends MessageToByteEncoder<WebSocketFrame> {
public class WebSocket08FrameEncoder extends MessageToByteEncoder<WebSocketFrame> implements WebSocketFrameEncoder {
private static final InternalLogger logger = InternalLoggerFactory.getInstance(WebSocket08FrameEncoder.class);

View File

@ -19,8 +19,6 @@ import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandler;
import io.netty.channel.ChannelOutboundHandler;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.ChannelPromise;
import io.netty.handler.codec.http.FullHttpRequest;
@ -230,12 +228,12 @@ public abstract class WebSocketClientHandshaker {
/**
* Returns the decoder to use after handshake is complete.
*/
protected abstract ChannelInboundHandler newWebsocketDecoder();
protected abstract WebSocketFrameDecoder newWebsocketDecoder();
/**
* Returns the encoder to use after the handshake is complete.
*/
protected abstract ChannelOutboundHandler newWebSocketEncoder();
protected abstract WebSocketFrameEncoder newWebSocketEncoder();
/**
* Performs the closing handshake

View File

@ -17,8 +17,6 @@ package io.netty.handler.codec.http.websocketx;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelInboundHandler;
import io.netty.channel.ChannelOutboundHandler;
import io.netty.handler.codec.http.DefaultFullHttpRequest;
import io.netty.handler.codec.http.FullHttpRequest;
import io.netty.handler.codec.http.FullHttpResponse;
@ -252,12 +250,12 @@ public class WebSocketClientHandshaker00 extends WebSocketClientHandshaker {
}
@Override
protected ChannelInboundHandler newWebsocketDecoder() {
protected WebSocketFrameDecoder newWebsocketDecoder() {
return new WebSocket00FrameDecoder(maxFramePayloadLength());
}
@Override
protected ChannelOutboundHandler newWebSocketEncoder() {
protected WebSocketFrameEncoder newWebSocketEncoder() {
return new WebSocket00FrameEncoder();
}
}

View File

@ -15,8 +15,6 @@
*/
package io.netty.handler.codec.http.websocketx;
import io.netty.channel.ChannelInboundHandler;
import io.netty.channel.ChannelOutboundHandler;
import io.netty.handler.codec.http.DefaultFullHttpRequest;
import io.netty.handler.codec.http.FullHttpRequest;
import io.netty.handler.codec.http.FullHttpResponse;
@ -191,12 +189,12 @@ public class WebSocketClientHandshaker07 extends WebSocketClientHandshaker {
}
@Override
protected ChannelInboundHandler newWebsocketDecoder() {
protected WebSocketFrameDecoder newWebsocketDecoder() {
return new WebSocket07FrameDecoder(false, allowExtensions, maxFramePayloadLength());
}
@Override
protected ChannelOutboundHandler newWebSocketEncoder() {
protected WebSocketFrameEncoder newWebSocketEncoder() {
return new WebSocket07FrameEncoder(true);
}
}

View File

@ -15,8 +15,6 @@
*/
package io.netty.handler.codec.http.websocketx;
import io.netty.channel.ChannelInboundHandler;
import io.netty.channel.ChannelOutboundHandler;
import io.netty.handler.codec.http.DefaultFullHttpRequest;
import io.netty.handler.codec.http.FullHttpRequest;
import io.netty.handler.codec.http.FullHttpResponse;
@ -191,12 +189,12 @@ public class WebSocketClientHandshaker08 extends WebSocketClientHandshaker {
}
@Override
protected ChannelInboundHandler newWebsocketDecoder() {
protected WebSocketFrameDecoder newWebsocketDecoder() {
return new WebSocket08FrameDecoder(false, allowExtensions, maxFramePayloadLength());
}
@Override
protected ChannelOutboundHandler newWebSocketEncoder() {
protected WebSocketFrameEncoder newWebSocketEncoder() {
return new WebSocket08FrameEncoder(true);
}
}

View File

@ -15,8 +15,6 @@
*/
package io.netty.handler.codec.http.websocketx;
import io.netty.channel.ChannelInboundHandler;
import io.netty.channel.ChannelOutboundHandler;
import io.netty.handler.codec.http.DefaultFullHttpRequest;
import io.netty.handler.codec.http.FullHttpRequest;
import io.netty.handler.codec.http.FullHttpResponse;
@ -191,12 +189,12 @@ public class WebSocketClientHandshaker13 extends WebSocketClientHandshaker {
}
@Override
protected ChannelInboundHandler newWebsocketDecoder() {
protected WebSocketFrameDecoder newWebsocketDecoder() {
return new WebSocket13FrameDecoder(false, allowExtensions, maxFramePayloadLength());
}
@Override
protected ChannelOutboundHandler newWebSocketEncoder() {
protected WebSocketFrameEncoder newWebSocketEncoder() {
return new WebSocket13FrameEncoder(true);
}
}

View File

@ -0,0 +1,27 @@
/*
* Copyright 2013 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 io.netty.handler.codec.http.websocketx;
import io.netty.channel.ChannelInboundHandler;
import io.netty.channel.ChannelPipeline;
/**
* Marker interface which all WebSocketFrame decoders need to implement.
*
* This makes it easier to access the added encoder later in the {@link ChannelPipeline}.
*/
public interface WebSocketFrameDecoder extends ChannelInboundHandler {
}

View File

@ -0,0 +1,27 @@
/*
* Copyright 2013 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 io.netty.handler.codec.http.websocketx;
import io.netty.channel.ChannelOutboundHandler;
import io.netty.channel.ChannelPipeline;
/**
* Marker interface which all WebSocketFrame encoders need to implement.
*
* This makes it easier to access the added encoder later in the {@link ChannelPipeline}.
*/
public interface WebSocketFrameEncoder extends ChannelOutboundHandler {
}

View File

@ -19,8 +19,6 @@ import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandler;
import io.netty.channel.ChannelOutboundHandler;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.ChannelPromise;
import io.netty.handler.codec.http.FullHttpRequest;
@ -272,11 +270,11 @@ public abstract class WebSocketServerHandshaker {
/**
* Returns the decoder to use after handshake is complete.
*/
protected abstract ChannelInboundHandler newWebsocketDecoder();
protected abstract WebSocketFrameDecoder newWebsocketDecoder();
/**
* Returns the encoder to use after the handshake is complete.
*/
protected abstract ChannelOutboundHandler newWebSocketEncoder();
protected abstract WebSocketFrameEncoder newWebSocketEncoder();
}

View File

@ -19,8 +19,6 @@ import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelInboundHandler;
import io.netty.channel.ChannelOutboundHandler;
import io.netty.channel.ChannelPromise;
import io.netty.handler.codec.http.DefaultFullHttpResponse;
import io.netty.handler.codec.http.FullHttpRequest;
@ -183,12 +181,12 @@ public class WebSocketServerHandshaker00 extends WebSocketServerHandshaker {
}
@Override
protected ChannelInboundHandler newWebsocketDecoder() {
protected WebSocketFrameDecoder newWebsocketDecoder() {
return new WebSocket00FrameDecoder(maxFramePayloadLength());
}
@Override
protected ChannelOutboundHandler newWebSocketEncoder() {
protected WebSocketFrameEncoder newWebSocketEncoder() {
return new WebSocket00FrameEncoder();
}
}

View File

@ -15,8 +15,6 @@
*/
package io.netty.handler.codec.http.websocketx;
import io.netty.channel.ChannelInboundHandler;
import io.netty.channel.ChannelOutboundHandler;
import io.netty.handler.codec.http.DefaultFullHttpResponse;
import io.netty.handler.codec.http.FullHttpRequest;
import io.netty.handler.codec.http.FullHttpResponse;
@ -132,12 +130,12 @@ public class WebSocketServerHandshaker07 extends WebSocketServerHandshaker {
}
@Override
protected ChannelInboundHandler newWebsocketDecoder() {
protected WebSocketFrameDecoder newWebsocketDecoder() {
return new WebSocket07FrameDecoder(true, allowExtensions, maxFramePayloadLength());
}
@Override
protected ChannelOutboundHandler newWebSocketEncoder() {
protected WebSocketFrameEncoder newWebSocketEncoder() {
return new WebSocket07FrameEncoder(false);
}
}

View File

@ -15,8 +15,6 @@
*/
package io.netty.handler.codec.http.websocketx;
import io.netty.channel.ChannelInboundHandler;
import io.netty.channel.ChannelOutboundHandler;
import io.netty.handler.codec.http.DefaultFullHttpResponse;
import io.netty.handler.codec.http.FullHttpRequest;
import io.netty.handler.codec.http.FullHttpResponse;
@ -131,12 +129,12 @@ public class WebSocketServerHandshaker08 extends WebSocketServerHandshaker {
}
@Override
protected ChannelInboundHandler newWebsocketDecoder() {
protected WebSocketFrameDecoder newWebsocketDecoder() {
return new WebSocket08FrameDecoder(true, allowExtensions, maxFramePayloadLength());
}
@Override
protected ChannelOutboundHandler newWebSocketEncoder() {
protected WebSocketFrameEncoder newWebSocketEncoder() {
return new WebSocket08FrameEncoder(false);
}
}

View File

@ -15,8 +15,6 @@
*/
package io.netty.handler.codec.http.websocketx;
import io.netty.channel.ChannelInboundHandler;
import io.netty.channel.ChannelOutboundHandler;
import io.netty.handler.codec.http.DefaultFullHttpResponse;
import io.netty.handler.codec.http.FullHttpRequest;
import io.netty.handler.codec.http.FullHttpResponse;
@ -130,12 +128,12 @@ public class WebSocketServerHandshaker13 extends WebSocketServerHandshaker {
}
@Override
protected ChannelInboundHandler newWebsocketDecoder() {
protected WebSocketFrameDecoder newWebsocketDecoder() {
return new WebSocket13FrameDecoder(true, allowExtensions, maxFramePayloadLength());
}
@Override
protected ChannelOutboundHandler newWebSocketEncoder() {
protected WebSocketFrameEncoder newWebSocketEncoder() {
return new WebSocket13FrameEncoder(false);
}
}