Package io.netty5.handler.ssl
Class ApplicationProtocolNegotiationHandler
- java.lang.Object
-
- io.netty5.handler.ssl.ApplicationProtocolNegotiationHandler
-
- All Implemented Interfaces:
io.netty5.channel.ChannelHandler
public abstract class ApplicationProtocolNegotiationHandler extends Object implements io.netty5.channel.ChannelHandler
Configures aChannelPipelinedepending on the application-level protocol negotiation result ofSslHandler. For example, you could configure your HTTP pipeline depending on the result of ALPN:public class MyInitializer extends
ChannelInitializer<Channel> { private finalSslContextsslCtx; public MyInitializer(SslContextsslCtx) { this.sslCtx = sslCtx; } protected void initChannel(Channelch) {ChannelPipelinep = ch.pipeline(); p.addLast(sslCtx.newHandler(...)); // AddsSslHandlerp.addLast(new MyNegotiationHandler()); } } public class MyNegotiationHandler extendsApplicationProtocolNegotiationHandler{ public MyNegotiationHandler() { super(ApplicationProtocolNames.HTTP_1_1); } protected void configurePipeline(ChannelHandlerContextctx, 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); } } }
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedApplicationProtocolNegotiationHandler(String fallbackProtocol)Creates a new instance with the specified fallback protocol name.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidchannelInactive(io.netty5.channel.ChannelHandlerContext ctx)voidchannelRead(io.netty5.channel.ChannelHandlerContext ctx, Object msg)protected abstract voidconfigurePipeline(io.netty5.channel.ChannelHandlerContext ctx, String protocol)Invoked on successful initial SSL/TLS handshake.voidexceptionCaught(io.netty5.channel.ChannelHandlerContext ctx, Throwable cause)voidhandlerAdded(io.netty5.channel.ChannelHandlerContext ctx)voidhandlerRemoved(io.netty5.channel.ChannelHandlerContext ctx)protected voidhandshakeFailure(io.netty5.channel.ChannelHandlerContext ctx, Throwable cause)Invoked on failed initial SSL/TLS handshake.voiduserEventTriggered(io.netty5.channel.ChannelHandlerContext ctx, Object evt)
-
-
-
Constructor Detail
-
ApplicationProtocolNegotiationHandler
protected ApplicationProtocolNegotiationHandler(String fallbackProtocol)
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 Detail
-
handlerAdded
public void handlerAdded(io.netty5.channel.ChannelHandlerContext ctx) throws Exception- Specified by:
handlerAddedin interfaceio.netty5.channel.ChannelHandler- Throws:
Exception
-
handlerRemoved
public void handlerRemoved(io.netty5.channel.ChannelHandlerContext ctx) throws Exception- Specified by:
handlerRemovedin interfaceio.netty5.channel.ChannelHandler- Throws:
Exception
-
channelRead
public void channelRead(io.netty5.channel.ChannelHandlerContext ctx, Object msg) throws Exception- Specified by:
channelReadin interfaceio.netty5.channel.ChannelHandler- Throws:
Exception
-
userEventTriggered
public void userEventTriggered(io.netty5.channel.ChannelHandlerContext ctx, Object evt) throws Exception- Specified by:
userEventTriggeredin interfaceio.netty5.channel.ChannelHandler- Throws:
Exception
-
channelInactive
public void channelInactive(io.netty5.channel.ChannelHandlerContext ctx) throws Exception- Specified by:
channelInactivein interfaceio.netty5.channel.ChannelHandler- Throws:
Exception
-
configurePipeline
protected abstract void configurePipeline(io.netty5.channel.ChannelHandlerContext ctx, String protocol) throws ExceptionInvoked 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
protected void handshakeFailure(io.netty5.channel.ChannelHandlerContext ctx, Throwable cause) throws ExceptionInvoked on failed initial SSL/TLS handshake.- Throws:
Exception
-
-