/** * Returns the reason text as per <a href="http://tools.ietf.org/html/rfc6455#section-7.4">RFC 6455</a> If a reason * text is not supplied, an empty string is returned. */ public String reasonText() { ByteBuf binaryData = content(); if (binaryData == null || binaryData.capacity() <= 2) { return ""; } binaryData.readerIndex(2); String reasonText = binaryData.toString(CharsetUtil.UTF_8); binaryData.readerIndex(0); return reasonText; }
/** * Returns the closing status code as per <a href="http://tools.ietf.org/html/rfc6455#section-7.4">RFC 6455</a>. If * a getStatus code is set, -1 is returned. */ public int statusCode() { ByteBuf binaryData = content(); if (binaryData == null || binaryData.capacity() == 0) { return -1; } binaryData.readerIndex(0); int statusCode = binaryData.readShort(); binaryData.readerIndex(0); return statusCode; }
@Override protected void decode(final ChannelHandlerContext channelHandlerContext, final CloseWebSocketFrame frame, final List<Object> objects) throws Exception { final ByteBuf messageBytes = frame.content(); final byte len = messageBytes.readByte(); if (len <= 0) { objects.add(RequestMessage.INVALID); return; } final ByteBuf contentTypeBytes = channelHandlerContext.alloc().buffer(len); try { messageBytes.readBytes(contentTypeBytes); final String contentType = contentTypeBytes.toString(UTF8); final MessageSerializer serializer = select(contentType, ServerSerializers.DEFAULT_SERIALIZER); // it's important to re-initialize these channel attributes as they apply globally to the channel. in // other words, the next request to this channel might not come with the same configuration and mixed // state can carry through from one request to the next channelHandlerContext.channel().attr(StateKey.SESSION).set(null); channelHandlerContext.channel().attr(StateKey.SERIALIZER).set(serializer); channelHandlerContext.channel().attr(StateKey.USE_BINARY).set(true); try { objects.add(serializer.deserializeRequest(messageBytes.discardReadBytes())); } catch (SerializationException se) { objects.add(RequestMessage.INVALID); } } finally { contentTypeBytes.release(); } }
/** * Returns the reason text as per <a href="http://tools.ietf.org/html/rfc6455#section-7.4">RFC 6455</a> If a reason * text is not supplied, an empty string is returned. */ public String reasonText() { ByteBuf binaryData = content(); if (binaryData == null || binaryData.capacity() <= 2) { return ""; } binaryData.readerIndex(2); String reasonText = binaryData.toString(CharsetUtil.UTF_8); binaryData.readerIndex(0); return reasonText; }
/** * Returns the reason text as per <a href="http://tools.ietf.org/html/rfc6455#section-7.4">RFC 6455</a> If a reason * text is not supplied, an empty string is returned. */ public String reasonText() { ByteBuf binaryData = content(); if (binaryData == null || binaryData.capacity() <= 2) { return ""; } binaryData.readerIndex(2); String reasonText = binaryData.toString(CharsetUtil.UTF_8); binaryData.readerIndex(0); return reasonText; }
/** * Returns the reason text as per <a href="http://tools.ietf.org/html/rfc6455#section-7.4">RFC 6455</a> If a reason * text is not supplied, an empty string is returned. */ public String reasonText() { ByteBuf binaryData = content(); if (binaryData == null || binaryData.capacity() <= 2) { return ""; } binaryData.readerIndex(2); String reasonText = binaryData.toString(CharsetUtil.UTF_8); binaryData.readerIndex(0); return reasonText; }
/** * Returns the reason text as per <a href="http://tools.ietf.org/html/rfc6455#section-7.4">RFC 6455</a> If a reason * text is not supplied, an empty string is returned. */ public String reasonText() { ByteBuf binaryData = content(); if (binaryData == null || binaryData.capacity() <= 2) { return ""; } binaryData.readerIndex(2); String reasonText = binaryData.toString(CharsetUtil.UTF_8); binaryData.readerIndex(0); return reasonText; }
/** * Returns the closing status code as per <a href="http://tools.ietf.org/html/rfc6455#section-7.4">RFC 6455</a>. If * a getStatus code is set, -1 is returned. */ public int statusCode() { ByteBuf binaryData = content(); if (binaryData == null || binaryData.capacity() == 0) { return -1; } binaryData.readerIndex(0); int statusCode = binaryData.readShort(); binaryData.readerIndex(0); return statusCode; }
/** * Returns the closing status code as per <a href="http://tools.ietf.org/html/rfc6455#section-7.4">RFC 6455</a>. If * a getStatus code is set, -1 is returned. */ public int statusCode() { ByteBuf binaryData = content(); if (binaryData == null || binaryData.capacity() == 0) { return -1; } binaryData.readerIndex(0); int statusCode = binaryData.readShort(); binaryData.readerIndex(0); return statusCode; }
/** * Returns the closing status code as per <a href="http://tools.ietf.org/html/rfc6455#section-7.4">RFC 6455</a>. If * a getStatus code is set, -1 is returned. */ public int statusCode() { ByteBuf binaryData = content(); if (binaryData == null || binaryData.capacity() == 0) { return -1; } binaryData.readerIndex(0); int statusCode = binaryData.readShort(); binaryData.readerIndex(0); return statusCode; }
/** * Returns the closing status code as per <a href="http://tools.ietf.org/html/rfc6455#section-7.4">RFC 6455</a>. If * a getStatus code is set, -1 is returned. */ public int statusCode() { ByteBuf binaryData = content(); if (binaryData == null || binaryData.capacity() == 0) { return -1; } binaryData.readerIndex(0); int statusCode = binaryData.readShort(); binaryData.readerIndex(0); return statusCode; }
@Override protected void decode(final ChannelHandlerContext channelHandlerContext, final CloseWebSocketFrame frame, final List<Object> objects) throws Exception { final ByteBuf messageBytes = frame.content(); final byte len = messageBytes.readByte(); if (len <= 0) { objects.add(RequestMessage.INVALID); return; } final ByteBuf contentTypeBytes = channelHandlerContext.alloc().buffer(len); try { messageBytes.readBytes(contentTypeBytes); final String contentType = contentTypeBytes.toString(UTF8); final MessageSerializer serializer = select(contentType, ServerSerializers.DEFAULT_SERIALIZER); // it's important to re-initialize these channel attributes as they apply globally to the channel. in // other words, the next request to this channel might not come with the same configuration and mixed // state can carry through from one request to the next channelHandlerContext.channel().attr(StateKey.SESSION).set(null); channelHandlerContext.channel().attr(StateKey.SERIALIZER).set(serializer); channelHandlerContext.channel().attr(StateKey.USE_BINARY).set(true); try { objects.add(serializer.deserializeRequest(messageBytes.discardReadBytes())); } catch (SerializationException se) { objects.add(RequestMessage.INVALID); } } finally { contentTypeBytes.release(); } }
sendCloseNow(new CloseWebSocketFrame(true, close.rsv(), close.content()));
@Override public void onInboundNext(ChannelHandlerContext ctx, Object frame) { if (frame instanceof CloseWebSocketFrame && ((CloseWebSocketFrame) frame).isFinalFragment()) { if (log.isDebugEnabled()) { log.debug(format(channel(), "CloseWebSocketFrame detected. Closing Websocket")); } onInboundComplete(); CloseWebSocketFrame close = (CloseWebSocketFrame) frame; sendCloseNow(new CloseWebSocketFrame(true, close.rsv(), close.content()), f -> terminate()); return; } if (frame instanceof PingWebSocketFrame) { ctx.writeAndFlush(new PongWebSocketFrame(((PingWebSocketFrame) frame).content())); ctx.read(); return; } if (frame != LastHttpContent.EMPTY_LAST_CONTENT) { super.onInboundNext(ctx, frame); } }
sendCloseNow(new CloseWebSocketFrame(true, close.rsv(), close.content()));
@Override public void onInboundNext(ChannelHandlerContext ctx, Object frame) { if (frame instanceof CloseWebSocketFrame && ((CloseWebSocketFrame) frame).isFinalFragment()) { if (log.isDebugEnabled()) { log.debug(format(channel(), "CloseWebSocketFrame detected. Closing Websocket")); } onInboundComplete(); CloseWebSocketFrame close = (CloseWebSocketFrame) frame; sendCloseNow(new CloseWebSocketFrame(true, close.rsv(), close.content()), f -> onHandlerTerminate()); return; } if (frame instanceof PingWebSocketFrame) { ctx.writeAndFlush(new PongWebSocketFrame(((PingWebSocketFrame) frame).content())); ctx.read(); return; } super.onInboundNext(ctx, frame); }
@Override public void onInboundNext(ChannelHandlerContext ctx, Object frame) { if (frame instanceof CloseWebSocketFrame && ((CloseWebSocketFrame) frame).isFinalFragment()) { if (log.isDebugEnabled()) { log.debug(format(channel(), "CloseWebSocketFrame detected. Closing Websocket")); } onInboundComplete(); CloseWebSocketFrame close = (CloseWebSocketFrame) frame; sendCloseNow(new CloseWebSocketFrame(true, close.rsv(), close.content()), f -> terminate()); return; } if (frame instanceof PingWebSocketFrame) { ctx.writeAndFlush(new PongWebSocketFrame(((PingWebSocketFrame) frame).content())); ctx.read(); return; } if (frame != LastHttpContent.EMPTY_LAST_CONTENT) { super.onInboundNext(ctx, frame); } }
sendCloseNow(new CloseWebSocketFrame(true, close.rsv(), close.content()));