From 0f01729b27e1cdfa37a871e6d10e9d9027c683f0 Mon Sep 17 00:00:00 2001 From: Sebastien Deleuze Date: Mon, 4 Jul 2016 09:52:39 +0200 Subject: [PATCH] Allow to configure Tomcat baseDir This commit also set Tomcat baseDir to java.io.tmpdir for integration tests in order to avoid creation of temporary directories in the project root. --- .../server/reactive/boot/TomcatHttpServer.java | 15 +++++++++++++-- .../AbstractHttpHandlerIntegrationTests.java | 5 ++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/boot/TomcatHttpServer.java b/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/boot/TomcatHttpServer.java index d0170d890b..acbb4568d3 100644 --- a/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/boot/TomcatHttpServer.java +++ b/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/boot/TomcatHttpServer.java @@ -20,13 +20,11 @@ import java.io.File; import org.apache.catalina.Context; import org.apache.catalina.LifecycleException; -import org.apache.catalina.core.StandardHost; import org.apache.catalina.startup.Tomcat; import org.springframework.beans.factory.InitializingBean; import org.springframework.http.server.reactive.ServletHttpHandlerAdapter; import org.springframework.util.Assert; -import org.springframework.util.SocketUtils; /** @@ -38,6 +36,16 @@ public class TomcatHttpServer extends HttpServerSupport implements InitializingB private boolean running; + private String baseDir; + + + public TomcatHttpServer() { + } + + public TomcatHttpServer(String baseDir) { + this.baseDir = baseDir; + } + @Override public boolean isRunning() { @@ -48,6 +56,9 @@ public class TomcatHttpServer extends HttpServerSupport implements InitializingB public void afterPropertiesSet() throws Exception { this.tomcatServer = new Tomcat(); + if (this.baseDir != null) { + this.tomcatServer.setBaseDir(baseDir); + } this.tomcatServer.setHostname(getHost()); this.tomcatServer.setPort(getPort()); diff --git a/spring-web-reactive/src/test/java/org/springframework/http/server/reactive/AbstractHttpHandlerIntegrationTests.java b/spring-web-reactive/src/test/java/org/springframework/http/server/reactive/AbstractHttpHandlerIntegrationTests.java index 83781e29f9..4a2b94e2db 100644 --- a/spring-web-reactive/src/test/java/org/springframework/http/server/reactive/AbstractHttpHandlerIntegrationTests.java +++ b/spring-web-reactive/src/test/java/org/springframework/http/server/reactive/AbstractHttpHandlerIntegrationTests.java @@ -16,6 +16,8 @@ package org.springframework.http.server.reactive; +import java.io.File; + import org.junit.After; import org.junit.Before; import org.junit.runner.RunWith; @@ -41,11 +43,12 @@ public abstract class AbstractHttpHandlerIntegrationTests { @Parameterized.Parameters(name = "server [{0}]") public static Object[][] arguments() { + File base = new File(System.getProperty("java.io.tmpdir")); return new Object[][] { {new JettyHttpServer()}, {new RxNettyHttpServer()}, {new ReactorHttpServer()}, - {new TomcatHttpServer()}, + {new TomcatHttpServer(base.getAbsolutePath())}, {new UndertowHttpServer()} }; }