ApplicationProtocolNegotiationHandler failure behavior

Motivation:
Child classes of ApplicationProtocolNegotiationHandler may want to override the behavior when a handshake failure is detected.

Modifications:
- Provide a method which can be overriden when a handshake failure is detected.

Result:
Child classes can override ApplicationProtocolNegotiationHandler handshake failure behavior.
This commit is contained in:
Scott Mitchell 2015-11-04 11:20:12 -08:00
parent 60a240316a
commit 6e66b542a9

View File

@ -99,8 +99,7 @@ public abstract class ApplicationProtocolNegotiationHandler extends ChannelInbou
String protocol = sslHandler.applicationProtocol(); String protocol = sslHandler.applicationProtocol();
configurePipeline(ctx, protocol != null? protocol : fallbackProtocol); configurePipeline(ctx, protocol != null? protocol : fallbackProtocol);
} else { } else {
logger.warn("{} TLS handshake failed:", ctx.channel(), handshakeEvent.cause()); handshakeFailure(ctx, handshakeEvent.cause());
ctx.close();
} }
} }
@ -117,6 +116,14 @@ public abstract class ApplicationProtocolNegotiationHandler extends ChannelInbou
*/ */
protected abstract void configurePipeline(ChannelHandlerContext ctx, String protocol) throws Exception; protected abstract void configurePipeline(ChannelHandlerContext ctx, String protocol) throws Exception;
/**
* Invoked on failed initial SSL/TLS handshake.
*/
protected void handshakeFailure(ChannelHandlerContext ctx, Throwable cause) throws Exception {
logger.warn("{} TLS handshake failed:", ctx.channel(), cause);
ctx.close();
}
@Override @Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
logger.warn("{} Failed to select the application-level protocol:", ctx.channel(), cause); logger.warn("{} Failed to select the application-level protocol:", ctx.channel(), cause);