- java.lang.Object
-
- io.netty5.handler.ssl.ApplicationProtocolNegotiationHandler
-
- All Implemented Interfaces:
ChannelHandler
public abstract class ApplicationProtocolNegotiationHandler extends Object implements 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 voidchannelExceptionCaught(ChannelHandlerContext ctx, Throwable cause)Gets called if aThrowablewas thrown when handling inbound events.voidchannelInactive(ChannelHandlerContext ctx)TheChannelof theChannelHandlerContextwas registered is now inactive and reached its end of lifetime.voidchannelInboundEvent(ChannelHandlerContext ctx, Object evt)Gets called if a custom inbound event happened.voidchannelRead(ChannelHandlerContext ctx, Object msg)Invoked when the currentChannelhas read a message from the peer.voidchannelShutdown(ChannelHandlerContext ctx, ChannelShutdownDirection direction)TheChannelof theChannelHandlerContextwas shutdown in one direction.protected abstract voidconfigurePipeline(ChannelHandlerContext ctx, String protocol)Invoked on successful initial SSL/TLS handshake.voidhandlerAdded(ChannelHandlerContext ctx)Gets called after theChannelHandlerwas added to the actual context and it's ready to handle events.voidhandlerRemoved(ChannelHandlerContext ctx)Gets called after theChannelHandlerwas removed from the actual context and it doesn't handle events anymore.protected voidhandshakeFailure(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(ChannelHandlerContext ctx) throws Exception
Description copied from interface:ChannelHandlerGets called after theChannelHandlerwas added to the actual context and it's ready to handle events.- Specified by:
handlerAddedin interfaceChannelHandler- Throws:
Exception
-
handlerRemoved
public void handlerRemoved(ChannelHandlerContext ctx) throws Exception
Description copied from interface:ChannelHandlerGets called after theChannelHandlerwas removed from the actual context and it doesn't handle events anymore.- Specified by:
handlerRemovedin interfaceChannelHandler- Throws:
Exception
-
channelRead
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception
Description copied from interface:ChannelHandlerInvoked when the currentChannelhas read a message from the peer.- Specified by:
channelReadin interfaceChannelHandler- Throws:
Exception
-
channelInboundEvent
public void channelInboundEvent(ChannelHandlerContext ctx, Object evt) throws Exception
Description copied from interface:ChannelHandlerGets called if a custom inbound event happened.- Specified by:
channelInboundEventin interfaceChannelHandler- Throws:
Exception
-
channelShutdown
public void channelShutdown(ChannelHandlerContext ctx, ChannelShutdownDirection direction)
Description copied from interface:ChannelHandlerTheChannelof theChannelHandlerContextwas shutdown in one direction. This might either be because the remote peer did cause a shutdown of one direction or the shutdown was requested explicit by us and was executed.- Specified by:
channelShutdownin interfaceChannelHandler- Parameters:
ctx- theChannelHandlerContextfor which we notify about the completed shutdown.direction- theChannelShutdownDirectionof the completed shutdown.
-
channelInactive
public void channelInactive(ChannelHandlerContext ctx) throws Exception
Description copied from interface:ChannelHandlerTheChannelof theChannelHandlerContextwas registered is now inactive and reached its end of lifetime.- Specified by:
channelInactivein interfaceChannelHandler- Throws:
Exception
-
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
protected void handshakeFailure(ChannelHandlerContext ctx, Throwable cause) throws Exception
Invoked on failed initial SSL/TLS handshake.- Throws:
Exception
-
channelExceptionCaught
public void channelExceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception
Description copied from interface:ChannelHandlerGets called if aThrowablewas thrown when handling inbound events.- Specified by:
channelExceptionCaughtin interfaceChannelHandler- Throws:
Exception
-
-