use of org.springframework.boot.web.server.PortInUseException in project spring-boot by spring-projects.
the class UndertowServletWebServerFactoryTests method handleExceptionCausedByBlockedPortOnPrimaryConnector.
@Override
protected void handleExceptionCausedByBlockedPortOnPrimaryConnector(RuntimeException ex, int blockedPort) {
assertThat(ex).isInstanceOf(PortInUseException.class);
assertThat(((PortInUseException) ex).getPort()).isEqualTo(blockedPort);
Undertow undertow = (Undertow) ReflectionTestUtils.getField(this.webServer, "undertow");
assertThat(undertow.getWorker()).isNull();
}
use of org.springframework.boot.web.server.PortInUseException in project spring-boot by spring-projects.
the class UndertowServletWebServer method start.
@Override
public void start() throws WebServerException {
synchronized (this.monitor) {
if (this.started) {
return;
}
try {
if (!this.autoStart) {
return;
}
if (this.undertow == null) {
this.undertow = createUndertowServer();
}
this.undertow.start();
this.started = true;
UndertowServletWebServer.logger.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());
}
}
throw new WebServerException("Unable to start embedded Undertow", ex);
}
}
}
use of org.springframework.boot.web.server.PortInUseException in project spring-boot by spring-projects.
the class UndertowWebServer method start.
@Override
public void start() throws WebServerException {
synchronized (this.monitor) {
if (this.started) {
return;
}
try {
if (!this.autoStart) {
return;
}
if (this.undertow == null) {
this.undertow = createUndertowServer();
}
this.undertow.start();
this.started = true;
String message = getStartLogMessage();
logger.info(message);
} catch (Exception ex) {
try {
PortInUseException.ifPortBindingException(ex, (bindException) -> {
List<Port> failedPorts = getConfiguredPorts();
failedPorts.removeAll(getActualPorts());
if (failedPorts.size() == 1) {
throw new PortInUseException(failedPorts.get(0).getNumber());
}
});
throw new WebServerException("Unable to start embedded Undertow", ex);
} finally {
stopSilently();
}
}
}
}
Aggregations