public abstract class ApplicationProtocolNegotiationHandler
extends io.netty.channel.ChannelInboundHandlerAdapter
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); } } }
Modifier | Constructor and Description |
---|---|
protected |
ApplicationProtocolNegotiationHandler(String fallbackProtocol)
Creates a new instance with the specified fallback protocol name.
|
Modifier and Type | Method and Description |
---|---|
void |
channelInactive(io.netty.channel.ChannelHandlerContext ctx) |
void |
channelRead(io.netty.channel.ChannelHandlerContext ctx,
Object msg) |
protected abstract void |
configurePipeline(io.netty.channel.ChannelHandlerContext ctx,
String protocol)
Invoked on successful initial SSL/TLS handshake.
|
void |
exceptionCaught(io.netty.channel.ChannelHandlerContext ctx,
Throwable cause) |
void |
handlerAdded(io.netty.channel.ChannelHandlerContext ctx) |
void |
handlerRemoved(io.netty.channel.ChannelHandlerContext ctx) |
protected void |
handshakeFailure(io.netty.channel.ChannelHandlerContext ctx,
Throwable cause)
Invoked on failed initial SSL/TLS handshake.
|
void |
userEventTriggered(io.netty.channel.ChannelHandlerContext ctx,
Object evt) |
protected ApplicationProtocolNegotiationHandler(String fallbackProtocol)
fallbackProtocol
- the name of the protocol to use when
ALPN/NPN negotiation fails or the client does not support ALPN/NPNpublic void handlerAdded(io.netty.channel.ChannelHandlerContext ctx) throws Exception
handlerAdded
in interface io.netty.channel.ChannelHandler
handlerAdded
in class io.netty.channel.ChannelHandlerAdapter
Exception
public void handlerRemoved(io.netty.channel.ChannelHandlerContext ctx) throws Exception
handlerRemoved
in interface io.netty.channel.ChannelHandler
handlerRemoved
in class io.netty.channel.ChannelHandlerAdapter
Exception
public void channelRead(io.netty.channel.ChannelHandlerContext ctx, Object msg) throws Exception
channelRead
in interface io.netty.channel.ChannelInboundHandler
channelRead
in class io.netty.channel.ChannelInboundHandlerAdapter
Exception
public void userEventTriggered(io.netty.channel.ChannelHandlerContext ctx, Object evt) throws Exception
userEventTriggered
in interface io.netty.channel.ChannelInboundHandler
userEventTriggered
in class io.netty.channel.ChannelInboundHandlerAdapter
Exception
public void channelInactive(io.netty.channel.ChannelHandlerContext ctx) throws Exception
channelInactive
in interface io.netty.channel.ChannelInboundHandler
channelInactive
in class io.netty.channel.ChannelInboundHandlerAdapter
Exception
protected abstract void configurePipeline(io.netty.channel.ChannelHandlerContext ctx, String protocol) throws Exception
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 extensionException
protected void handshakeFailure(io.netty.channel.ChannelHandlerContext ctx, Throwable cause) throws Exception
Exception
public void exceptionCaught(io.netty.channel.ChannelHandlerContext ctx, Throwable cause) throws Exception
exceptionCaught
in interface io.netty.channel.ChannelHandler
exceptionCaught
in interface io.netty.channel.ChannelInboundHandler
exceptionCaught
in class io.netty.channel.ChannelInboundHandlerAdapter
Exception
Copyright © 2008–2024 The Netty Project. All rights reserved.