OptionalSslHandler Class — netty Architecture
Architecture documentation for the OptionalSslHandler class in OptionalSslHandler.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 18d476fe_9be9_0c53_8989_4e0784f98ac4["OptionalSslHandler"] 43d1db2a_aab3_3d9b_8134_1a5717ed60b0["OptionalSslHandler.java"] 18d476fe_9be9_0c53_8989_4e0784f98ac4 -->|defined in| 43d1db2a_aab3_3d9b_8134_1a5717ed60b0 fe84abc0_26ed_eca8_0dec_2090d4b56e6b["OptionalSslHandler()"] 18d476fe_9be9_0c53_8989_4e0784f98ac4 -->|method| fe84abc0_26ed_eca8_0dec_2090d4b56e6b 7f38a5c8_bb25_873f_69ff_5f0e8badd744["decode()"] 18d476fe_9be9_0c53_8989_4e0784f98ac4 -->|method| 7f38a5c8_bb25_873f_69ff_5f0e8badd744 d7229944_6e31_dc15_3ef2_d31179ce99ce["handleSsl()"] 18d476fe_9be9_0c53_8989_4e0784f98ac4 -->|method| d7229944_6e31_dc15_3ef2_d31179ce99ce 7f7f86e6_fd96_a0aa_060a_dd6c81c8318f["handleNonSsl()"] 18d476fe_9be9_0c53_8989_4e0784f98ac4 -->|method| 7f7f86e6_fd96_a0aa_060a_dd6c81c8318f 24c069d5_c60b_ffae_f297_dc42d2162b3d["String()"] 18d476fe_9be9_0c53_8989_4e0784f98ac4 -->|method| 24c069d5_c60b_ffae_f297_dc42d2162b3d a471cff4_9383_4212_a038_e79d4502e12f["SslHandler()"] 18d476fe_9be9_0c53_8989_4e0784f98ac4 -->|method| a471cff4_9383_4212_a038_e79d4502e12f 056fdeb1_a3cf_965d_c313_c9caa19a7f67["ChannelHandler()"] 18d476fe_9be9_0c53_8989_4e0784f98ac4 -->|method| 056fdeb1_a3cf_965d_c313_c9caa19a7f67
Relationship Graph
Source Code
handler/src/main/java/io/netty/handler/ssl/OptionalSslHandler.java lines 34–117
public class OptionalSslHandler extends ByteToMessageDecoder {
private final SslContext sslContext;
public OptionalSslHandler(SslContext sslContext) {
this.sslContext = ObjectUtil.checkNotNull(sslContext, "sslContext");
}
@Override
protected void decode(ChannelHandlerContext context, ByteBuf in, List<Object> out) throws Exception {
if (in.readableBytes() < SslUtils.SSL_RECORD_HEADER_LENGTH) {
return;
}
if (SslHandler.isEncrypted(in, false)) {
handleSsl(context);
} else {
handleNonSsl(context);
}
}
private void handleSsl(ChannelHandlerContext context) {
SslHandler sslHandler = null;
try {
sslHandler = newSslHandler(context, sslContext);
context.pipeline().replace(this, newSslHandlerName(), sslHandler);
sslHandler = null;
} finally {
// Since the SslHandler was not inserted into the pipeline the ownership of the SSLEngine was not
// transferred to the SslHandler.
if (sslHandler != null) {
ReferenceCountUtil.safeRelease(sslHandler.engine());
}
}
}
private void handleNonSsl(ChannelHandlerContext context) {
ChannelHandler handler = newNonSslHandler(context);
if (handler != null) {
context.pipeline().replace(this, newNonSslHandlerName(), handler);
} else {
context.pipeline().remove(this);
}
}
/**
* Optionally specify the SSL handler name, this method may return {@code null}.
* @return the name of the SSL handler.
*/
protected String newSslHandlerName() {
return null;
}
/**
* Override to configure the SslHandler eg. {@link SSLParameters#setEndpointIdentificationAlgorithm(String)}.
* The hostname and port is not known by this method so servers may want to override this method and use the
* {@link SslContext#newHandler(ByteBufAllocator, String, int)} variant.
*
* @param context the {@link ChannelHandlerContext} to use.
* @param sslContext the {@link SSLContext} to use.
* @return the {@link SslHandler} which will replace the {@link OptionalSslHandler} in the pipeline if the
* traffic is SSL.
*/
protected SslHandler newSslHandler(ChannelHandlerContext context, SslContext sslContext) {
return sslContext.newHandler(context.alloc());
}
/**
* Optionally specify the non-SSL handler name, this method may return {@code null}.
* @return the name of the non-SSL handler.
*/
protected String newNonSslHandlerName() {
return null;
}
/**
* Override to configure the ChannelHandler.
* @param context the {@link ChannelHandlerContext} to use.
* @return the {@link ChannelHandler} which will replace the {@link OptionalSslHandler} in the pipeline
* or {@code null} to simply remove the {@link OptionalSslHandler} if the traffic is non-SSL.
*/
protected ChannelHandler newNonSslHandler(ChannelHandlerContext context) {
Source
Frequently Asked Questions
What is the OptionalSslHandler class?
OptionalSslHandler is a class in the netty codebase, defined in handler/src/main/java/io/netty/handler/ssl/OptionalSslHandler.java.
Where is OptionalSslHandler defined?
OptionalSslHandler is defined in handler/src/main/java/io/netty/handler/ssl/OptionalSslHandler.java at line 34.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free