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); } } }
| Modifier and Type | Field and Description |
|---|---|
| private final RecyclableArrayList | |
| private ChannelHandlerContext | |
| private final String | |
| private static final InternalLogger | |
| private boolean |
| Access | Constructor 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. |
| Modifier and Type | Method and Description |
|---|---|
| public void | channelExceptionCaught(ChannelHandlerContext ctx, Throwable cause)
Overrides default io. Throwable was thrown when handling inbound events.
|
| public void | channelInactive(ChannelHandlerContext ctx)
Overrides default io. 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. |
| public void | channelRead(ChannelHandlerContext ctx, Object msg)
Overrides default io. Channel has read a message from the peer.
|
| public void | channelShutdown(ChannelHandlerContext
the ctx, ChannelShutdownDirection ChannelHandlerContext for which we notify about the completed shutdown.the direction)ChannelShutdownDirection of the completed shutdown.Overrides default io. 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 | |
| public void | handlerAdded(ChannelHandlerContext ctx)
Overrides default io. ChannelHandler was added to the actual context and it's ready to handle events.
|
| public void | handlerRemoved(ChannelHandlerContext ctx)
Overrides default io. 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 |
| bufferedMessages | back to summary |
|---|---|
| private final RecyclableArrayList bufferedMessages | |
| ctx | back to summary |
|---|---|
| private ChannelHandlerContext ctx | |
| fallbackProtocol | back to summary |
|---|---|
| private final String fallbackProtocol | |
| logger | back to summary |
|---|---|
| private static final InternalLogger logger | |
| sslHandlerChecked | back to summary |
|---|---|
| private boolean sslHandlerChecked | |
| ApplicationProtocolNegotiationHandler | back to summary |
|---|---|
| protected ApplicationProtocolNegotiationHandler(String fallbackProtocol) Creates a new instance with the specified fallback protocol name.
| |
| channelExceptionCaught | back to summary |
|---|---|
| public void channelExceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception Overrides default io. Doc from io. Gets called if a
| |
| channelInactive | back to summary |
|---|---|
| public void channelInactive(ChannelHandlerContext ctx) throws Exception Overrides default io. Doc from io. The
| |
| channelInboundEvent | back to summary |
|---|---|
| public void channelInboundEvent(ChannelHandlerContext ctx, Object evt) throws Exception Overrides default io. Doc from io. Gets called if a custom inbound event happened.
| |
| channelRead | back to summary |
|---|---|
| public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception Overrides default io. Doc from io. Invoked when the current
| |
| channelShutdown | back to summary |
|---|---|
| public void channelShutdown(ChannelHandlerContext ctx, ChannelShutdownDirection direction) Overrides default io. Doc from io. The
| |
| configurePipeline | back 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.
| |
| fireBufferedMessages | back to summary |
|---|---|
| private void fireBufferedMessages() Process all backlog into pipeline from List. | |
| handlerAdded | back to summary |
|---|---|
| public void handlerAdded(ChannelHandlerContext ctx) throws Exception Overrides default io. Doc from io. Gets called after the
| |
| handlerRemoved | back to summary |
|---|---|
| public void handlerRemoved(ChannelHandlerContext ctx) throws Exception Overrides default io. Doc from io. Gets called after the
| |
| handshakeFailure | back to summary |
|---|---|
| protected void handshakeFailure(ChannelHandlerContext ctx, Throwable cause) throws Exception Invoked on failed initial SSL/TLS handshake. | |
| removeSelfIfPresent | back to summary |
|---|---|
| private void removeSelfIfPresent(ChannelHandlerContext ctx) | |