Top Description Fields Constructors Methods
io.netty.handler.ssl

public abstract Class ApplicationProtocolNegotiationHandler

extends ChannelInboundHandlerAdapter
Class Inheritance
Imports
io.netty.channel.Channel, .ChannelHandlerContext, .ChannelInboundHandlerAdapter, .ChannelInitializer, .ChannelPipeline, io.netty.channel.socket.ChannelInputShutdownEvent, io.netty.handler.codec.DecoderException, io.netty.util.internal.ObjectUtil, .RecyclableArrayList, io.netty.util.internal.logging.InternalLogger, .InternalLoggerFactory, javax.net.ssl.SSLException

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 extends ChannelInitializer<Channel> {
    private final SslContext sslCtx;

    public MyInitializer(SslContext sslCtx) {
        this.sslCtx = sslCtx;
    }

    protected void initChannel(Channel ch) {
        ChannelPipeline p = ch.pipeline();
        p.addLast(sslCtx.newHandler(...)); // Adds SslHandler
        p.addLast(new MyNegotiationHandler());
    }
}

public class MyNegotiationHandler extends ApplicationProtocolNegotiationHandler {
    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);
        }
    }
}

Field Summary

Modifier and TypeField and Description
private final RecyclableArrayList
private ChannelHandlerContext
private final String
private static final InternalLogger
private boolean

Constructor Summary

AccessConstructor and Description
protected
ApplicationProtocolNegotiationHandler(String
the name of the protocol to use when ALPN/NPN negotiation fails or the client does not support ALPN/NPN
fallbackProtocol
)

Creates a new instance with the specified fallback protocol name.

Method Summary

Modifier and TypeMethod and Description
public void
public void
protected abstract void
configurePipeline(ChannelHandlerContext ctx, String
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
protocol
)

Invoked on successful initial SSL/TLS handshake.

public void
private void
fireBufferedMessages()

Process all backlog into pipeline from List.

public void
handlerAdded(ChannelHandlerContext ctx)

Overrides io.netty.channel.ChannelHandlerAdapter.handlerAdded.

Implements io.netty.channel.ChannelHandler.handlerAdded.

Gets called after the ChannelHandler was added to the actual context and it's ready to handle events.
public void
handlerRemoved(ChannelHandlerContext ctx)

Overrides io.netty.channel.ChannelHandlerAdapter.handlerRemoved.

Implements io.netty.channel.ChannelHandler.handlerRemoved.

Gets called after the ChannelHandler 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.

private void
public void
Inherited from io.netty.channel.ChannelInboundHandlerAdapter:
channelActivechannelReadCompletechannelRegisteredchannelUnregisteredchannelWritabilityChanged

Field Detail

bufferedMessagesback to summary
private final RecyclableArrayList bufferedMessages
ctxback to summary
private ChannelHandlerContext ctx
fallbackProtocolback to summary
private final String fallbackProtocol
loggerback to summary
private static final InternalLogger logger
sslHandlerCheckedback to summary
private boolean sslHandlerChecked

Constructor Detail

ApplicationProtocolNegotiationHandlerback to summary
protected ApplicationProtocolNegotiationHandler(String fallbackProtocol)

Creates a new instance with the specified fallback protocol name.

Parameters
fallbackProtocol:String

the name of the protocol to use when ALPN/NPN negotiation fails or the client does not support ALPN/NPN

Method Detail

channelInactiveback to summary
public void channelInactive(ChannelHandlerContext ctx) throws Exception

Overrides io.netty.channel.ChannelInboundHandlerAdapter.channelInactive.

Implements io.netty.channel.ChannelInboundHandler.channelInactive.

Doc from io.netty.channel.ChannelInboundHandlerAdapter.channelInactive.

Calls ChannelHandlerContext#fireChannelInactive() to forward to the next ChannelInboundHandler in the ChannelPipeline. Sub-classes may override this method to change behavior.

Annotations
@Override
channelReadback to summary
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception

Overrides io.netty.channel.ChannelInboundHandlerAdapter.channelRead.

Implements io.netty.channel.ChannelInboundHandler.channelRead.

Doc from io.netty.channel.ChannelInboundHandlerAdapter.channelRead.

Calls ChannelHandlerContext#fireChannelRead(Object) to forward to the next ChannelInboundHandler in the ChannelPipeline. Sub-classes may override this method to change behavior.

Annotations
@Override
configurePipelineback to summary
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:String

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

exceptionCaughtback to summary
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception

Overrides io.netty.channel.ChannelInboundHandlerAdapter.exceptionCaught.

Implements io.netty.channel.ChannelInboundHandler.exceptionCaught, io.netty.channel.ChannelHandler.exceptionCaught.

Doc from io.netty.channel.ChannelInboundHandlerAdapter.exceptionCaught.

Calls ChannelHandlerContext#fireExceptionCaught(Throwable) to forward to the next ChannelHandler in the ChannelPipeline. Sub-classes may override this method to change behavior.

Annotations
@Override
fireBufferedMessagesback to summary
private void fireBufferedMessages()

Process all backlog into pipeline from List.

handlerAddedback to summary
public void handlerAdded(ChannelHandlerContext ctx) throws Exception

Overrides io.netty.channel.ChannelHandlerAdapter.handlerAdded.

Implements io.netty.channel.ChannelHandler.handlerAdded.

Doc from io.netty.channel.ChannelHandler.handlerAdded.

Gets called after the ChannelHandler was added to the actual context and it's ready to handle events.

Annotations
@Override
handlerRemovedback to summary
public void handlerRemoved(ChannelHandlerContext ctx) throws Exception

Overrides io.netty.channel.ChannelHandlerAdapter.handlerRemoved.

Implements io.netty.channel.ChannelHandler.handlerRemoved.

Doc from io.netty.channel.ChannelHandler.handlerRemoved.

Gets called after the ChannelHandler was removed from the actual context and it doesn't handle events anymore.

Annotations
@Override
handshakeFailureback to summary
protected void handshakeFailure(ChannelHandlerContext ctx, Throwable cause) throws Exception

Invoked on failed initial SSL/TLS handshake.

removeSelfIfPresentback to summary
private void removeSelfIfPresent(ChannelHandlerContext ctx)
userEventTriggeredback to summary
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception

Overrides io.netty.channel.ChannelInboundHandlerAdapter.userEventTriggered.

Implements io.netty.channel.ChannelInboundHandler.userEventTriggered.

Doc from io.netty.channel.ChannelInboundHandlerAdapter.userEventTriggered.

Calls ChannelHandlerContext#fireUserEventTriggered(Object) to forward to the next ChannelInboundHandler in the ChannelPipeline. Sub-classes may override this method to change behavior.

Annotations
@Override