我有以下服务器,它接受传入连接以及随后对该连接的请求。但我收到以下错误: io.netty.handler.ssl.NotSslRecordException:不是 SSL/TLS 记录:4a524d4900024
令人困惑的一点:它并不能解决所有问题!好像是随机的。
有时还有那个: **[pool-8-thread-1] 错误 io.netty.util.ResourceLeakDetector - 泄漏:在垃圾收集之前未调用 ByteBuf.release()。请参阅 https://netty.io/wiki/reference-counted-objects.html 了解最近访问记录中的更多信息:
创建于: io.netty.buffer.PooledByteBufAllocator.newDirectBuffer(PooledByteBufAllocator.java)** ...
没有 SSLContext,一切正常。那里出了什么问题?
import com.ibm.crypto.provider.RACFInputStream;
import com.ibm.mq.MQException;
import java.io.File;
import java.io.InputStream;
import java.net.InetSocketAddress;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.cert.CertificateException;
import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLException;
import javax.net.ssl.SSLHandshakeException;
import javax.net.ssl.TrustManagerFactory;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.handler.logging.ByteBufFormat;
import io.netty.handler.logging.LogLevel;
import io.netty.handler.logging.LoggingHandler;
import io.netty.handler.ssl.SslContext;
import io.netty.handler.ssl.SslContextBuilder;
import io.netty.handler.traffic.ChannelTrafficShapingHandler;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class DxlServer
{
private final static String KEY_STORE = "JCERACFKS";
private final static String RACF_USER_ID = "RACFUSER";
private final static String RING = "KEYRING";
private final static String CERT_TYPE = "IbmX509";
private final int port;
private final String mqManagerName;
private final String requestQueueName;
private final String modelQueueName;
private final int millisecondsBeforeQuiesce;
private static DxlServer server = null;
private EventLoopGroup dispatcher = null;
private EventLoopGroup children = null;
boolean shuttingDown = false;
public DxlServer(String[] args) {
try {
port = Integer.parseInt(args[0]);
} catch (NumberFormatException nfe) {
println("bad port number: " + args[0]);
throw nfe;
}
mqManagerName = args[1];
requestQueueName = args[2];
modelQueueName = args[3];
if (args.length == 3 || args[4].equals("0")) {
millisecondsBeforeQuiesce = QUIESCE_INTERVAL;
} else {
try {
millisecondsBeforeQuiesce = Integer.parseInt(args[4]);
} catch (NumberFormatException nfe) {
println("bad millis-before-quiesce: " + args[4]);
throw nfe;
}
}
}
public static void main( String[] args ) throws Exception
{
if (!checkSyntax(args)) {
return;
}
server = new DxlServer(args);
server.start();
}
private static boolean checkSyntax(String[] args) throws Exception {
if (args.length != 4 && args.length != 5) {
String errMsg = "Usage: " + DxlServer.class.getSimpleName() +
" <port> <mqmanagername> <requestqueuename> <modelqueuename> [<millis-before-quiesce>]";
System.err.println(errMsg);
throw new Exception("Missing Arguments:\n" + errMsg);
// return false;
}
return true;
}
private void start() throws InterruptedException {
MqAssembly mqAsm;
try {
mqAsm = new MqAssembly(mqManagerName, requestQueueName, modelQueueName);
} catch (MQException e) {
// TODO: Logging
e.printStackTrace();
return;
}
if (VERBOSE) {
println("dxl server starting to listen at port " + port);
}
dispatcher = new NioEventLoopGroup(1);
children = new NioEventLoopGroup();
try {
KeyStore ks = KeyStore.getInstance(KEY_STORE);
// IBM SSL specifics BEGIN>>>
InputStream inputStream = new RACFInputStream(
RACF_USER_ID, RING, null);
// IBM SSL specifics <<<END
ks.load(inputStream, null);
KeyManagerFactory kmf = KeyManagerFactory.getInstance(CERT_TYPE);
kmf.init(ks, null);
SslContext sslCtx = SslContextBuilder.forServer(kmf).build();
ServerBootstrap b = new ServerBootstrap();
b.group(dispatcher, children)
.channel(NioServerSocketChannel.class)
.localAddress(new InetSocketAddress(port))
.childHandler(new ChannelInitializer<SocketChannel>() {
@Override
public void initChannel(SocketChannel ch) throws Exception {
ch.pipeline().addLast(new LoggingHandler(Logger.class, LogLevel.INFO, ByteBufFormat.HEX_DUMP));
ch.pipeline().addLast("ssl", sslCtx.newHandler(ch.alloc()));
ch.pipeline().addLast(new ChannelTrafficShapingHandler(200));
ch.pipeline().addLast(new DxlVarlengthDecoder(MAX_PAYLOAD_LENGTH));
ch.pipeline().addLast(new MqSession(mqAsm, millisecondsBeforeQuiesce));
}
});
ChannelFuture f = b.bind().sync();
f.channel().closeFuture().sync();
} catch (KeyStoreException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
shutdown();
}
}
public void shutdown() throws InterruptedException {
if (shuttingDown) {
return;
}
shuttingDown = true;
dispatcher.shutdownGracefully().sync();
//children
children.shutdownGracefully().sync();
}
}
我正在尝试不使用 SSLContext,一切正常。我已经注释掉了ChannelTrafficShapingHandler,但没有任何效果。