Log all configured connectors when Tomcat is initialized
Previously, Tomcat initialization would only log the port of the primary connector and would omit the scheme, whereas once Tomcat was started the port of every connector and their schemes would be logged. This commit makes things symmetrical by updating the logging performed at initialization to include every connector's port and scheme. During initialization the port number that the connector the has been configured with is logged. This means that, if the connector has been configured to bind to an free port, 0 will be logged. Once Tomcat has started, the number of the port that the connector has bound to is logged. Closes gh-1601
This commit is contained in:
parent
7434d53369
commit
ef8472a951
|
|
@ -75,6 +75,8 @@ public class TomcatEmbeddedServletContainer implements EmbeddedServletContainer
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void initialize() throws EmbeddedServletContainerException {
|
private synchronized void initialize() throws EmbeddedServletContainerException {
|
||||||
|
this.logger.info("Tomcat initialized with port(s): "
|
||||||
|
+ getConfiguredPortsDescription());
|
||||||
try {
|
try {
|
||||||
addInstanceIdToEngineName();
|
addInstanceIdToEngineName();
|
||||||
|
|
||||||
|
|
@ -97,6 +99,15 @@ public class TomcatEmbeddedServletContainer implements EmbeddedServletContainer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getConfiguredPortsDescription() {
|
||||||
|
StringBuilder ports = new StringBuilder();
|
||||||
|
for (Connector connector : this.tomcat.getService().findConnectors()) {
|
||||||
|
ports.append(ports.length() == 0 ? "" : " ");
|
||||||
|
ports.append(connector.getPort() + "/" + connector.getScheme());
|
||||||
|
}
|
||||||
|
return ports.toString();
|
||||||
|
}
|
||||||
|
|
||||||
private void addInstanceIdToEngineName() {
|
private void addInstanceIdToEngineName() {
|
||||||
int instanceId = containerCounter.incrementAndGet();
|
int instanceId = containerCounter.incrementAndGet();
|
||||||
if (instanceId > 0) {
|
if (instanceId > 0) {
|
||||||
|
|
@ -153,6 +164,8 @@ public class TomcatEmbeddedServletContainer implements EmbeddedServletContainer
|
||||||
stopSilently();
|
stopSilently();
|
||||||
throw new IllegalStateException("Tomcat connector in failed state");
|
throw new IllegalStateException("Tomcat connector in failed state");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.logger.info("Tomcat started on port(s): " + getActualPortsDescription());
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean connectorsHaveFailedToStart() {
|
private boolean connectorsHaveFailedToStart() {
|
||||||
|
|
@ -204,7 +217,6 @@ public class TomcatEmbeddedServletContainer implements EmbeddedServletContainer
|
||||||
((TomcatEmbeddedContext) child).deferredLoadOnStartup();
|
((TomcatEmbeddedContext) child).deferredLoadOnStartup();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
logPorts();
|
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
this.logger.error("Cannot start connector: ", ex);
|
this.logger.error("Cannot start connector: ", ex);
|
||||||
|
|
@ -217,14 +229,13 @@ public class TomcatEmbeddedServletContainer implements EmbeddedServletContainer
|
||||||
return this.serviceConnectors;
|
return this.serviceConnectors;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void logPorts() {
|
private String getActualPortsDescription() {
|
||||||
StringBuilder ports = new StringBuilder();
|
StringBuilder ports = new StringBuilder();
|
||||||
for (Connector additionalConnector : this.tomcat.getService().findConnectors()) {
|
for (Connector connector : this.tomcat.getService().findConnectors()) {
|
||||||
ports.append(ports.length() == 0 ? "" : " ");
|
ports.append(ports.length() == 0 ? "" : " ");
|
||||||
ports.append(additionalConnector.getLocalPort() + "/"
|
ports.append(connector.getLocalPort() + "/" + connector.getScheme());
|
||||||
+ additionalConnector.getScheme());
|
|
||||||
}
|
}
|
||||||
this.logger.info("Tomcat started on port(s): " + ports.toString());
|
return ports.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -149,7 +149,6 @@ public class TomcatEmbeddedServletContainerFactory extends
|
||||||
}
|
}
|
||||||
|
|
||||||
prepareContext(tomcat.getHost(), initializers);
|
prepareContext(tomcat.getHost(), initializers);
|
||||||
this.logger.info("Server initialized with port: " + getPort());
|
|
||||||
return getTomcatEmbeddedServletContainer(tomcat);
|
return getTomcatEmbeddedServletContainer(tomcat);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue