Package io.netty.handler.ssl
Class ApplicationProtocolNegotiationHandler
java.lang.Object
io.netty.channel.ChannelHandlerAdapter
io.netty.channel.ChannelInboundHandlerAdapter
io.netty.handler.ssl.ApplicationProtocolNegotiationHandler
- All Implemented Interfaces:
ChannelHandler
,ChannelInboundHandler
Configures a
ChannelPipeline
depending on the application-level protocol negotiation result of
SslHandler
. For example, you could configure your HTTP pipeline depending on the result of ALPN:
public class MyInitializer extendsChannelInitializer
<Channel
> { private finalSslContext
sslCtx; public MyInitializer(SslContext
sslCtx) { this.sslCtx = sslCtx; } protected void initChannel(Channel
ch) {ChannelPipeline
p = ch.pipeline(); p.addLast(sslCtx.newHandler(...)); // AddsSslHandler
p.addLast(new MyNegotiationHandler()); } } public class MyNegotiationHandler extendsApplicationProtocolNegotiationHandler
{ public MyNegotiationHandler() { super(ApplicationProtocolNames
.HTTP_1_1); } protected void configurePipeline(ChannelHandlerContext
ctx, String protocol) { if (ApplicationProtocolNames
.HTTP_2.equals(protocol) { configureHttp2(ctx); } else if (ApplicationProtocolNames
.HTTP_1_1.equals(protocol)) { configureHttp1(ctx); } else { throw new IllegalStateException("unknown protocol: " + protocol); } } }
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler
ChannelHandler.Sharable
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final RecyclableArrayList
private ChannelHandlerContext
private final String
private static final InternalLogger
private boolean
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
ApplicationProtocolNegotiationHandler
(String fallbackProtocol) Creates a new instance with the specified fallback protocol name. -
Method Summary
Modifier and TypeMethodDescriptionvoid
CallsChannelHandlerContext.fireChannelInactive()
to forward to the nextChannelInboundHandler
in theChannelPipeline
.void
channelRead
(ChannelHandlerContext ctx, Object msg) CallsChannelHandlerContext.fireChannelRead(Object)
to forward to the nextChannelInboundHandler
in theChannelPipeline
.protected abstract void
configurePipeline
(ChannelHandlerContext ctx, String protocol) Invoked on successful initial SSL/TLS handshake.void
exceptionCaught
(ChannelHandlerContext ctx, Throwable cause) CallsChannelHandlerContext.fireExceptionCaught(Throwable)
to forward to the nextChannelHandler
in theChannelPipeline
.private void
Process all backlog into pipeline from List.void
Do nothing by default, sub-classes may override this method.void
Do nothing by default, sub-classes may override this method.protected void
handshakeFailure
(ChannelHandlerContext ctx, Throwable cause) Invoked on failed initial SSL/TLS handshake.private void
void
userEventTriggered
(ChannelHandlerContext ctx, Object evt) CallsChannelHandlerContext.fireUserEventTriggered(Object)
to forward to the nextChannelInboundHandler
in theChannelPipeline
.Methods inherited from class io.netty.channel.ChannelInboundHandlerAdapter
channelActive, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged
Methods inherited from class io.netty.channel.ChannelHandlerAdapter
ensureNotSharable, isSharable
-
Field Details
-
logger
-
fallbackProtocol
-
bufferedMessages
-
ctx
-
sslHandlerChecked
private boolean sslHandlerChecked
-
-
Constructor Details
-
ApplicationProtocolNegotiationHandler
Creates a new instance with the specified fallback protocol name.- Parameters:
fallbackProtocol
- the name of the protocol to use when ALPN/NPN negotiation fails or the client does not support ALPN/NPN
-
-
Method Details
-
handlerAdded
Description copied from class:ChannelHandlerAdapter
Do nothing by default, sub-classes may override this method.- Specified by:
handlerAdded
in interfaceChannelHandler
- Overrides:
handlerAdded
in classChannelHandlerAdapter
- Throws:
Exception
-
handlerRemoved
Description copied from class:ChannelHandlerAdapter
Do nothing by default, sub-classes may override this method.- Specified by:
handlerRemoved
in interfaceChannelHandler
- Overrides:
handlerRemoved
in classChannelHandlerAdapter
- Throws:
Exception
-
channelRead
Description copied from class:ChannelInboundHandlerAdapter
CallsChannelHandlerContext.fireChannelRead(Object)
to forward to the nextChannelInboundHandler
in theChannelPipeline
. Sub-classes may override this method to change behavior.- Specified by:
channelRead
in interfaceChannelInboundHandler
- Overrides:
channelRead
in classChannelInboundHandlerAdapter
- Throws:
Exception
-
fireBufferedMessages
private void fireBufferedMessages()Process all backlog into pipeline from List. -
userEventTriggered
Description copied from class:ChannelInboundHandlerAdapter
CallsChannelHandlerContext.fireUserEventTriggered(Object)
to forward to the nextChannelInboundHandler
in theChannelPipeline
. Sub-classes may override this method to change behavior.- Specified by:
userEventTriggered
in interfaceChannelInboundHandler
- Overrides:
userEventTriggered
in classChannelInboundHandlerAdapter
- Throws:
Exception
-
channelInactive
Description copied from class:ChannelInboundHandlerAdapter
CallsChannelHandlerContext.fireChannelInactive()
to forward to the nextChannelInboundHandler
in theChannelPipeline
. Sub-classes may override this method to change behavior.- Specified by:
channelInactive
in interfaceChannelInboundHandler
- Overrides:
channelInactive
in classChannelInboundHandlerAdapter
- Throws:
Exception
-
removeSelfIfPresent
-
configurePipeline
protected abstract void configurePipeline(ChannelHandlerContext ctx, String protocol) throws Exception Invoked on successful initial SSL/TLS handshake. Implement this method to configure your pipeline for the negotiated application-level protocol.- Parameters:
protocol
- the name of the negotiated application-level protocol, or the fallback protocol name specified in the constructor call if negotiation failed or the client isn't aware of ALPN/NPN extension- Throws:
Exception
-
handshakeFailure
Invoked on failed initial SSL/TLS handshake.- Throws:
Exception
-
exceptionCaught
Description copied from class:ChannelInboundHandlerAdapter
CallsChannelHandlerContext.fireExceptionCaught(Throwable)
to forward to the nextChannelHandler
in theChannelPipeline
. Sub-classes may override this method to change behavior.- Specified by:
exceptionCaught
in interfaceChannelHandler
- Specified by:
exceptionCaught
in interfaceChannelInboundHandler
- Overrides:
exceptionCaught
in classChannelInboundHandlerAdapter
- Throws:
Exception
-