Commit 84305825 authored by Phillip Webb's avatar Phillip Webb

Throw EmbeddedContainerExceptions from Tomcat

Wrap Tomcat start errors in EmbeddedContainerException.

Fixes gh-4204
parent 5a84c02b
......@@ -146,18 +146,24 @@ public class TomcatEmbeddedServletContainer implements EmbeddedServletContainer
@Override
public void start() throws EmbeddedServletContainerException {
addPreviouslyRemovedConnectors();
Connector connector = this.tomcat.getConnector();
if (connector != null && this.autoStart) {
startConnector(connector);
try {
addPreviouslyRemovedConnectors();
Connector connector = this.tomcat.getConnector();
if (connector != null && this.autoStart) {
startConnector(connector);
}
// Ensure process isn't left running if it actually failed to start
if (connectorsHaveFailedToStart()) {
stopSilently();
throw new IllegalStateException("Tomcat connector in failed state");
}
TomcatEmbeddedServletContainer.logger
.info("Tomcat started on port(s): " + getPortsDescription(true));
}
// Ensure process isn't left running if it actually failed to start
if (connectorsHaveFailedToStart()) {
stopSilently();
throw new IllegalStateException("Tomcat connector in failed state");
catch (Exception ex) {
throw new EmbeddedServletContainerException(
"Unable to start embedded Tomcat servlet container", ex);
}
TomcatEmbeddedServletContainer.logger
.info("Tomcat started on port(s): " + getPortsDescription(true));
}
private boolean connectorsHaveFailedToStart() {
......
......@@ -41,6 +41,7 @@ import org.apache.coyote.http11.AbstractHttp11JsseProtocol;
import org.junit.Test;
import org.mockito.InOrder;
import org.springframework.boot.context.embedded.AbstractEmbeddedServletContainerFactoryTests;
import org.springframework.boot.context.embedded.EmbeddedServletContainerException;
import org.springframework.boot.context.embedded.Ssl;
import org.springframework.util.SocketUtils;
......@@ -278,7 +279,7 @@ public class TomcatEmbeddedServletContainerFactoryTests
TomcatEmbeddedServletContainerFactoryTests.this.container.start();
fail();
}
catch (IllegalStateException ex) {
catch (EmbeddedServletContainerException ex) {
// Ignore
}
}
......@@ -308,7 +309,7 @@ public class TomcatEmbeddedServletContainerFactoryTests
TomcatEmbeddedServletContainerFactoryTests.this.container.start();
fail();
}
catch (IllegalStateException ex) {
catch (EmbeddedServletContainerException ex) {
// Ignore
}
}
......@@ -382,7 +383,6 @@ public class TomcatEmbeddedServletContainerFactoryTests
private void doWithBlockedPort(final int port, Runnable action) throws IOException {
ServerSocket serverSocket = new ServerSocket();
serverSocket.bind(new InetSocketAddress(port));
try {
action.run();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment