0

我正在使用带有 OpenJDK 1.7 的 Netty 4.0.11 运行 HTTP 服务器。我正在使用 CentOS 6.3。

当我在命令上使用“java -jar myServer.jar”时,一切正常。但是,当我将它放在服务上时,我得到一个异常说通道无法初始化。

这很奇怪,因为在命令行上一切正常。但是,在服务中,似乎出了点问题。

Nov 07, 2013 4:26:00 PM io.netty.channel.ChannelInitializer channelRegistered
WARNING: Failed to initialize a channel. Closing: [id: 0x921deb84, /14.63.176.113:17319 => /172.27.125.139:1003]
java.lang.NullPointerException
    at server.BookkServerInitializer.initChannel(BookkServerInitializer.java:23)
    at server.BookkServerInitializer.initChannel(BookkServerInitializer.java:18)
    at io.netty.channel.ChannelInitializer.channelRegistered(ChannelInitializer.java:70)
    at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRegistered(DefaultChannelHandlerContext.java:162)
    at io.netty.channel.DefaultChannelHandlerContext.fireChannelRegistered(DefaultChannelHandlerContext.java:148)
    at io.netty.channel.DefaultChannelPipeline.fireChannelRegistered(DefaultChannelPipeline.java:730)
    at io.netty.channel.AbstractChannel$AbstractUnsafe.register0(AbstractChannel.java:442)
    at io.netty.channel.AbstractChannel$AbstractUnsafe.access$100(AbstractChannel.java:374)
    at io.netty.channel.AbstractChannel$AbstractUnsafe$1.run(AbstractChannel.java:418)
    at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:354)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:353)
    at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:101)
    at java.lang.Thread.run(Thread.java:724)

这里是调用异常的地方。

package server;

import handler.BookkServerHandler;
import handler.DeleteConnections;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpContentCompressor;
import io.netty.handler.codec.http.HttpContentDecompressor;
import io.netty.handler.codec.http.HttpServerCodec;
import io.netty.handler.ssl.SslHandler;
import io.netty.handler.timeout.IdleStateHandler;
import util.ssl.ServerSslContext;

import javax.net.ssl.SSLEngine;


class BookkServerInitializer extends ChannelInitializer<SocketChannel> {
    public void initChannel(SocketChannel ch) throws Exception {
        ChannelPipeline pipeline = ch.pipeline();

        if (!System.getProperty("os.name").equals("Windows 7")) {
            SSLEngine engine = ServerSslContext.getInstance().serverContext().createSSLEngine();
            engine.setUseClientMode(false);
            pipeline.addLast("ssl", new SslHandler(engine));
        }

        pipeline.addFirst("connectionDeleter", new DeleteConnections());
        pipeline.addFirst("idleState", new IdleStateHandler(3, 3, 3));
        pipeline.addLast("codec", new HttpServerCodec());
        pipeline.addLast("inflater", new HttpContentDecompressor());
        pipeline.addLast("deflater", new HttpContentCompressor(9, 15, 9));
        pipeline.addLast("handler", new BookkServerHandler());
    }
}

异常日志显示我的 SSLEngine 是问题所在。

我在没有 SSL 的情况下测试了服务器,它可以工作!!!

SSL 与服务发生了什么?

4

1 回答 1

0

通过更改密钥库的目录解决。

我曾经将我的密钥库存储在与 jar 文件相同的目录中。所以我使用了路径“密钥库”。

只需将其更改为“/DirectoryOfTheKeystore/keystore”。有用!!

于 2013-11-07T08:11:00.603 回答