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

public abstract Class ApplicationProtocolNegotiationHandler

extends Object
implements ChannelHandler
Class Inheritance
All Implemented Interfaces
io.netty5.channel.ChannelHandler
Imports
io.netty5.channel.Channel, .ChannelHandler, .ChannelHandlerContext, .ChannelInitializer, .ChannelPipeline, .ChannelShutdownDirection, io.netty5.handler.codec.DecoderException, io.netty5.util.internal.RecyclableArrayList, io.netty5.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
channelExceptionCaught(ChannelHandlerContext ctx, Throwable cause)

Overrides default io.netty5.channel.ChannelHandler.channelExceptionCaught.

Gets called if a Throwable was thrown when handling inbound events.
public void
channelInactive(ChannelHandlerContext ctx)

Overrides default io.netty5.channel.ChannelHandler.channelInactive.

The Channel of the ChannelHandlerContext was registered is now inactive and reached its end of lifetime.
public void
channelInboundEvent(ChannelHandlerContext ctx, Object evt)

Overrides default io.netty5.channel.ChannelHandler.channelInboundEvent.

Gets called if a custom inbound event happened.
public void
channelRead(ChannelHandlerContext ctx, Object msg)

Overrides default io.netty5.channel.ChannelHandler.channelRead.

Invoked when the current Channel has read a message from the peer.
public void
channelShutdown(ChannelHandlerContext
the ChannelHandlerContext for which we notify about the completed shutdown.
ctx
,
ChannelShutdownDirection
the ChannelShutdownDirection of the completed shutdown.
direction
)

Overrides default io.netty5.channel.ChannelHandler.channelShutdown.

The Channel of the ChannelHandlerContext was shutdown in one direction.
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.

private void
fireBufferedMessages()

Process all backlog into pipeline from List.

public void
handlerAdded(ChannelHandlerContext ctx)

Overrides default io.netty5.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 default io.netty5.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
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

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

channelExceptionCaughtback to summary
public void channelExceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception

Overrides default io.netty5.channel.ChannelHandler.channelExceptionCaught.

Doc from io.netty5.channel.ChannelHandler.channelExceptionCaught.

Gets called if a Throwable was thrown when handling inbound events.

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

Overrides default io.netty5.channel.ChannelHandler.channelInactive.

Doc from io.netty5.channel.ChannelHandler.channelInactive.

The Channel of the ChannelHandlerContext was registered is now inactive and reached its end of lifetime.

Annotations
@Override
channelInboundEventback to summary
public void channelInboundEvent(ChannelHandlerContext ctx, Object evt) throws Exception

Overrides default io.netty5.channel.ChannelHandler.channelInboundEvent.

Doc from io.netty5.channel.ChannelHandler.channelInboundEvent.

Gets called if a custom inbound event happened.

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

Overrides default io.netty5.channel.ChannelHandler.channelRead.

Doc from io.netty5.channel.ChannelHandler.channelRead.

Invoked when the current Channel has read a message from the peer.

Annotations
@Override
channelShutdownback to summary
public void channelShutdown(ChannelHandlerContext ctx, ChannelShutdownDirection direction)

Overrides default io.netty5.channel.ChannelHandler.channelShutdown.

Doc from io.netty5.channel.ChannelHandler.channelShutdown.

The Channel of the ChannelHandlerContext 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.

Parameters
ctx:ChannelHandlerContext

the ChannelHandlerContext for which we notify about the completed shutdown.

direction:ChannelShutdownDirection

the ChannelShutdownDirection of the completed shutdown.

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

fireBufferedMessagesback to summary
private void fireBufferedMessages()

Process all backlog into pipeline from List.

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

Overrides default io.netty5.channel.ChannelHandler.handlerAdded.

Doc from io.netty5.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 default io.netty5.channel.ChannelHandler.handlerRemoved.

Doc from io.netty5.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)