diff --git a/src/main/java/com/loafle/commons/server/socket/netty/handler/codec/BinaryWebSocketFrame.java b/src/main/java/com/loafle/commons/server/socket/netty/handler/codec/BinarySocketFrame.java similarity index 55% rename from src/main/java/com/loafle/commons/server/socket/netty/handler/codec/BinaryWebSocketFrame.java rename to src/main/java/com/loafle/commons/server/socket/netty/handler/codec/BinarySocketFrame.java index 140046c..e451e32 100644 --- a/src/main/java/com/loafle/commons/server/socket/netty/handler/codec/BinaryWebSocketFrame.java +++ b/src/main/java/com/loafle/commons/server/socket/netty/handler/codec/BinarySocketFrame.java @@ -4,14 +4,14 @@ import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; /** - * Web Socket frame containing binary data + * Socket frame containing binary data */ -public class BinaryWebSocketFrame extends WebSocketFrame { +public class BinarySocketFrame extends SocketFrame { /** * Creates a new empty binary frame. */ - public BinaryWebSocketFrame() { + public BinarySocketFrame() { super(Unpooled.buffer(0)); } @@ -21,7 +21,7 @@ public class BinaryWebSocketFrame extends WebSocketFrame { * @param binaryData * the content of the frame. */ - public BinaryWebSocketFrame(ByteBuf binaryData) { + public BinarySocketFrame(ByteBuf binaryData) { super(binaryData); } @@ -35,50 +35,50 @@ public class BinaryWebSocketFrame extends WebSocketFrame { * @param binaryData * the content of the frame. */ - public BinaryWebSocketFrame(boolean finalFragment, int rsv, ByteBuf binaryData) { + public BinarySocketFrame(boolean finalFragment, int rsv, ByteBuf binaryData) { super(finalFragment, rsv, binaryData); } @Override - public BinaryWebSocketFrame copy() { - return (BinaryWebSocketFrame) super.copy(); + public BinarySocketFrame copy() { + return (BinarySocketFrame) super.copy(); } @Override - public BinaryWebSocketFrame duplicate() { - return (BinaryWebSocketFrame) super.duplicate(); + public BinarySocketFrame duplicate() { + return (BinarySocketFrame) super.duplicate(); } @Override - public BinaryWebSocketFrame retainedDuplicate() { - return (BinaryWebSocketFrame) super.retainedDuplicate(); + public BinarySocketFrame retainedDuplicate() { + return (BinarySocketFrame) super.retainedDuplicate(); } @Override - public BinaryWebSocketFrame replace(ByteBuf content) { - return new BinaryWebSocketFrame(isFinalFragment(), rsv(), content); + public BinarySocketFrame replace(ByteBuf content) { + return new BinarySocketFrame(isFinalFragment(), rsv(), content); } @Override - public BinaryWebSocketFrame retain() { + public BinarySocketFrame retain() { super.retain(); return this; } @Override - public BinaryWebSocketFrame retain(int increment) { + public BinarySocketFrame retain(int increment) { super.retain(increment); return this; } @Override - public BinaryWebSocketFrame touch() { + public BinarySocketFrame touch() { super.touch(); return this; } @Override - public BinaryWebSocketFrame touch(Object hint) { + public BinarySocketFrame touch(Object hint) { super.touch(hint); return this; } diff --git a/src/main/java/com/loafle/commons/server/socket/netty/handler/codec/CloseWebSocketFrame.java b/src/main/java/com/loafle/commons/server/socket/netty/handler/codec/CloseSocketFrame.java similarity index 78% rename from src/main/java/com/loafle/commons/server/socket/netty/handler/codec/CloseWebSocketFrame.java rename to src/main/java/com/loafle/commons/server/socket/netty/handler/codec/CloseSocketFrame.java index c1d8612..b9af840 100644 --- a/src/main/java/com/loafle/commons/server/socket/netty/handler/codec/CloseWebSocketFrame.java +++ b/src/main/java/com/loafle/commons/server/socket/netty/handler/codec/CloseSocketFrame.java @@ -6,14 +6,14 @@ import io.netty.util.CharsetUtil; import io.netty.util.internal.StringUtil; /** - * Web Socket Frame for closing the connection + * Socket Frame for closing the connection */ -public class CloseWebSocketFrame extends WebSocketFrame { +public class CloseSocketFrame extends SocketFrame { /** * Creates a new empty close frame. */ - public CloseWebSocketFrame() { + public CloseSocketFrame() { super(Unpooled.buffer(0)); } @@ -26,7 +26,7 @@ public class CloseWebSocketFrame extends WebSocketFrame { * @param reasonText * Reason text. Set to null if no text. */ - public CloseWebSocketFrame(int statusCode, String reasonText) { + public CloseSocketFrame(int statusCode, String reasonText) { this(true, 0, statusCode, reasonText); } @@ -38,7 +38,7 @@ public class CloseWebSocketFrame extends WebSocketFrame { * @param rsv * reserved bits used for protocol extensions */ - public CloseWebSocketFrame(boolean finalFragment, int rsv) { + public CloseSocketFrame(boolean finalFragment, int rsv) { this(finalFragment, rsv, Unpooled.buffer(0)); } @@ -55,7 +55,7 @@ public class CloseWebSocketFrame extends WebSocketFrame { * @param reasonText * Reason text. Set to null if no text. */ - public CloseWebSocketFrame(boolean finalFragment, int rsv, int statusCode, String reasonText) { + public CloseSocketFrame(boolean finalFragment, int rsv, int statusCode, String reasonText) { super(finalFragment, rsv, newBinaryData(statusCode, reasonText)); } @@ -84,7 +84,7 @@ public class CloseWebSocketFrame extends WebSocketFrame { * @param binaryData * the content of the frame. Must be 2 byte integer followed by optional UTF-8 encoded string. */ - public CloseWebSocketFrame(boolean finalFragment, int rsv, ByteBuf binaryData) { + public CloseSocketFrame(boolean finalFragment, int rsv, ByteBuf binaryData) { super(finalFragment, rsv, binaryData); } @@ -123,45 +123,45 @@ public class CloseWebSocketFrame extends WebSocketFrame { } @Override - public CloseWebSocketFrame copy() { - return (CloseWebSocketFrame) super.copy(); + public CloseSocketFrame copy() { + return (CloseSocketFrame) super.copy(); } @Override - public CloseWebSocketFrame duplicate() { - return (CloseWebSocketFrame) super.duplicate(); + public CloseSocketFrame duplicate() { + return (CloseSocketFrame) super.duplicate(); } @Override - public CloseWebSocketFrame retainedDuplicate() { - return (CloseWebSocketFrame) super.retainedDuplicate(); + public CloseSocketFrame retainedDuplicate() { + return (CloseSocketFrame) super.retainedDuplicate(); } @Override - public CloseWebSocketFrame replace(ByteBuf content) { - return new CloseWebSocketFrame(isFinalFragment(), rsv(), content); + public CloseSocketFrame replace(ByteBuf content) { + return new CloseSocketFrame(isFinalFragment(), rsv(), content); } @Override - public CloseWebSocketFrame retain() { + public CloseSocketFrame retain() { super.retain(); return this; } @Override - public CloseWebSocketFrame retain(int increment) { + public CloseSocketFrame retain(int increment) { super.retain(increment); return this; } @Override - public CloseWebSocketFrame touch() { + public CloseSocketFrame touch() { super.touch(); return this; } @Override - public CloseWebSocketFrame touch(Object hint) { + public CloseSocketFrame touch(Object hint) { super.touch(hint); return this; } diff --git a/src/main/java/com/loafle/commons/server/socket/netty/handler/codec/ContinuationWebSocketFrame.java b/src/main/java/com/loafle/commons/server/socket/netty/handler/codec/ContinuationSocketFrame.java similarity index 64% rename from src/main/java/com/loafle/commons/server/socket/netty/handler/codec/ContinuationWebSocketFrame.java rename to src/main/java/com/loafle/commons/server/socket/netty/handler/codec/ContinuationSocketFrame.java index 4490dc1..9fabde8 100644 --- a/src/main/java/com/loafle/commons/server/socket/netty/handler/codec/ContinuationWebSocketFrame.java +++ b/src/main/java/com/loafle/commons/server/socket/netty/handler/codec/ContinuationSocketFrame.java @@ -5,15 +5,15 @@ import io.netty.buffer.Unpooled; import io.netty.util.CharsetUtil; /** - * Web Socket continuation frame containing continuation text or binary data. This is used for + * Socket continuation frame containing continuation text or binary data. This is used for * fragmented messages where the contents of a messages is contained more than 1 frame. */ -public class ContinuationWebSocketFrame extends WebSocketFrame { +public class ContinuationSocketFrame extends SocketFrame { /** * Creates a new empty continuation frame. */ - public ContinuationWebSocketFrame() { + public ContinuationSocketFrame() { this(Unpooled.buffer(0)); } @@ -23,7 +23,7 @@ public class ContinuationWebSocketFrame extends WebSocketFrame { * * @param binaryData the content of the frame. */ - public ContinuationWebSocketFrame(ByteBuf binaryData) { + public ContinuationSocketFrame(ByteBuf binaryData) { super(binaryData); } @@ -37,7 +37,7 @@ public class ContinuationWebSocketFrame extends WebSocketFrame { * @param binaryData * the content of the frame. */ - public ContinuationWebSocketFrame(boolean finalFragment, int rsv, ByteBuf binaryData) { + public ContinuationSocketFrame(boolean finalFragment, int rsv, ByteBuf binaryData) { super(finalFragment, rsv, binaryData); } @@ -51,7 +51,7 @@ public class ContinuationWebSocketFrame extends WebSocketFrame { * @param text * text content of the frame. */ - public ContinuationWebSocketFrame(boolean finalFragment, int rsv, String text) { + public ContinuationSocketFrame(boolean finalFragment, int rsv, String text) { this(finalFragment, rsv, fromText(text)); } @@ -77,45 +77,45 @@ public class ContinuationWebSocketFrame extends WebSocketFrame { } @Override - public ContinuationWebSocketFrame copy() { - return (ContinuationWebSocketFrame) super.copy(); + public ContinuationSocketFrame copy() { + return (ContinuationSocketFrame) super.copy(); } @Override - public ContinuationWebSocketFrame duplicate() { - return (ContinuationWebSocketFrame) super.duplicate(); + public ContinuationSocketFrame duplicate() { + return (ContinuationSocketFrame) super.duplicate(); } @Override - public ContinuationWebSocketFrame retainedDuplicate() { - return (ContinuationWebSocketFrame) super.retainedDuplicate(); + public ContinuationSocketFrame retainedDuplicate() { + return (ContinuationSocketFrame) super.retainedDuplicate(); } @Override - public ContinuationWebSocketFrame replace(ByteBuf content) { - return new ContinuationWebSocketFrame(isFinalFragment(), rsv(), content); + public ContinuationSocketFrame replace(ByteBuf content) { + return new ContinuationSocketFrame(isFinalFragment(), rsv(), content); } @Override - public ContinuationWebSocketFrame retain() { + public ContinuationSocketFrame retain() { super.retain(); return this; } @Override - public ContinuationWebSocketFrame retain(int increment) { + public ContinuationSocketFrame retain(int increment) { super.retain(increment); return this; } @Override - public ContinuationWebSocketFrame touch() { + public ContinuationSocketFrame touch() { super.touch(); return this; } @Override - public ContinuationWebSocketFrame touch(Object hint) { + public ContinuationSocketFrame touch(Object hint) { super.touch(hint); return this; } diff --git a/src/main/java/com/loafle/commons/server/socket/netty/handler/codec/PingWebSocketFrame.java b/src/main/java/com/loafle/commons/server/socket/netty/handler/codec/PingSocketFrame.java similarity index 55% rename from src/main/java/com/loafle/commons/server/socket/netty/handler/codec/PingWebSocketFrame.java rename to src/main/java/com/loafle/commons/server/socket/netty/handler/codec/PingSocketFrame.java index 78eb109..7cfe33e 100644 --- a/src/main/java/com/loafle/commons/server/socket/netty/handler/codec/PingWebSocketFrame.java +++ b/src/main/java/com/loafle/commons/server/socket/netty/handler/codec/PingSocketFrame.java @@ -4,14 +4,14 @@ import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; /** - * Web Socket frame containing binary data + * Socket frame containing binary data */ -public class PingWebSocketFrame extends WebSocketFrame { +public class PingSocketFrame extends SocketFrame { /** * Creates a new empty ping frame. */ - public PingWebSocketFrame() { + public PingSocketFrame() { super(true, 0, Unpooled.buffer(0)); } @@ -21,7 +21,7 @@ public class PingWebSocketFrame extends WebSocketFrame { * @param binaryData * the content of the frame. */ - public PingWebSocketFrame(ByteBuf binaryData) { + public PingSocketFrame(ByteBuf binaryData) { super(binaryData); } @@ -35,50 +35,50 @@ public class PingWebSocketFrame extends WebSocketFrame { * @param binaryData * the content of the frame. */ - public PingWebSocketFrame(boolean finalFragment, int rsv, ByteBuf binaryData) { + public PingSocketFrame(boolean finalFragment, int rsv, ByteBuf binaryData) { super(finalFragment, rsv, binaryData); } @Override - public PingWebSocketFrame copy() { - return (PingWebSocketFrame) super.copy(); + public PingSocketFrame copy() { + return (PingSocketFrame) super.copy(); } @Override - public PingWebSocketFrame duplicate() { - return (PingWebSocketFrame) super.duplicate(); + public PingSocketFrame duplicate() { + return (PingSocketFrame) super.duplicate(); } @Override - public PingWebSocketFrame retainedDuplicate() { - return (PingWebSocketFrame) super.retainedDuplicate(); + public PingSocketFrame retainedDuplicate() { + return (PingSocketFrame) super.retainedDuplicate(); } @Override - public PingWebSocketFrame replace(ByteBuf content) { - return new PingWebSocketFrame(isFinalFragment(), rsv(), content); + public PingSocketFrame replace(ByteBuf content) { + return new PingSocketFrame(isFinalFragment(), rsv(), content); } @Override - public PingWebSocketFrame retain() { + public PingSocketFrame retain() { super.retain(); return this; } @Override - public PingWebSocketFrame retain(int increment) { + public PingSocketFrame retain(int increment) { super.retain(increment); return this; } @Override - public PingWebSocketFrame touch() { + public PingSocketFrame touch() { super.touch(); return this; } @Override - public PingWebSocketFrame touch(Object hint) { + public PingSocketFrame touch(Object hint) { super.touch(hint); return this; } diff --git a/src/main/java/com/loafle/commons/server/socket/netty/handler/codec/PongWebSocketFrame.java b/src/main/java/com/loafle/commons/server/socket/netty/handler/codec/PongSocketFrame.java similarity index 55% rename from src/main/java/com/loafle/commons/server/socket/netty/handler/codec/PongWebSocketFrame.java rename to src/main/java/com/loafle/commons/server/socket/netty/handler/codec/PongSocketFrame.java index 72e2fb7..39d5871 100644 --- a/src/main/java/com/loafle/commons/server/socket/netty/handler/codec/PongWebSocketFrame.java +++ b/src/main/java/com/loafle/commons/server/socket/netty/handler/codec/PongSocketFrame.java @@ -4,14 +4,14 @@ import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; /** - * Web Socket frame containing binary data + * Socket frame containing binary data */ -public class PongWebSocketFrame extends WebSocketFrame { +public class PongSocketFrame extends SocketFrame { /** * Creates a new empty pong frame. */ - public PongWebSocketFrame() { + public PongSocketFrame() { super(Unpooled.buffer(0)); } @@ -21,7 +21,7 @@ public class PongWebSocketFrame extends WebSocketFrame { * @param binaryData * the content of the frame. */ - public PongWebSocketFrame(ByteBuf binaryData) { + public PongSocketFrame(ByteBuf binaryData) { super(binaryData); } @@ -35,50 +35,50 @@ public class PongWebSocketFrame extends WebSocketFrame { * @param binaryData * the content of the frame. */ - public PongWebSocketFrame(boolean finalFragment, int rsv, ByteBuf binaryData) { + public PongSocketFrame(boolean finalFragment, int rsv, ByteBuf binaryData) { super(finalFragment, rsv, binaryData); } @Override - public PongWebSocketFrame copy() { - return (PongWebSocketFrame) super.copy(); + public PongSocketFrame copy() { + return (PongSocketFrame) super.copy(); } @Override - public PongWebSocketFrame duplicate() { - return (PongWebSocketFrame) super.duplicate(); + public PongSocketFrame duplicate() { + return (PongSocketFrame) super.duplicate(); } @Override - public PongWebSocketFrame retainedDuplicate() { - return (PongWebSocketFrame) super.retainedDuplicate(); + public PongSocketFrame retainedDuplicate() { + return (PongSocketFrame) super.retainedDuplicate(); } @Override - public PongWebSocketFrame replace(ByteBuf content) { - return new PongWebSocketFrame(isFinalFragment(), rsv(), content); + public PongSocketFrame replace(ByteBuf content) { + return new PongSocketFrame(isFinalFragment(), rsv(), content); } @Override - public PongWebSocketFrame retain() { + public PongSocketFrame retain() { super.retain(); return this; } @Override - public PongWebSocketFrame retain(int increment) { + public PongSocketFrame retain(int increment) { super.retain(increment); return this; } @Override - public PongWebSocketFrame touch() { + public PongSocketFrame touch() { super.touch(); return this; } @Override - public PongWebSocketFrame touch(Object hint) { + public PongSocketFrame touch(Object hint) { super.touch(hint); return this; } diff --git a/src/main/java/com/loafle/commons/server/socket/netty/handler/codec/WebSocket13FrameDecoder.java b/src/main/java/com/loafle/commons/server/socket/netty/handler/codec/Socket13FrameDecoder.java similarity index 88% rename from src/main/java/com/loafle/commons/server/socket/netty/handler/codec/WebSocket13FrameDecoder.java rename to src/main/java/com/loafle/commons/server/socket/netty/handler/codec/Socket13FrameDecoder.java index 9dab43f..ad8f5e6 100644 --- a/src/main/java/com/loafle/commons/server/socket/netty/handler/codec/WebSocket13FrameDecoder.java +++ b/src/main/java/com/loafle/commons/server/socket/netty/handler/codec/Socket13FrameDecoder.java @@ -15,16 +15,16 @@ import io.netty.util.internal.logging.InternalLogger; import io.netty.util.internal.logging.InternalLoggerFactory; /** - * Decodes a web socket frame from wire protocol version 8 format. This code was forked from webbit and modified. */ -public class WebSocket13FrameDecoder extends ByteToMessageDecoder implements WebSocketFrameDecoder { +public class Socket13FrameDecoder extends ByteToMessageDecoder implements SocketFrameDecoder { enum State { READING_FIRST, READING_SECOND, READING_SIZE, MASKING_KEY, PAYLOAD, CORRUPT } - private static final InternalLogger logger = InternalLoggerFactory.getInstance(WebSocket13FrameDecoder.class); + private static final InternalLogger logger = InternalLoggerFactory.getInstance(Socket13FrameDecoder.class); private static final byte OPCODE_CONT = 0x0; private static final byte OPCODE_TEXT = 0x1; @@ -52,7 +52,7 @@ public class WebSocket13FrameDecoder extends ByteToMessageDecoder implements Web * Constructor * * @param expectMaskedFrames - * Web socket servers must set this to true processed incoming masked payload. Client implementations + * Socket servers must set this to true processed incoming masked payload. Client implementations * must set this to false. * @param allowExtensions * Flag to allow reserved extension bits to be used or not @@ -60,7 +60,7 @@ public class WebSocket13FrameDecoder extends ByteToMessageDecoder implements Web * Maximum length of a frame's payload. Setting this to an appropriate value for you application * helps check for denial of services attacks. */ - public WebSocket13FrameDecoder(boolean expectMaskedFrames, boolean allowExtensions, int maxFramePayloadLength) { + public Socket13FrameDecoder(boolean expectMaskedFrames, boolean allowExtensions, int maxFramePayloadLength) { this(expectMaskedFrames, allowExtensions, maxFramePayloadLength, false); } @@ -68,7 +68,7 @@ public class WebSocket13FrameDecoder extends ByteToMessageDecoder implements Web * Constructor * * @param expectMaskedFrames - * Web socket servers must set this to true processed incoming masked payload. Client implementations + * Socket servers must set this to true processed incoming masked payload. Client implementations * must set this to false. * @param allowExtensions * Flag to allow reserved extension bits to be used or not @@ -79,7 +79,7 @@ public class WebSocket13FrameDecoder extends ByteToMessageDecoder implements Web * When set to true, frames which are not masked properly according to the standard will still be * accepted. */ - public WebSocket13FrameDecoder(boolean expectMaskedFrames, boolean allowExtensions, int maxFramePayloadLength, + public Socket13FrameDecoder(boolean expectMaskedFrames, boolean allowExtensions, int maxFramePayloadLength, boolean allowMaskMismatch) { this.expectMaskedFrames = expectMaskedFrames; this.allowMaskMismatch = allowMaskMismatch; @@ -104,7 +104,7 @@ public class WebSocket13FrameDecoder extends ByteToMessageDecoder implements Web frameOpcode = b & 0x0F; if (logger.isDebugEnabled()) { - logger.debug("Decoding WebSocket Frame opCode={}", frameOpcode); + logger.debug("Decoding Socket Frame opCode={}", frameOpcode); } state = State.READING_SECOND; @@ -209,7 +209,7 @@ public class WebSocket13FrameDecoder extends ByteToMessageDecoder implements Web } if (logger.isDebugEnabled()) { - logger.debug("Decoding WebSocket Frame length={}", framePayloadLength); + logger.debug("Decoding Socket Frame length={}", framePayloadLength); } state = State.MASKING_KEY; @@ -245,18 +245,18 @@ public class WebSocket13FrameDecoder extends ByteToMessageDecoder implements Web // Processing ping/pong/close frames because they cannot be // fragmented if (frameOpcode == OPCODE_PING) { - out.add(new PingWebSocketFrame(frameFinalFlag, frameRsv, payloadBuffer)); + out.add(new PingSocketFrame(frameFinalFlag, frameRsv, payloadBuffer)); payloadBuffer = null; return; } if (frameOpcode == OPCODE_PONG) { - out.add(new PongWebSocketFrame(frameFinalFlag, frameRsv, payloadBuffer)); + out.add(new PongSocketFrame(frameFinalFlag, frameRsv, payloadBuffer)); payloadBuffer = null; return; } if (frameOpcode == OPCODE_CLOSE) { checkCloseFrameBody(ctx, payloadBuffer); - out.add(new CloseWebSocketFrame(frameFinalFlag, frameRsv, payloadBuffer)); + out.add(new CloseSocketFrame(frameFinalFlag, frameRsv, payloadBuffer)); payloadBuffer = null; return; } @@ -276,19 +276,19 @@ public class WebSocket13FrameDecoder extends ByteToMessageDecoder implements Web // Return the frame if (frameOpcode == OPCODE_TEXT) { - out.add(new TextWebSocketFrame(frameFinalFlag, frameRsv, payloadBuffer)); + out.add(new TextSocketFrame(frameFinalFlag, frameRsv, payloadBuffer)); payloadBuffer = null; return; } else if (frameOpcode == OPCODE_BINARY) { - out.add(new BinaryWebSocketFrame(frameFinalFlag, frameRsv, payloadBuffer)); + out.add(new BinarySocketFrame(frameFinalFlag, frameRsv, payloadBuffer)); payloadBuffer = null; return; } else if (frameOpcode == OPCODE_CONT) { - out.add(new ContinuationWebSocketFrame(frameFinalFlag, frameRsv, payloadBuffer)); + out.add(new ContinuationSocketFrame(frameFinalFlag, frameRsv, payloadBuffer)); payloadBuffer = null; return; } else { - throw new UnsupportedOperationException("Cannot decode web socket frame with opcode: " + frameOpcode); + throw new UnsupportedOperationException("Cannot decode socket frame with opcode: " + frameOpcode); } } finally { if (payloadBuffer != null) { @@ -340,7 +340,7 @@ public class WebSocket13FrameDecoder extends ByteToMessageDecoder implements Web private void protocolViolation(ChannelHandlerContext ctx, CorruptedFrameException ex) { state = State.CORRUPT; if (ctx.channel().isActive()) { - Object closeMessage = new CloseWebSocketFrame(1002, null); + Object closeMessage = new CloseSocketFrame(1002, null); ctx.writeAndFlush(closeMessage).addListener(ChannelFutureListener.CLOSE); } throw ex; diff --git a/src/main/java/com/loafle/commons/server/socket/netty/handler/codec/WebSocket13FrameEncoder.java b/src/main/java/com/loafle/commons/server/socket/netty/handler/codec/Socket13FrameEncoder.java similarity index 84% rename from src/main/java/com/loafle/commons/server/socket/netty/handler/codec/WebSocket13FrameEncoder.java rename to src/main/java/com/loafle/commons/server/socket/netty/handler/codec/Socket13FrameEncoder.java index 8c7b50a..7f00f23 100644 --- a/src/main/java/com/loafle/commons/server/socket/netty/handler/codec/WebSocket13FrameEncoder.java +++ b/src/main/java/com/loafle/commons/server/socket/netty/handler/codec/Socket13FrameEncoder.java @@ -13,13 +13,13 @@ import java.util.List; /** *

- * Encodes a web socket frame into wire protocol version 8 format. This code was forked from webbit and modified. *

*/ -public class WebSocket13FrameEncoder extends MessageToMessageEncoder implements WebSocketFrameEncoder { +public class Socket13FrameEncoder extends MessageToMessageEncoder implements SocketFrameEncoder { - private static final InternalLogger logger = InternalLoggerFactory.getInstance(WebSocket13FrameEncoder.class); + private static final InternalLogger logger = InternalLoggerFactory.getInstance(Socket13FrameEncoder.class); private static final byte OPCODE_CONT = 0x0; private static final byte OPCODE_TEXT = 0x1; @@ -42,30 +42,30 @@ public class WebSocket13FrameEncoder extends MessageToMessageEncoder out) throws Exception { + protected void encode(ChannelHandlerContext ctx, SocketFrame msg, List out) throws Exception { final ByteBuf data = msg.content(); byte[] mask; byte opcode; - if (msg instanceof TextWebSocketFrame) { + if (msg instanceof TextSocketFrame) { opcode = OPCODE_TEXT; - } else if (msg instanceof PingWebSocketFrame) { + } else if (msg instanceof PingSocketFrame) { opcode = OPCODE_PING; - } else if (msg instanceof PongWebSocketFrame) { + } else if (msg instanceof PongSocketFrame) { opcode = OPCODE_PONG; - } else if (msg instanceof CloseWebSocketFrame) { + } else if (msg instanceof CloseSocketFrame) { opcode = OPCODE_CLOSE; - } else if (msg instanceof BinaryWebSocketFrame) { + } else if (msg instanceof BinarySocketFrame) { opcode = OPCODE_BINARY; - } else if (msg instanceof ContinuationWebSocketFrame) { + } else if (msg instanceof ContinuationSocketFrame) { opcode = OPCODE_CONT; } else { throw new UnsupportedOperationException("Cannot encode frame of type: " + msg.getClass().getName()); @@ -74,7 +74,7 @@ public class WebSocket13FrameEncoder extends MessageToMessageEncoder