Pom.xml: 若发现找不到对应classifier变量,可以尝试重新编译
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<version>4.1.32.Final</version>
<exclusions>
<exclusion>
<groupId>io.netty</groupId>
<artifactId>netty-tcnative-boringssl-static</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-tcnative-boringssl-static</artifactId>
<version>2.0.20.Final</version>
<classifier>${os.detected.classifier}</classifier>
</dependency>
private boolean initSocketChannel(SocketChannel socketChannel) {
SslContext sslContext = initSSLContext();
if (sslContext == null){
logger.info("sslContext init fail, return.");
return false;
}
SSLEngine sslEngine = sslContext.newEngine(socketChannel.alloc());
sslEngine.setUseClientMode(false);
sslEngine.setNeedClientAuth(false);
SslHandler sslHandler = new SslHandler(sslEngine);
sslHandler.setHandshakeTimeoutMillis(60 * 1000);
socketChannel.pipeline().addFirst("ssl", new SslHandler(sslEngine));
socketChannel.pipeline().addLast(new IdleStateHandler(60, 0, 0, TimeUnit.SECONDS));
ByteBuf delimiter = Unpooled.copiedBuffer("\r\n".getBytes());
socketChannel.pipeline().addLast(new DelimiterBasedFrameDecoder(2048, delimiter));
socketChannel.pipeline().addLast("decode", new StringDecoder());
socketChannel.pipeline().addLast("encode", new StringEncoder());
socketChannel.pipeline().addLast(eventExecutorGroup, new HeartBeatServerHandler());
socketChannel.pipeline().addLast(idleStateTrigger);
return true;
}
private SslContext initSSLContext() {
SslContext sslContext = null;
try {
final Decoder decoder = Base64.getDecoder();
// String pass = new String(decoder.decodeBuffer("MTExMTEx"), "UTF-8");
String pass = new String(decoder.decode("aWRzYmcxMjMu"), "UTF-8");
KeyStore ks = KeyStore.getInstance(Util.SSL_JKS);
InputStream ksInputStream = HeartBeatServer.class.getResourceAsStream("/server.jks");
ks.load(ksInputStream, pass.toCharArray());
OpenSslCachingX509KeyManagerFactory kmf = new OpenSslCachingX509KeyManagerFactory(KeyManagerFactory.getInstance(Util.SSL_MANAGER_X509));
kmf.init(ks, pass.toCharArray());
sslContext = SslContextBuilder.forServer(kmf).sslProvider(SslProvider.OPENSSL).build();
//SSLContext.getInstance(Util.SSL_VERSION);
//sslContext.init(kmf.getKeyManagers(), null, null);
} catch (Exception e) {
logger.error(e.toString());
}
if (sslContext != null) {
logger.debug("sslContext初始化成功");
}
return sslContext;
}