Top Description Fields Constructors Methods
io.netty.handler.ssl

public Class OptionalSslHandler

extends ByteToMessageDecoder
Class Inheritance
Imports
io.netty.buffer.ByteBuf, .ByteBufAllocator, io.netty.channel.ChannelHandler, .ChannelHandlerContext, io.netty.handler.codec.ByteToMessageDecoder, io.netty.util.ReferenceCountUtil, io.netty.util.internal.ObjectUtil, javax.net.ssl.SSLContext, .SSLParameters, java.util.List

OptionalSslHandler is a utility decoder to support both SSL and non-SSL handlers based on the first message received.

Field Summary

Modifier and TypeField and Description
private final SslContext
Inherited from io.netty.handler.codec.ByteToMessageDecoder:
COMPOSITE_CUMULATORMERGE_CUMULATOR

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected void
decode(ChannelHandlerContext context, ByteBuf
the ByteBuf from which to read data
in
,
List<Object>
the List to which decoded messages should be added
out
)

Implements abstract io.netty.handler.codec.ByteToMessageDecoder.decode.

Decode the from one ByteBuf to an other.
private void
private void
protected ChannelHandler

Returns:

the ChannelHandler which will replace the OptionalSslHandler in the pipeline or null to simply remove the OptionalSslHandler if the traffic is non-SSL.
newNonSslHandler
(ChannelHandlerContext context)

Override to configure the ChannelHandler.

protected String

Returns:

the name of the non-SSL handler.
newNonSslHandlerName
()

Optionally specify the non-SSL handler name, this method may return null.

protected SslHandler

Returns:

the SslHandler which will replace the OptionalSslHandler in the pipeline if the traffic is SSL.
newSslHandler
(ChannelHandlerContext context, SslContext
the SSLContext to use.
sslContext
)

Override to configure the SslHandler eg.

protected String

Returns:

the name of the SSL handler.
newSslHandlerName
()

Optionally specify the SSL handler name, this method may return null.

Inherited from io.netty.handler.codec.ByteToMessageDecoder:
actualReadableBytescallDecodechannelInactivechannelReadchannelReadCompletedecodeLastdiscardSomeReadByteshandlerRemovedhandlerRemoved0internalBufferisSingleDecodesetCumulatorsetDiscardAfterReadssetSingleDecodeuserEventTriggered

Field Detail

sslContextback to summary
private final SslContext sslContext

Constructor Detail

OptionalSslHandlerback to summary
public OptionalSslHandler(SslContext sslContext)

Method Detail

decodeback to summary
protected void decode(ChannelHandlerContext context, ByteBuf in, List<Object> out) throws Exception

Implements abstract io.netty.handler.codec.ByteToMessageDecoder.decode.

Doc from io.netty.handler.codec.ByteToMessageDecoder.decode.

Decode the from one ByteBuf to an other. This method will be called till either the input ByteBuf has nothing to read when return from this method or till nothing was read from the input ByteBuf.

Parameters
context:ChannelHandlerContext

the ChannelHandlerContext which this ByteToMessageDecoder belongs to

in:ByteBuf

the ByteBuf from which to read data

out:List<Object>

the List to which decoded messages should be added

Annotations
@Override
Exceptions
Exception:
is thrown if an error occurs
handleNonSslback to summary
private void handleNonSsl(ChannelHandlerContext context)
handleSslback to summary
private void handleSsl(ChannelHandlerContext context)
newNonSslHandlerback to summary
protected ChannelHandler newNonSslHandler(ChannelHandlerContext context)

Override to configure the ChannelHandler.

Parameters
context:ChannelHandlerContext

the ChannelHandlerContext to use.

Returns:ChannelHandler

the ChannelHandler which will replace the OptionalSslHandler in the pipeline or null to simply remove the OptionalSslHandler if the traffic is non-SSL.

newNonSslHandlerNameback to summary
protected String newNonSslHandlerName()

Optionally specify the non-SSL handler name, this method may return null.

Returns:String

the name of the non-SSL handler.

newSslHandlerback to summary
protected SslHandler newSslHandler(ChannelHandlerContext context, SslContext sslContext)

Override to configure the SslHandler eg. SSLParameters#setEndpointIdentificationAlgorithm(String). The hostname and port is not known by this method so servers may want to override this method and use the SslContext#newHandler(ByteBufAllocator, String, int) variant.

Parameters
context:ChannelHandlerContext

the ChannelHandlerContext to use.

sslContext:SslContext

the SSLContext to use.

Returns:SslHandler

the SslHandler which will replace the OptionalSslHandler in the pipeline if the traffic is SSL.

newSslHandlerNameback to summary
protected String newSslHandlerName()

Optionally specify the SSL handler name, this method may return null.

Returns:String

the name of the SSL handler.