protected DecodingState finishDecode(final int frameSize, ProtocolDecoderOutput out) throws Exception { if (frameSize == 0) { out.write(new WsBinaryMessage(allocator.wrap(allocator.allocate(0)))); return READ_FRAME_TYPE; } else { checkSizeLimit(frameSize); return new FixedLengthDecodingState(allocator, frameSize) { @Override protected DecodingState finishDecode(IoBuffer product, ProtocolDecoderOutput out) throws Exception { // read the binary frame contents out.write(new WsBinaryMessage((IoBufferEx) product)); return READ_FRAME_TYPE; } }; } } };
@Override protected void wsTextReceived(NextFilter nextFilter, IoSession session, WsTextMessage wsText) throws Exception { IoBufferEx text = wsText.getBytes(); super.wsBinaryReceived(nextFilter, session, new WsBinaryMessage(text)); } }
protected DecodingState finishDecode(final int frameSize, ProtocolDecoderOutput out) throws Exception { if (frameSize == 0) { out.write(new WsBinaryMessage(allocator.wrap(allocator.allocate(0)))); return READ_FRAME_TYPE; } else { checkSizeLimit(frameSize); return new FixedLengthDecodingState(allocator, frameSize) { @Override protected DecodingState finishDecode(IoBuffer product, ProtocolDecoderOutput out) throws Exception { // read the binary frame contents out.write(new WsBinaryMessage((IoBufferEx) product)); return READ_FRAME_TYPE; } }; } } };
@Override public void decodeWsMessage(IoBufferEx payload, Kind messageKind, boolean fin, ProtocolDecoderOutput out) { switch(messageKind) { case CONTINUATION: out.write(new WsContinuationMessage(payload, fin)); break; case BINARY: out.write(new WsBinaryMessage(payload, fin)); break; case TEXT: out.write(new WsTextMessage(payload, fin)); break; default: assert false; } } };
@Override protected void wsTextReceived(NextFilter nextFilter, IoSession session, WsTextMessage wsText) throws Exception { IoBufferEx encodedEx = wsText.getBytes(); ByteBuffer encoded = encodedEx.buf(); ByteBuffer binary = utf8.decode(encoded); IoSessionEx sessionEx = (IoSessionEx) session; IoBufferAllocatorEx<?> allocator = sessionEx.getBufferAllocator(); IoBufferEx binaryEx = allocator.wrap(binary, encodedEx.flags()); super.wsBinaryReceived(nextFilter, session, new WsBinaryMessage(binaryEx)); }
@Override protected void wsTextReceived(NextFilter nextFilter, IoSession session, WsTextMessage wsText) throws Exception { IoBufferEx encodedEx = wsText.getBytes(); ByteBuffer encoded = encodedEx.buf(); ByteBuffer binary = base64.decode(encoded); IoSessionEx sessionEx = (IoSessionEx) session; IoBufferAllocatorEx<?> allocator = sessionEx.getBufferAllocator(); IoBufferEx binaryEx = allocator.wrap(binary, encodedEx.flags()); super.wsBinaryReceived(nextFilter, session, new WsBinaryMessage(binaryEx)); }
logger.error(e.toString()); WsBinaryMessage message = new WsBinaryMessage(messageBuf);
newWsebMessage = new WsBinaryMessage(buf); lastWrite = flushNowInternal(transport, new WsBinaryMessage(buf), buf, filterChain, request);
break; default: newWsMessage = new WsBinaryMessage(buf, wsBuffer.isFin()); break; return flushNowInternal(parent, new WsBinaryMessage(buf), buf, filterChain, request);
@Override protected void doFilterWrite(final NextFilter nextFilter, final WsnSession wsnSession, WriteRequest writeRequest) throws Exception { IoSession parent = wsnSession.getParent(); Encoding encoding = (Encoding) parent.getAttribute("encoding"); final WsMessage emptyWsMessage; final IoBufferAllocatorEx<?> allocator = wsnSession.getBufferAllocator(); switch(encoding) { case TEXT: emptyWsMessage = new WsTextMessage(allocator.wrap(allocator.allocate(0))); break; default: emptyWsMessage = new WsBinaryMessage(allocator.wrap(allocator.allocate(0))); } writeRequest.getFuture().addListener(new IoFutureListener<WriteFuture>() { @Override public void operationComplete(WriteFuture future) { if (logger.isDebugEnabled()) { logger.debug("HttpEmptyPacketWriterFilter writing empty packet."); } wsnSession.getParent().write(emptyWsMessage); } }); HttpResponseMessage message = (HttpResponseMessage) writeRequest.getMessage(); if ( message.getStatus() != HttpStatus.CLIENT_UNAUTHORIZED) { wsnSession.getFilterChain().remove(HttpEmptyPacketWriterFilter.this); } nextFilter.filterWrite(wsnSession, writeRequest); }