- 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 aChannelPipeline
depending 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 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); } } }
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
ApplicationProtocolNegotiationHandler(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 void
channelExceptionCaught(io.netty5.channel.ChannelHandlerContext ctx, Throwable cause)
void
channelInactive(io.netty5.channel.ChannelHandlerContext ctx)
void
channelInboundEvent(io.netty5.channel.ChannelHandlerContext ctx, Object evt)
void
channelRead(io.netty5.channel.ChannelHandlerContext ctx, Object msg)
void
channelShutdown(io.netty5.channel.ChannelHandlerContext ctx, io.netty5.channel.ChannelShutdownDirection direction)
protected abstract void
configurePipeline(io.netty5.channel.ChannelHandlerContext ctx, String protocol)
Invoked on successful initial SSL/TLS handshake.void
handlerAdded(io.netty5.channel.ChannelHandlerContext ctx)
void
handlerRemoved(io.netty5.channel.ChannelHandlerContext ctx)
protected void
handshakeFailure(io.netty5.channel.ChannelHandlerContext ctx, Throwable cause)
Invoked on failed initial SSL/TLS handshake.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.netty5.channel.ChannelHandler
bind, channelActive, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, close, connect, deregister, disconnect, flush, isSharable, pendingOutboundBytes, read, register, sendOutboundEvent, shutdown, write
-
-
-
-
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:
handlerAdded
in interfaceio.netty5.channel.ChannelHandler
- Throws:
Exception
-
handlerRemoved
public void handlerRemoved(io.netty5.channel.ChannelHandlerContext ctx) throws Exception
- Specified by:
handlerRemoved
in interfaceio.netty5.channel.ChannelHandler
- Throws:
Exception
-
channelRead
public void channelRead(io.netty5.channel.ChannelHandlerContext ctx, Object msg) throws Exception
- Specified by:
channelRead
in interfaceio.netty5.channel.ChannelHandler
- Throws:
Exception
-
channelInboundEvent
public void channelInboundEvent(io.netty5.channel.ChannelHandlerContext ctx, Object evt) throws Exception
- Specified by:
channelInboundEvent
in interfaceio.netty5.channel.ChannelHandler
- Throws:
Exception
-
channelShutdown
public void channelShutdown(io.netty5.channel.ChannelHandlerContext ctx, io.netty5.channel.ChannelShutdownDirection direction)
- Specified by:
channelShutdown
in interfaceio.netty5.channel.ChannelHandler
-
channelInactive
public void channelInactive(io.netty5.channel.ChannelHandlerContext ctx) throws Exception
- Specified by:
channelInactive
in interfaceio.netty5.channel.ChannelHandler
- Throws:
Exception
-
configurePipeline
protected abstract void configurePipeline(io.netty5.channel.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
protected void handshakeFailure(io.netty5.channel.ChannelHandlerContext ctx, Throwable cause) throws Exception
Invoked on failed initial SSL/TLS handshake.- Throws:
Exception
-
-