|
|
@ -44,7 +44,8 @@ import org.springframework.util.Assert;
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public class TomcatEmbeddedServletContainer implements EmbeddedServletContainer {
|
|
|
|
public class TomcatEmbeddedServletContainer implements EmbeddedServletContainer {
|
|
|
|
|
|
|
|
|
|
|
|
private final Log logger = LogFactory.getLog(TomcatEmbeddedServletContainer.class);
|
|
|
|
private static final Log logger = LogFactory
|
|
|
|
|
|
|
|
.getLog(TomcatEmbeddedServletContainer.class);
|
|
|
|
|
|
|
|
|
|
|
|
private static AtomicInteger containerCounter = new AtomicInteger(-1);
|
|
|
|
private static AtomicInteger containerCounter = new AtomicInteger(-1);
|
|
|
|
|
|
|
|
|
|
|
@ -75,8 +76,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): "
|
|
|
|
TomcatEmbeddedServletContainer.logger.info("Tomcat initialized with port(s): "
|
|
|
|
+ getConfiguredPortsDescription());
|
|
|
|
+ getPortsDescription(false));
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
addInstanceIdToEngineName();
|
|
|
|
addInstanceIdToEngineName();
|
|
|
|
|
|
|
|
|
|
|
@ -99,15 +100,6 @@ 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) {
|
|
|
@ -157,15 +149,13 @@ public class TomcatEmbeddedServletContainer implements EmbeddedServletContainer
|
|
|
|
if (connector != null && this.autoStart) {
|
|
|
|
if (connector != null && this.autoStart) {
|
|
|
|
startConnector(connector);
|
|
|
|
startConnector(connector);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Ensure process isn't left running if it actually failed to start
|
|
|
|
// Ensure process isn't left running if it actually failed to start
|
|
|
|
|
|
|
|
|
|
|
|
if (connectorsHaveFailedToStart()) {
|
|
|
|
if (connectorsHaveFailedToStart()) {
|
|
|
|
stopSilently();
|
|
|
|
stopSilently();
|
|
|
|
throw new IllegalStateException("Tomcat connector in failed state");
|
|
|
|
throw new IllegalStateException("Tomcat connector in failed state");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TomcatEmbeddedServletContainer.logger.info("Tomcat started on port(s): "
|
|
|
|
this.logger.info("Tomcat started on port(s): " + getActualPortsDescription());
|
|
|
|
+ getPortsDescription(true));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private boolean connectorsHaveFailedToStart() {
|
|
|
|
private boolean connectorsHaveFailedToStart() {
|
|
|
@ -206,7 +196,7 @@ public class TomcatEmbeddedServletContainer implements EmbeddedServletContainer
|
|
|
|
connector.getProtocolHandler().stop();
|
|
|
|
connector.getProtocolHandler().stop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception ex) {
|
|
|
|
catch (Exception ex) {
|
|
|
|
this.logger.error("Cannot pause connector: ", ex);
|
|
|
|
TomcatEmbeddedServletContainer.logger.error("Cannot pause connector: ", ex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -219,7 +209,7 @@ public class TomcatEmbeddedServletContainer implements EmbeddedServletContainer
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception ex) {
|
|
|
|
catch (Exception ex) {
|
|
|
|
this.logger.error("Cannot start connector: ", ex);
|
|
|
|
TomcatEmbeddedServletContainer.logger.error("Cannot start connector: ", ex);
|
|
|
|
throw new EmbeddedServletContainerException(
|
|
|
|
throw new EmbeddedServletContainerException(
|
|
|
|
"Unable to start embedded Tomcat connectors", ex);
|
|
|
|
"Unable to start embedded Tomcat connectors", ex);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -229,15 +219,6 @@ public class TomcatEmbeddedServletContainer implements EmbeddedServletContainer
|
|
|
|
return this.serviceConnectors;
|
|
|
|
return this.serviceConnectors;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private String getActualPortsDescription() {
|
|
|
|
|
|
|
|
StringBuilder ports = new StringBuilder();
|
|
|
|
|
|
|
|
for (Connector connector : this.tomcat.getService().findConnectors()) {
|
|
|
|
|
|
|
|
ports.append(ports.length() == 0 ? "" : " ");
|
|
|
|
|
|
|
|
ports.append(connector.getLocalPort() + "/" + connector.getScheme());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return ports.toString();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public synchronized void stop() throws EmbeddedServletContainerException {
|
|
|
|
public synchronized void stop() throws EmbeddedServletContainerException {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
@ -258,6 +239,16 @@ public class TomcatEmbeddedServletContainer implements EmbeddedServletContainer
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String getPortsDescription(boolean localPort) {
|
|
|
|
|
|
|
|
StringBuilder ports = new StringBuilder();
|
|
|
|
|
|
|
|
for (Connector connector : this.tomcat.getService().findConnectors()) {
|
|
|
|
|
|
|
|
ports.append(ports.length() == 0 ? "" : " ");
|
|
|
|
|
|
|
|
int port = (localPort ? connector.getLocalPort() : connector.getPort());
|
|
|
|
|
|
|
|
ports.append(port + " (" + connector.getScheme() + ")");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return ports.toString();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public int getPort() {
|
|
|
|
public int getPort() {
|
|
|
|
Connector connector = this.tomcat.getConnector();
|
|
|
|
Connector connector = this.tomcat.getConnector();
|
|
|
|