From f76479fb99c168e6129a1173aa2ef0126a4c131c Mon Sep 17 00:00:00 2001 From: tinexw Date: Thu, 5 Oct 2017 22:15:11 +0200 Subject: [PATCH] Log context path at startup See gh-10544 --- .../boot/web/embedded/jetty/JettyWebServer.java | 14 +++++++++++++- .../boot/web/embedded/tomcat/TomcatWebServer.java | 13 ++++++++++++- .../undertow/UndertowServletWebServer.java | 4 +++- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/JettyWebServer.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/JettyWebServer.java index 5d92fc79c2..931fa5adb5 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/JettyWebServer.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/JettyWebServer.java @@ -17,7 +17,9 @@ package org.springframework.boot.web.embedded.jetty; import java.net.BindException; +import java.util.Arrays; import java.util.List; +import java.util.stream.Collectors; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -25,6 +27,7 @@ import org.eclipse.jetty.server.Connector; import org.eclipse.jetty.server.Handler; import org.eclipse.jetty.server.NetworkConnector; import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.server.handler.ContextHandler; import org.eclipse.jetty.server.handler.HandlerCollection; import org.eclipse.jetty.server.handler.HandlerWrapper; import org.eclipse.jetty.util.component.AbstractLifeCycle; @@ -44,6 +47,7 @@ import org.springframework.util.StringUtils; * @author David Liu * @author Eddú Meléndez * @author Brian Clozel + * @author Kristine Jetzke * @since 2.0.0 * @see JettyReactiveWebServerFactory */ @@ -151,7 +155,8 @@ public class JettyWebServer implements WebServer { } this.started = true; JettyWebServer.logger - .info("Jetty started on port(s) " + getActualPortsDescription()); + .info("Jetty started on port(s) " + getActualPortsDescription() + + " with context path " + getContextPath()); } catch (WebServerException ex) { throw ex; @@ -190,6 +195,13 @@ public class JettyWebServer implements WebServer { return " (" + StringUtils.collectionToDelimitedString(protocols, ", ") + ")"; } + private String getContextPath() { + return Arrays.stream(this.server.getHandlers()) + .filter(ContextHandler.class::isInstance) + .map(handler -> ((ContextHandler) handler).getContextPath()) + .collect(Collectors.joining(" ")); + } + private void handleDeferredInitialize(Handler... handlers) throws Exception { for (Handler handler : handlers) { if (handler instanceof JettyEmbeddedWebAppContext) { diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/TomcatWebServer.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/TomcatWebServer.java index 019f11b2d1..33942f070a 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/TomcatWebServer.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/TomcatWebServer.java @@ -16,9 +16,11 @@ package org.springframework.boot.web.embedded.tomcat; +import java.util.Arrays; import java.util.HashMap; import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; +import java.util.stream.Collectors; import javax.naming.NamingException; @@ -43,6 +45,7 @@ import org.springframework.util.Assert; * should be created using the {@link TomcatReactiveWebServerFactory} and not directly. * * @author Brian Clozel + * @author Kristine Jetzke * @since 2.0.0 */ public class TomcatWebServer implements WebServer { @@ -191,7 +194,8 @@ public class TomcatWebServer implements WebServer { checkThatConnectorsHaveStarted(); this.started = true; TomcatWebServer.logger - .info("Tomcat started on port(s): " + getPortsDescription(true)); + .info("Tomcat started on port(s): " + getPortsDescription(true) + + " with context path " + getContextPath()); } catch (ConnectorStartFailedException ex) { stopSilently(); @@ -322,6 +326,13 @@ public class TomcatWebServer implements WebServer { return 0; } + private String getContextPath() { + return Arrays.stream(this.tomcat.getHost().findChildren()) + .filter(TomcatEmbeddedContext.class::isInstance) + .map(context -> ((TomcatEmbeddedContext) context).getPath()) + .collect(Collectors.joining(" ")); + } + /** * Returns access to the underlying Tomcat server. * @return the Tomcat server diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/UndertowServletWebServer.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/UndertowServletWebServer.java index a48b973416..518ef52f00 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/UndertowServletWebServer.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/UndertowServletWebServer.java @@ -62,6 +62,7 @@ import org.springframework.util.StringUtils; * @author Andy Wilkinson * @author Eddú Meléndez * @author Christoph Dreis + * @author Kristine Jetzke * @since 2.0.0 * @see UndertowServletWebServerFactory */ @@ -156,7 +157,8 @@ public class UndertowServletWebServer implements WebServer { this.undertow.start(); this.started = true; UndertowServletWebServer.logger - .info("Undertow started on port(s) " + getPortsDescription()); + .info("Undertow started on port(s) " + getPortsDescription() + + " with context path " + this.contextPath); } catch (Exception ex) { try {