Browse Source

Merge branch '1.5.x'

pull/10601/head
Andy Wilkinson 9 years ago
parent
commit
bcfb1d17b1
  1. 32
      spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/UndertowServletWebServer.java
  2. 32
      spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/UndertowWebServer.java
  3. 3
      spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/embedded/undertow/UndertowServletWebServerFactoryTests.java

32
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/UndertowServletWebServer.java

@ -159,20 +159,36 @@ public class UndertowServletWebServer implements WebServer { @@ -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) {

32
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/UndertowWebServer.java

@ -88,20 +88,36 @@ public class UndertowWebServer implements WebServer { @@ -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) {

3
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/embedded/undertow/UndertowServletWebServerFactoryTests.java

@ -303,6 +303,9 @@ public class UndertowServletWebServerFactoryTests @@ -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();
}
}

Loading…
Cancel
Save