Merge branch '1.5.x'

This commit is contained in:
Andy Wilkinson 2017-10-11 16:19:25 +01:00
commit bcfb1d17b1
3 changed files with 51 additions and 16 deletions

View File

@ -159,20 +159,36 @@ public class UndertowServletWebServer implements WebServer {
.info("Undertow started on port(s) " + getPortsDescription());
}
catch (Exception ex) {
if (findBindException(ex) != null) {
List<Port> failedPorts = getConfiguredPorts();
List<Port> actualPorts = getActualPorts();
failedPorts.removeAll(actualPorts);
if (failedPorts.size() == 1) {
throw new PortInUseException(
failedPorts.iterator().next().getNumber());
try {
if (findBindException(ex) != null) {
List<Port> failedPorts = getConfiguredPorts();
List<Port> actualPorts = getActualPorts();
failedPorts.removeAll(actualPorts);
if (failedPorts.size() == 1) {
throw new PortInUseException(
failedPorts.iterator().next().getNumber());
}
}
throw new WebServerException("Unable to start embedded Undertow", ex);
}
finally {
stopSilently();
}
throw new WebServerException("Unable to start embedded Undertow", ex);
}
}
}
private void stopSilently() {
try {
if (this.undertow != null) {
this.undertow.stop();
}
}
catch (Exception ex) {
// Ignore
}
}
private BindException findBindException(Exception ex) {
Throwable candidate = ex;
while (candidate != null) {

View File

@ -88,20 +88,36 @@ public class UndertowWebServer implements WebServer {
.info("Undertow started on port(s) " + getPortsDescription());
}
catch (Exception ex) {
if (findBindException(ex) != null) {
List<UndertowWebServer.Port> failedPorts = getConfiguredPorts();
List<UndertowWebServer.Port> actualPorts = getActualPorts();
failedPorts.removeAll(actualPorts);
if (failedPorts.size() == 1) {
throw new PortInUseException(
failedPorts.iterator().next().getNumber());
try {
if (findBindException(ex) != null) {
List<UndertowWebServer.Port> failedPorts = getConfiguredPorts();
List<UndertowWebServer.Port> actualPorts = getActualPorts();
failedPorts.removeAll(actualPorts);
if (failedPorts.size() == 1) {
throw new PortInUseException(
failedPorts.iterator().next().getNumber());
}
}
throw new WebServerException("Unable to start embedded Undertow", ex);
}
finally {
stopSilently();
}
throw new WebServerException("Unable to start embedded Undertow", ex);
}
}
}
private void stopSilently() {
try {
if (this.undertow != null) {
this.undertow.stop();
}
}
catch (Exception ex) {
// Ignore
}
}
private BindException findBindException(Exception ex) {
Throwable candidate = ex;
while (candidate != null) {

View File

@ -303,6 +303,9 @@ public class UndertowServletWebServerFactoryTests
int blockedPort) {
assertThat(ex).isInstanceOf(PortInUseException.class);
assertThat(((PortInUseException) ex).getPort()).isEqualTo(blockedPort);
Object undertow = ReflectionTestUtils.getField(this.webServer, "undertow");
Object worker = ReflectionTestUtils.getField(undertow, "worker");
assertThat(worker).isNull();
}
}