Class ApplicationProtocolNegotiationHandler
java.lang.Object
io.netty.channel.ChannelHandlerAdapter
io.netty.channel.ChannelInboundHandlerAdapter
io.netty.handler.ssl.ApplicationProtocolNegotiationHandler
- All Implemented Interfaces:
ChannelHandler, ChannelInboundHandler
Configures a
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 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); } } }
-
Nested Class Summary
Nested classes/interfaces inherited from interface ChannelHandler
ChannelHandler.Sharable -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final RecyclableArrayListprivate ChannelHandlerContextprivate final java.lang.Stringprivate static final InternalLoggerprivate boolean -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedApplicationProtocolNegotiationHandler(java.lang.String fallbackProtocol) Creates a new instance with the specified fallback protocol name. -
Method Summary
Modifier and TypeMethodDescriptionvoidCallsChannelHandlerContext.fireChannelInactive()to forward to the nextChannelInboundHandlerin theChannelPipeline.voidchannelRead(ChannelHandlerContext ctx, java.lang.Object msg) CallsChannelHandlerContext.fireChannelRead(Object)to forward to the nextChannelInboundHandlerin theChannelPipeline.protected abstract voidconfigurePipeline(ChannelHandlerContext ctx, java.lang.String protocol) Invoked on successful initial SSL/TLS handshake.voidexceptionCaught(ChannelHandlerContext ctx, java.lang.Throwable cause) CallsChannelHandlerContext.fireExceptionCaught(Throwable)to forward to the nextChannelHandlerin theChannelPipeline.private voidProcess all backlog into pipeline from List.voidDo nothing by default, sub-classes may override this method.voidDo nothing by default, sub-classes may override this method.protected voidhandshakeFailure(ChannelHandlerContext ctx, java.lang.Throwable cause) Invoked on failed initial SSL/TLS handshake.private voidvoiduserEventTriggered(ChannelHandlerContext ctx, java.lang.Object evt) CallsChannelHandlerContext.fireUserEventTriggered(Object)to forward to the nextChannelInboundHandlerin theChannelPipeline.Methods inherited from class ChannelInboundHandlerAdapter
channelActive, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChangedMethods inherited from class ChannelHandlerAdapter
ensureNotSharable, isSharableMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
logger
-
fallbackProtocol
private final java.lang.String fallbackProtocol -
bufferedMessages
-
ctx
-
sslHandlerChecked
private boolean sslHandlerChecked
-
-
Constructor Details
-
ApplicationProtocolNegotiationHandler
protected ApplicationProtocolNegotiationHandler(java.lang.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 Details
-
handlerAdded
Description copied from class:ChannelHandlerAdapterDo nothing by default, sub-classes may override this method.- Specified by:
handlerAddedin interfaceChannelHandler- Overrides:
handlerAddedin classChannelHandlerAdapter- Throws:
java.lang.Exception
-
handlerRemoved
Description copied from class:ChannelHandlerAdapterDo nothing by default, sub-classes may override this method.- Specified by:
handlerRemovedin interfaceChannelHandler- Overrides:
handlerRemovedin classChannelHandlerAdapter- Throws:
java.lang.Exception
-
channelRead
Description copied from class:ChannelInboundHandlerAdapterCallsChannelHandlerContext.fireChannelRead(Object)to forward to the nextChannelInboundHandlerin theChannelPipeline. Sub-classes may override this method to change behavior.- Specified by:
channelReadin interfaceChannelInboundHandler- Overrides:
channelReadin classChannelInboundHandlerAdapter- Throws:
java.lang.Exception
-
fireBufferedMessages
private void fireBufferedMessages()Process all backlog into pipeline from List. -
userEventTriggered
public void userEventTriggered(ChannelHandlerContext ctx, java.lang.Object evt) throws java.lang.Exception Description copied from class:ChannelInboundHandlerAdapterCallsChannelHandlerContext.fireUserEventTriggered(Object)to forward to the nextChannelInboundHandlerin theChannelPipeline. Sub-classes may override this method to change behavior.- Specified by:
userEventTriggeredin interfaceChannelInboundHandler- Overrides:
userEventTriggeredin classChannelInboundHandlerAdapter- Throws:
java.lang.Exception
-
channelInactive
Description copied from class:ChannelInboundHandlerAdapterCallsChannelHandlerContext.fireChannelInactive()to forward to the nextChannelInboundHandlerin theChannelPipeline. Sub-classes may override this method to change behavior.- Specified by:
channelInactivein interfaceChannelInboundHandler- Overrides:
channelInactivein classChannelInboundHandlerAdapter- Throws:
java.lang.Exception
-
removeSelfIfPresent
-
configurePipeline
protected abstract void configurePipeline(ChannelHandlerContext ctx, java.lang.String protocol) throws java.lang.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:
java.lang.Exception
-
handshakeFailure
protected void handshakeFailure(ChannelHandlerContext ctx, java.lang.Throwable cause) throws java.lang.Exception Invoked on failed initial SSL/TLS handshake.- Throws:
java.lang.Exception
-
exceptionCaught
public void exceptionCaught(ChannelHandlerContext ctx, java.lang.Throwable cause) throws java.lang.Exception Description copied from class:ChannelInboundHandlerAdapterCallsChannelHandlerContext.fireExceptionCaught(Throwable)to forward to the nextChannelHandlerin theChannelPipeline. Sub-classes may override this method to change behavior.- Specified by:
exceptionCaughtin interfaceChannelHandler- Specified by:
exceptionCaughtin interfaceChannelInboundHandler- Overrides:
exceptionCaughtin classChannelInboundHandlerAdapter- Throws:
java.lang.Exception
-