public abstract class ApplicationProtocolNegotiationHandler extends ChannelInboundHandlerAdapter
ChannelPipeline
取决于应用层协议协商结果SslHandler
。
例如,您可以根据ALPN的结果来配置HTTP管道:
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);
}
}
}
ChannelHandler.Sharable
Modifier | Constructor and Description |
---|---|
protected |
ApplicationProtocolNegotiationHandler(java.lang.String fallbackProtocol)
使用指定的回退协议名称创建新实例。
|
Modifier and Type | Method and Description |
---|---|
protected abstract void |
configurePipeline(ChannelHandlerContext ctx, java.lang.String protocol)
调用成功的初始SSL / TLS握手。
|
void |
exceptionCaught(ChannelHandlerContext ctx, java.lang.Throwable cause)
|
protected void |
handshakeFailure(ChannelHandlerContext ctx, java.lang.Throwable cause)
在失败的初始SSL / TLS握手中调用。
|
void |
userEventTriggered(ChannelHandlerContext ctx, java.lang.Object evt)
|
channelActive, channelInactive, channelRead, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged
ensureNotSharable, handlerAdded, handlerRemoved, isSharable
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
handlerAdded, handlerRemoved
protected ApplicationProtocolNegotiationHandler(java.lang.String fallbackProtocol)
fallbackProtocol
- ALPN / NPN协商失败或客户端不支持ALPN / NPN时使用的协议名称
public void userEventTriggered(ChannelHandlerContext ctx, java.lang.Object evt) throws java.lang.Exception
ChannelInboundHandlerAdapter
ChannelHandlerContext.fireUserEventTriggered(Object)
转发到ChannelPipeline
中的下一个ChannelInboundHandler
。
子类可以重写此方法来更改行为。
userEventTriggered
,界面
ChannelInboundHandler
userEventTriggered
ChannelInboundHandlerAdapter
java.lang.Exception
protected abstract void configurePipeline(ChannelHandlerContext ctx, java.lang.String protocol) throws java.lang.Exception
protocol
- 协商失败或客户端不知道ALPN / NPN扩展的协商应用程序级协议的名称或构造函数调用中指定的回退协议名称
java.lang.Exception
protected void handshakeFailure(ChannelHandlerContext ctx, java.lang.Throwable cause) throws java.lang.Exception
java.lang.Exception
public void exceptionCaught(ChannelHandlerContext ctx, java.lang.Throwable cause) throws java.lang.Exception
ChannelInboundHandlerAdapter
ChannelHandlerContext.fireExceptionCaught(Throwable)
转发到ChannelPipeline
中的下一个ChannelHandler
。
子类可以重写此方法来更改行为。
exceptionCaught
在界面
ChannelHandler
exceptionCaught
在界面
ChannelInboundHandler
exceptionCaught
在课堂上
ChannelInboundHandlerAdapter
java.lang.Exception
Copyright © 2008–2018 The Netty Project. All rights reserved.