- java.lang.Object
-
- io.netty5.handler.ssl.ApplicationProtocolNegotiationHandler
-
- All Implemented Interfaces:
ChannelHandler
public abstract class ApplicationProtocolNegotiationHandler extends Object implements 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(ChannelHandlerContext ctx, Throwable cause)
Gets called if aThrowable
was thrown when handling inbound events.void
channelInactive(ChannelHandlerContext ctx)
TheChannel
of theChannelHandlerContext
was registered is now inactive and reached its end of lifetime.void
channelInboundEvent(ChannelHandlerContext ctx, Object evt)
Gets called if a custom inbound event happened.void
channelRead(ChannelHandlerContext ctx, Object msg)
Invoked when the currentChannel
has read a message from the peer.void
channelShutdown(ChannelHandlerContext ctx, ChannelShutdownDirection direction)
TheChannel
of theChannelHandlerContext
was shutdown in one direction.protected abstract void
configurePipeline(ChannelHandlerContext ctx, String protocol)
Invoked on successful initial SSL/TLS handshake.void
handlerAdded(ChannelHandlerContext ctx)
Gets called after theChannelHandler
was added to the actual context and it's ready to handle events.void
handlerRemoved(ChannelHandlerContext ctx)
Gets called after theChannelHandler
was removed from the actual context and it doesn't handle events anymore.protected void
handshakeFailure(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:ChannelHandler
Gets called after theChannelHandler
was added to the actual context and it's ready to handle events.- Specified by:
handlerAdded
in interfaceChannelHandler
- Throws:
Exception
-
handlerRemoved
public void handlerRemoved(ChannelHandlerContext ctx) throws Exception
Description copied from interface:ChannelHandler
Gets called after theChannelHandler
was removed from the actual context and it doesn't handle events anymore.- Specified by:
handlerRemoved
in interfaceChannelHandler
- Throws:
Exception
-
channelRead
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception
Description copied from interface:ChannelHandler
Invoked when the currentChannel
has read a message from the peer.- Specified by:
channelRead
in interfaceChannelHandler
- Throws:
Exception
-
channelInboundEvent
public void channelInboundEvent(ChannelHandlerContext ctx, Object evt) throws Exception
Description copied from interface:ChannelHandler
Gets called if a custom inbound event happened.- Specified by:
channelInboundEvent
in interfaceChannelHandler
- Throws:
Exception
-
channelShutdown
public void channelShutdown(ChannelHandlerContext ctx, ChannelShutdownDirection direction)
Description copied from interface:ChannelHandler
TheChannel
of theChannelHandlerContext
was 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:
channelShutdown
in interfaceChannelHandler
- Parameters:
ctx
- theChannelHandlerContext
for which we notify about the completed shutdown.direction
- theChannelShutdownDirection
of the completed shutdown.
-
channelInactive
public void channelInactive(ChannelHandlerContext ctx) throws Exception
Description copied from interface:ChannelHandler
TheChannel
of theChannelHandlerContext
was registered is now inactive and reached its end of lifetime.- Specified by:
channelInactive
in 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:ChannelHandler
Gets called if aThrowable
was thrown when handling inbound events.- Specified by:
channelExceptionCaught
in interfaceChannelHandler
- Throws:
Exception
-
-