Search in sources :

Example 1 with PortInUseException

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();
}
Also used : PortInUseException(org.springframework.boot.web.server.PortInUseException) Undertow(io.undertow.Undertow)

Example 2 with PortInUseException

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);
        }
    }
}
Also used : PortInUseException(org.springframework.boot.web.server.PortInUseException) WebServerException(org.springframework.boot.web.server.WebServerException) ArrayList(java.util.ArrayList) List(java.util.List) ServletException(javax.servlet.ServletException) WebServerException(org.springframework.boot.web.server.WebServerException) BindException(java.net.BindException) PortInUseException(org.springframework.boot.web.server.PortInUseException)

Example 3 with PortInUseException

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();
            }
        }
    }
}
Also used : SocketAddress(java.net.SocketAddress) BoundChannel(org.xnio.channels.BoundChannel) WebServerException(org.springframework.boot.web.server.WebServerException) HttpServerExchange(io.undertow.server.HttpServerExchange) IOException(java.io.IOException) Field(java.lang.reflect.Field) InetSocketAddress(java.net.InetSocketAddress) AtomicReference(java.util.concurrent.atomic.AtomicReference) GracefulShutdownResult(org.springframework.boot.web.server.GracefulShutdownResult) ArrayList(java.util.ArrayList) Undertow(io.undertow.Undertow) HttpHandler(io.undertow.server.HttpHandler) WebServer(org.springframework.boot.web.server.WebServer) List(java.util.List) ReflectionUtils(org.springframework.util.ReflectionUtils) Closeable(java.io.Closeable) PortInUseException(org.springframework.boot.web.server.PortInUseException) Log(org.apache.commons.logging.Log) GracefulShutdownHandler(io.undertow.server.handlers.GracefulShutdownHandler) LogFactory(org.apache.commons.logging.LogFactory) Collections(java.util.Collections) GracefulShutdownCallback(org.springframework.boot.web.server.GracefulShutdownCallback) Assert(org.springframework.util.Assert) StringUtils(org.springframework.util.StringUtils) PortInUseException(org.springframework.boot.web.server.PortInUseException) WebServerException(org.springframework.boot.web.server.WebServerException) ArrayList(java.util.ArrayList) List(java.util.List) WebServerException(org.springframework.boot.web.server.WebServerException) IOException(java.io.IOException) PortInUseException(org.springframework.boot.web.server.PortInUseException)

Aggregations

PortInUseException (org.springframework.boot.web.server.PortInUseException)3 Undertow (io.undertow.Undertow)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 WebServerException (org.springframework.boot.web.server.WebServerException)2 HttpHandler (io.undertow.server.HttpHandler)1 HttpServerExchange (io.undertow.server.HttpServerExchange)1 GracefulShutdownHandler (io.undertow.server.handlers.GracefulShutdownHandler)1 Closeable (java.io.Closeable)1 IOException (java.io.IOException)1 Field (java.lang.reflect.Field)1 BindException (java.net.BindException)1 InetSocketAddress (java.net.InetSocketAddress)1 SocketAddress (java.net.SocketAddress)1 Collections (java.util.Collections)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 ServletException (javax.servlet.ServletException)1 Log (org.apache.commons.logging.Log)1 LogFactory (org.apache.commons.logging.LogFactory)1 GracefulShutdownCallback (org.springframework.boot.web.server.GracefulShutdownCallback)1