|
|
|
@ -25,11 +25,14 @@ import java.util.ArrayList;
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
import java.util.Collection;
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
import java.util.EventListener;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
|
|
import javax.servlet.ServletContainerInitializer;
|
|
|
|
|
import javax.servlet.ServletContext;
|
|
|
|
|
import javax.servlet.ServletContextEvent;
|
|
|
|
|
import javax.servlet.ServletContextListener;
|
|
|
|
|
import javax.servlet.ServletException;
|
|
|
|
|
|
|
|
|
|
import io.undertow.Undertow;
|
|
|
|
@ -48,6 +51,7 @@ import io.undertow.server.session.SessionManager;
|
|
|
|
|
import io.undertow.servlet.Servlets;
|
|
|
|
|
import io.undertow.servlet.api.DeploymentInfo;
|
|
|
|
|
import io.undertow.servlet.api.DeploymentManager;
|
|
|
|
|
import io.undertow.servlet.api.ListenerInfo;
|
|
|
|
|
import io.undertow.servlet.api.MimeMapping;
|
|
|
|
|
import io.undertow.servlet.api.ServletContainerInitializerInfo;
|
|
|
|
|
import io.undertow.servlet.api.ServletStackTraces;
|
|
|
|
@ -292,27 +296,35 @@ public class UndertowServletWebServerFactory extends AbstractServletWebServerFac
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void configureAccessLog(DeploymentInfo deploymentInfo) {
|
|
|
|
|
deploymentInfo.addInitialHandlerChainWrapper(this::createAccessLogHandler);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private AccessLogHandler createAccessLogHandler(HttpHandler handler) {
|
|
|
|
|
try {
|
|
|
|
|
createAccessLogDirectoryIfNecessary();
|
|
|
|
|
XnioWorker worker = createWorker();
|
|
|
|
|
String prefix = (this.accessLogPrefix != null ? this.accessLogPrefix
|
|
|
|
|
: "access_log.");
|
|
|
|
|
AccessLogReceiver accessLogReceiver = new DefaultAccessLogReceiver(
|
|
|
|
|
createWorker(), this.accessLogDirectory, prefix, this.accessLogSuffix,
|
|
|
|
|
DefaultAccessLogReceiver accessLogReceiver = new DefaultAccessLogReceiver(
|
|
|
|
|
worker, this.accessLogDirectory, prefix, this.accessLogSuffix,
|
|
|
|
|
this.accessLogRotate);
|
|
|
|
|
String formatString = (this.accessLogPattern != null ? this.accessLogPattern
|
|
|
|
|
: "common");
|
|
|
|
|
return new AccessLogHandler(handler, accessLogReceiver, formatString,
|
|
|
|
|
Undertow.class.getClassLoader());
|
|
|
|
|
EventListener listener = new AccessLogShutdownListener(worker,
|
|
|
|
|
accessLogReceiver);
|
|
|
|
|
deploymentInfo.addListener(new ListenerInfo(AccessLogShutdownListener.class,
|
|
|
|
|
new ImmediateInstanceFactory<EventListener>(listener)));
|
|
|
|
|
deploymentInfo.addInitialHandlerChainWrapper(
|
|
|
|
|
(handler) -> createAccessLogHandler(handler, accessLogReceiver));
|
|
|
|
|
}
|
|
|
|
|
catch (IOException ex) {
|
|
|
|
|
throw new IllegalStateException("Failed to create AccessLogHandler", ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private AccessLogHandler createAccessLogHandler(HttpHandler handler,
|
|
|
|
|
AccessLogReceiver accessLogReceiver) {
|
|
|
|
|
createAccessLogDirectoryIfNecessary();
|
|
|
|
|
String formatString = ((this.accessLogPattern != null) ? this.accessLogPattern
|
|
|
|
|
: "common");
|
|
|
|
|
return new AccessLogHandler(handler, accessLogReceiver, formatString,
|
|
|
|
|
Undertow.class.getClassLoader());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void createAccessLogDirectoryIfNecessary() {
|
|
|
|
|
Assert.state(this.accessLogDirectory != null, "Access log directory is not set");
|
|
|
|
|
if (!this.accessLogDirectory.isDirectory() && !this.accessLogDirectory.mkdirs()) {
|
|
|
|
@ -645,4 +657,33 @@ public class UndertowServletWebServerFactory extends AbstractServletWebServerFac
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static class AccessLogShutdownListener implements ServletContextListener {
|
|
|
|
|
|
|
|
|
|
private final XnioWorker worker;
|
|
|
|
|
|
|
|
|
|
private final DefaultAccessLogReceiver accessLogReceiver;
|
|
|
|
|
|
|
|
|
|
AccessLogShutdownListener(XnioWorker worker,
|
|
|
|
|
DefaultAccessLogReceiver accessLogReceiver) {
|
|
|
|
|
this.worker = worker;
|
|
|
|
|
this.accessLogReceiver = accessLogReceiver;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void contextInitialized(ServletContextEvent sce) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void contextDestroyed(ServletContextEvent sce) {
|
|
|
|
|
try {
|
|
|
|
|
this.accessLogReceiver.close();
|
|
|
|
|
this.worker.shutdown();
|
|
|
|
|
}
|
|
|
|
|
catch (IOException ex) {
|
|
|
|
|
throw new IllegalStateException(ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|