@Test public void testNonByteBufWriteIsReleased() throws Exception { SSLEngine engine = SSLContext.getDefault().createSSLEngine(); engine.setUseClientMode(false); EmbeddedChannel ch = new EmbeddedChannel(new SslHandler(engine)); AbstractReferenceCounted referenceCounted = new AbstractReferenceCounted() { @Override public ReferenceCounted touch(Object hint) { return this; } @Override protected void deallocate() { } }; try { ch.write(referenceCounted).get(); fail(); } catch (ExecutionException e) { assertThat(e.getCause(), is(instanceOf(UnsupportedMessageTypeException.class))); } assertEquals(0, referenceCounted.refCnt()); assertTrue(ch.finishAndReleaseAll()); }
@Override public void write(final ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { if (!(msg instanceof ByteBuf)) { UnsupportedMessageTypeException exception = new UnsupportedMessageTypeException(msg, ByteBuf.class); ReferenceCountUtil.safeRelease(msg); promise.setFailure(exception); } else if (pendingUnencryptedWrites == null) { ReferenceCountUtil.safeRelease(msg); promise.setFailure(newPendingWritesNullException()); } else { pendingUnencryptedWrites.add((ByteBuf) msg, promise); } }
SslHandler extends ByteToMessageDecoder implements ChannelOutboundHandler { @Override public void write(final ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { if (!(msg instanceof ByteBuf)) { UnsupportedMessageTypeException exception = new UnsupportedMessageTypeException(msg, ByteBuf.class); ReferenceCountUtil.safeRelease(msg); promise.setFailure(exception); } else if (pendingUnencryptedWrites == null) { ReferenceCountUtil.safeRelease(msg); promise.setFailure(newPendingWritesNullException()); } else { pendingUnencryptedWrites.add((ByteBuf) msg, promise); } } }
SslHandler extends ByteToMessageDecoder implements ChannelOutboundHandler { @Override public void write(final ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { if (!(msg instanceof ByteBuf)) { UnsupportedMessageTypeException exception = new UnsupportedMessageTypeException(msg, ByteBuf.class); ReferenceCountUtil.safeRelease(msg); promise.setFailure(exception); } else if (pendingUnencryptedWrites == null) { ReferenceCountUtil.safeRelease(msg); promise.setFailure(newPendingWritesNullException()); } else { pendingUnencryptedWrites.add((ByteBuf) msg, promise); } } SslHandler(SSLEngine engine); @SuppressWarnings("deprecation")  SslHandler(SSLEngine engine, boolean startTls); @Deprecated  SslHandler(SSLEngine engine, Executor delegatedTaskExecutor); @Deprecated  SslHandler(SSLEngine engine, boolean startTls, Executor delegatedTaskExecutor); }
SslHandler extends ByteToMessageDecoder implements ChannelOutboundHandler { @Override public void write(final ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { if (!(msg instanceof ByteBuf)) { UnsupportedMessageTypeException exception = new UnsupportedMessageTypeException(msg, ByteBuf.class); ReferenceCountUtil.safeRelease(msg); promise.setFailure(exception); } else if (pendingUnencryptedWrites == null) { ReferenceCountUtil.safeRelease(msg); promise.setFailure(newPendingWritesNullException()); } else { pendingUnencryptedWrites.add((ByteBuf) msg, promise); } } SslHandler(SSLEngine engine); @SuppressWarnings("deprecation")  SslHandler(SSLEngine engine, boolean startTls); @Deprecated  SslHandler(SSLEngine engine, Executor delegatedTaskExecutor); @Deprecated  SslHandler(SSLEngine engine, boolean startTls, Executor delegatedTaskExecutor); long getHandshakeTimeoutMillis(); void setHandshakeTimeout(long handshakeTimeout, TimeUnit unit); void setHandshakeTimeoutMillis(long handshakeTimeoutMillis); @UnstableApi final void setWrapDataSize(int wrapDataSize); @Deprecated long getCloseNotifyTimeoutMillis(); @Deprecated void setCloseNotifyTimeout(long closeNotifyTimeout, TimeUnit unit); @Deprecated void setCloseNotifyTimeoutMillis(long closeNotifyFlushTimeoutMillis); final long getCloseNotifyFlushTimeoutMillis(); final void setCloseNotifyFlushTimeout(long closeNotifyFlushTimeout, TimeUnit unit); final void setCloseNotifyFlushTimeoutMillis(long closeNotifyFlushTimeoutMillis); final long getCloseNotifyReadTimeoutMillis(); final void setCloseNotifyReadTimeout(long closeNotifyReadTimeout, TimeUnit unit); final void setCloseNotifyReadTimeoutMillis(long closeNotifyReadTimeoutMillis); SSLEngine engine(); String applicationProtocol(); Future<Channel> handshakeFuture(); @Deprecated ChannelFuture close(); @Deprecated ChannelFuture close(final ChannelPromise promise); Future<Channel> sslCloseFuture(); @Override void handlerRemoved0(ChannelHandlerContext ctx); @Override void bind(ChannelHandlerContext ctx, SocketAddress localAddress, ChannelPromise promise); @Override void connect(ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress,
                        ChannelPromise promise); @Override void deregister(ChannelHandlerContext ctx, ChannelPromise promise); @Override void disconnect(final ChannelHandlerContext ctx,
                           final ChannelPromise promise); @Override void close(final ChannelHandlerContext ctx,
                      final ChannelPromise promise); @Override void read(ChannelHandlerContext ctx); @Override void write(final ChannelHandlerContext ctx, Object msg, ChannelPromise promise); @Override void flush(ChannelHandlerContext ctx); @Override void channelInactive(ChannelHandlerContext ctx); @Override void exceptionCaught(ChannelHandlerContext ctx, Throwable cause); static boolean isEncrypted(ByteBuf buffer); @Override void channelReadComplete(ChannelHandlerContext ctx); @Override void handlerAdded(final ChannelHandlerContext ctx); Future<Channel> renegotiate(); Future<Channel> renegotiate(final Promise<Channel> promise); @Override void channelActive(final ChannelHandlerContext ctx); }
SslHandler extends ByteToMessageDecoder implements ChannelOutboundHandler { @Override public void write(final ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { if (!(msg instanceof ByteBuf)) { UnsupportedMessageTypeException exception = new UnsupportedMessageTypeException(msg, ByteBuf.class); ReferenceCountUtil.safeRelease(msg); promise.setFailure(exception); } else if (pendingUnencryptedWrites == null) { ReferenceCountUtil.safeRelease(msg); promise.setFailure(newPendingWritesNullException()); } else { pendingUnencryptedWrites.add((ByteBuf) msg, promise); } } SslHandler(SSLEngine engine); @SuppressWarnings("deprecation")  SslHandler(SSLEngine engine, boolean startTls); @Deprecated  SslHandler(SSLEngine engine, Executor delegatedTaskExecutor); @Deprecated  SslHandler(SSLEngine engine, boolean startTls, Executor delegatedTaskExecutor); long getHandshakeTimeoutMillis(); void setHandshakeTimeout(long handshakeTimeout, TimeUnit unit); void setHandshakeTimeoutMillis(long handshakeTimeoutMillis); @UnstableApi final void setWrapDataSize(int wrapDataSize); @Deprecated long getCloseNotifyTimeoutMillis(); @Deprecated void setCloseNotifyTimeout(long closeNotifyTimeout, TimeUnit unit); @Deprecated void setCloseNotifyTimeoutMillis(long closeNotifyFlushTimeoutMillis); final long getCloseNotifyFlushTimeoutMillis(); final void setCloseNotifyFlushTimeout(long closeNotifyFlushTimeout, TimeUnit unit); final void setCloseNotifyFlushTimeoutMillis(long closeNotifyFlushTimeoutMillis); final long getCloseNotifyReadTimeoutMillis(); final void setCloseNotifyReadTimeout(long closeNotifyReadTimeout, TimeUnit unit); final void setCloseNotifyReadTimeoutMillis(long closeNotifyReadTimeoutMillis); SSLEngine engine(); String applicationProtocol(); Future<Channel> handshakeFuture(); @Deprecated ChannelFuture close(); @Deprecated ChannelFuture close(final ChannelPromise promise); Future<Channel> sslCloseFuture(); @Override void handlerRemoved0(ChannelHandlerContext ctx); @Override void bind(ChannelHandlerContext ctx, SocketAddress localAddress, ChannelPromise promise); @Override void connect(ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress,
                        ChannelPromise promise); @Override void deregister(ChannelHandlerContext ctx, ChannelPromise promise); @Override void disconnect(final ChannelHandlerContext ctx,
                           final ChannelPromise promise); @Override void close(final ChannelHandlerContext ctx,
                      final ChannelPromise promise); @Override void read(ChannelHandlerContext ctx); @Override void write(final ChannelHandlerContext ctx, Object msg, ChannelPromise promise); @Override void flush(ChannelHandlerContext ctx); @Override void channelInactive(ChannelHandlerContext ctx); @Override void exceptionCaught(ChannelHandlerContext ctx, Throwable cause); static boolean isEncrypted(ByteBuf buffer); @Override void channelReadComplete(ChannelHandlerContext ctx); @Override void handlerAdded(final ChannelHandlerContext ctx); Future<Channel> renegotiate(); Future<Channel> renegotiate(final Promise<Channel> promise); @Override void channelActive(final ChannelHandlerContext ctx);  }