|
|
@ -19,6 +19,11 @@ package org.springframework.boot.context.embedded.undertow;
|
|
|
|
import io.undertow.Undertow;
|
|
|
|
import io.undertow.Undertow;
|
|
|
|
import io.undertow.Undertow.Builder;
|
|
|
|
import io.undertow.Undertow.Builder;
|
|
|
|
import io.undertow.UndertowMessages;
|
|
|
|
import io.undertow.UndertowMessages;
|
|
|
|
|
|
|
|
import io.undertow.server.HandlerWrapper;
|
|
|
|
|
|
|
|
import io.undertow.server.HttpHandler;
|
|
|
|
|
|
|
|
import io.undertow.server.handlers.accesslog.AccessLogHandler;
|
|
|
|
|
|
|
|
import io.undertow.server.handlers.accesslog.AccessLogReceiver;
|
|
|
|
|
|
|
|
import io.undertow.server.handlers.accesslog.DefaultAccessLogReceiver;
|
|
|
|
import io.undertow.server.handlers.resource.ClassPathResourceManager;
|
|
|
|
import io.undertow.server.handlers.resource.ClassPathResourceManager;
|
|
|
|
import io.undertow.server.handlers.resource.FileResourceManager;
|
|
|
|
import io.undertow.server.handlers.resource.FileResourceManager;
|
|
|
|
import io.undertow.server.handlers.resource.Resource;
|
|
|
|
import io.undertow.server.handlers.resource.Resource;
|
|
|
@ -69,8 +74,11 @@ import org.springframework.context.ResourceLoaderAware;
|
|
|
|
import org.springframework.core.io.ResourceLoader;
|
|
|
|
import org.springframework.core.io.ResourceLoader;
|
|
|
|
import org.springframework.util.Assert;
|
|
|
|
import org.springframework.util.Assert;
|
|
|
|
import org.springframework.util.ResourceUtils;
|
|
|
|
import org.springframework.util.ResourceUtils;
|
|
|
|
|
|
|
|
import org.xnio.OptionMap;
|
|
|
|
import org.xnio.Options;
|
|
|
|
import org.xnio.Options;
|
|
|
|
import org.xnio.SslClientAuthMode;
|
|
|
|
import org.xnio.SslClientAuthMode;
|
|
|
|
|
|
|
|
import org.xnio.Xnio;
|
|
|
|
|
|
|
|
import org.xnio.XnioWorker;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* {@link EmbeddedServletContainerFactory} that can be used to create
|
|
|
|
* {@link EmbeddedServletContainerFactory} that can be used to create
|
|
|
@ -81,6 +89,7 @@ import org.xnio.SslClientAuthMode;
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @author Ivan Sopov
|
|
|
|
* @author Ivan Sopov
|
|
|
|
* @author Andy Wilkinson
|
|
|
|
* @author Andy Wilkinson
|
|
|
|
|
|
|
|
* @author Marcos Barbero
|
|
|
|
* @since 1.2.0
|
|
|
|
* @since 1.2.0
|
|
|
|
* @see UndertowEmbeddedServletContainer
|
|
|
|
* @see UndertowEmbeddedServletContainer
|
|
|
|
*/
|
|
|
|
*/
|
|
|
@ -105,6 +114,12 @@ public class UndertowEmbeddedServletContainerFactory extends
|
|
|
|
|
|
|
|
|
|
|
|
private Boolean directBuffers;
|
|
|
|
private Boolean directBuffers;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private File accessLogDirectory;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String accessLogPattern;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private boolean accessLogEnabled = false;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Create a new {@link UndertowEmbeddedServletContainerFactory} instance.
|
|
|
|
* Create a new {@link UndertowEmbeddedServletContainerFactory} instance.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
@ -337,6 +352,9 @@ public class UndertowEmbeddedServletContainerFactory extends
|
|
|
|
for (UndertowDeploymentInfoCustomizer customizer : this.deploymentInfoCustomizers) {
|
|
|
|
for (UndertowDeploymentInfoCustomizer customizer : this.deploymentInfoCustomizers) {
|
|
|
|
customizer.customize(deployment);
|
|
|
|
customizer.customize(deployment);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isAccessLogEnabled()) {
|
|
|
|
|
|
|
|
configureAccessLog(deployment);
|
|
|
|
|
|
|
|
}
|
|
|
|
DeploymentManager manager = Servlets.defaultContainer().addDeployment(deployment);
|
|
|
|
DeploymentManager manager = Servlets.defaultContainer().addDeployment(deployment);
|
|
|
|
manager.deploy();
|
|
|
|
manager.deploy();
|
|
|
|
SessionManager sessionManager = manager.getDeployment().getSessionManager();
|
|
|
|
SessionManager sessionManager = manager.getDeployment().getSessionManager();
|
|
|
@ -345,6 +363,44 @@ public class UndertowEmbeddedServletContainerFactory extends
|
|
|
|
return manager;
|
|
|
|
return manager;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void configureAccessLog(DeploymentInfo deploymentInfo) {
|
|
|
|
|
|
|
|
deploymentInfo.addInitialHandlerChainWrapper(new HandlerWrapper() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public HttpHandler wrap(HttpHandler handler) {
|
|
|
|
|
|
|
|
return createAccessLogHandler(handler);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private AccessLogHandler createAccessLogHandler(HttpHandler handler) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
createAccessLogDirectoryIfNecessary();
|
|
|
|
|
|
|
|
AccessLogReceiver accessLogReceiver = new DefaultAccessLogReceiver(
|
|
|
|
|
|
|
|
createWorker(), this.accessLogDirectory, "access_log");
|
|
|
|
|
|
|
|
String formatString = (this.accessLogPattern != null) ? this.accessLogPattern
|
|
|
|
|
|
|
|
: "common";
|
|
|
|
|
|
|
|
return new AccessLogHandler(handler, accessLogReceiver, formatString,
|
|
|
|
|
|
|
|
Undertow.class.getClassLoader());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (IOException ex) {
|
|
|
|
|
|
|
|
throw new IllegalStateException("Failed to create AccessLogHandler", ex);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void createAccessLogDirectoryIfNecessary() {
|
|
|
|
|
|
|
|
Assert.notNull(this.accessLogDirectory, "accesslogDirectory must not be null");
|
|
|
|
|
|
|
|
if (!this.accessLogDirectory.isDirectory() && !this.accessLogDirectory.mkdirs()) {
|
|
|
|
|
|
|
|
throw new IllegalStateException("Failed to create access log directory '"
|
|
|
|
|
|
|
|
+ this.accessLogDirectory + "'");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private XnioWorker createWorker() throws IOException {
|
|
|
|
|
|
|
|
Xnio xnio = Xnio.getInstance(Undertow.class.getClassLoader());
|
|
|
|
|
|
|
|
OptionMap.Builder builder = OptionMap.builder();
|
|
|
|
|
|
|
|
return xnio.createWorker(builder.getMap());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void registerServletContainerInitializerToDriveServletContextInitializers(
|
|
|
|
private void registerServletContainerInitializerToDriveServletContextInitializers(
|
|
|
|
DeploymentInfo deployment, ServletContextInitializer... initializers) {
|
|
|
|
DeploymentInfo deployment, ServletContextInitializer... initializers) {
|
|
|
|
ServletContextInitializer[] mergedInitializers = mergeInitializers(initializers);
|
|
|
|
ServletContextInitializer[] mergedInitializers = mergeInitializers(initializers);
|
|
|
@ -442,6 +498,22 @@ public class UndertowEmbeddedServletContainerFactory extends
|
|
|
|
this.directBuffers = directBuffers;
|
|
|
|
this.directBuffers = directBuffers;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void setAccessLogDirectory(File accessLogDirectory) {
|
|
|
|
|
|
|
|
this.accessLogDirectory = accessLogDirectory;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void setAccessLogPattern(String accessLogPattern) {
|
|
|
|
|
|
|
|
this.accessLogPattern = accessLogPattern;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void setAccessLogEnabled(boolean accessLogEnabled) {
|
|
|
|
|
|
|
|
this.accessLogEnabled = accessLogEnabled;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public boolean isAccessLogEnabled() {
|
|
|
|
|
|
|
|
return this.accessLogEnabled;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Undertow {@link ResourceManager} for JAR resources.
|
|
|
|
* Undertow {@link ResourceManager} for JAR resources.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|