简体   繁体   中英

SSL on service(on CentOS) does not work

I am running a HTTP server using Netty 4.0.11 with OpenJDK 1.7. I am using CentOS 6.3.

Everything works fine when I just use "java -jar myServer.jar" on the command. However, when I put the it on the service, I get an exception saying the channel can't be initialized.

It's strange because, everything works fine on just command line. But, on service, something seems to go wrong.

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)

And here's where the exception is called.

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());
    }
}

The exception log shows that my SSLEngine is where to problem is.

I tested the server without SSL, it works!!!

What's going on with SSL with service??

Solved by changing the directory of the keystore.

I used to store my keystore in the same directroy as the jar file. So i used the path "keystore".

Just change it to "/DirectoryOfTheKeystore/keystore". It works!!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM