我試圖運行使用SSL的Jetty(v9)服務器(因此只能通過HTTPS訪問)。一切運行正常使用普通的HTTP。然後,我改變了我的啓動類,所以它看起來像這樣:log4j在添加SSL配置後不能與Jetty配合使用
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();
我也跑這生成一個密鑰存儲文件:
keytool -genkey -alias sitename -keyalg RSA -keystore keystore.jks -keysize 2048
現在當我啓動服務器,一切都揭開序幕罰款。我使用log4j(v1.2.17 - 和slf4j)進行日誌記錄輸出到預定文件(按照我的log4j.properties中的指示)並使用上面的日誌消息。但是,當我打的Web服務器在瀏覽器中,記錄停止工作並出現以下錯誤輸出到控制檯:
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 [[email protected]] whereas object of type
log4j:ERROR "org.apache.log4j.RollingFileAppender" was loaded by [[email protected]].
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.
...這是重複控制檯每次一個servlet處理新的請求。我的servlet中的每一個使用靜態塊像初始化log4j的:
static {
PropertyConfigurator.configure("war/WEB-INF/log4j.properties");
}
我log4j.properties看起來是這樣的:
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
正如我所說的,一切正常,直到我加入了新的SSL配置代碼到服務器啓動類,但我不明白髮生了什麼問題。
您的安全數據是否應該記錄? –
我不確定你的意思。無論我使用的是HTTP還是HTTPS,我都想繼續正常記錄。我只是不明白髮生了什麼變化,阻止了我的servlet能夠再次登錄 – RTF