Pregunta

I'm trying to run a Jetty (v9) server using SSL (so that access is through HTTPS only). Everything ran fine using plain HTTP. Then I changed my launcher class so it looks like this:

PropertyConfigurator.configure("war/WEB-INF/log4j.properties");
Server server = new Server();

WebAppContext webapp = new WebAppContext();
webapp.setContextPath("/");
webapp.setWar("war");
server.setHandler(webapp);

HttpConfiguration https = new HttpConfiguration();
https.addCustomizer(new SecureRequestCustomizer());

SslContextFactory sslContextFactory = new SslContextFactory();
sslContextFactory.setKeyStorePath("keystore.jks");
sslContextFactory.setKeyStorePassword("<password>");
sslContextFactory.setKeyManagerPassword("<password>");

ServerConnector sslConnector = new ServerConnector(server,
        new SslConnectionFactory(sslContextFactory, "http/1.1"),
        new HttpConnectionFactory(https));
sslConnector.setPort(443);
server.setConnectors(new Connector[] { sslConnector });

LOG.info("Starting server on port 443");
server.start();
server.join();

I also ran this to generate a keystore file:

keytool -genkey -alias sitename -keyalg RSA -keystore keystore.jks -keysize 2048

When I launch the server now, everything kicks off fine. My logging using log4j (v1.2.17 - and slf4j) outputs to the intended file (as instructed in my log4j.properties) with the above log message. But when I hit the web server in a browser, logging stops working with the following error output to the console:

log4j:ERROR A "org.apache.log4j.RollingFileAppender" object is not assignable to a "org.apache.log4j.Appender" variable.
log4j:ERROR The class "org.apache.log4j.Appender" was loaded by 
log4j:ERROR [sun.misc.Launcher$AppClassLoader@178b0f9] whereas object of type 
log4j:ERROR "org.apache.log4j.RollingFileAppender" was loaded by [WebAppClassLoader=8317419@7ee9eb].
log4j:ERROR Could not instantiate appender named "filer".
log4j:WARN No appenders could be found for logger (ie.search4less.quickbooks.servlet.AppServlet).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

...and this is repeated to the console everytime a servlet handles a new request. Each one of my servlets is initializing log4j using a static block like:

static {
    PropertyConfigurator.configure("war/WEB-INF/log4j.properties");
}

My log4j.properties looks like this:

log4j.rootLogger=INFO, filer

log4j.appender.filer=org.apache.log4j.RollingFileAppender
log4j.appender.filer.layout=org.apache.log4j.PatternLayout
log4j.appender.filer.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-4r [%t] %-5p %c %x - %m%n
log4j.appender.filer.File=./logs/quickbooks.log
log4j.appender.filer.MaxFileSize=1MB
log4j.appender.filer.MaxBackupIndex=9
log4j.appender.filer.append=true

As I said, everything worked fine until I added the new SSL configuration code to the server launcher class, but I don't understand what's going wrong.

¿Fue útil?

Solución

I got it working. The problem was actually nothing to do with SSL configuration at all. Between adding those SSL config changes, I had moved a lib directory into WEB-INF that contained all my dependencies (including the log4j and slf4j jars). That was causing some kind of conflict. Removing them from there solved it.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top