Search in sources :

Example 11 with WebServerException

use of org.springframework.boot.web.server.WebServerException 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)

Example 12 with WebServerException

use of org.springframework.boot.web.server.WebServerException in project spring-boot by spring-projects.

the class JettyWebServer method start.

@Override
public void start() throws WebServerException {
    synchronized (this.monitor) {
        if (this.started) {
            return;
        }
        this.server.setConnectors(this.connectors);
        if (!this.autoStart) {
            return;
        }
        try {
            this.server.start();
            for (Handler handler : this.server.getHandlers()) {
                handleDeferredInitialize(handler);
            }
            Connector[] connectors = this.server.getConnectors();
            for (Connector connector : connectors) {
                try {
                    connector.start();
                } catch (IOException ex) {
                    if (connector instanceof NetworkConnector) {
                        PortInUseException.throwIfPortBindingException(ex, () -> ((NetworkConnector) connector).getPort());
                    }
                    throw ex;
                }
            }
            this.started = true;
            logger.info("Jetty started on port(s) " + getActualPortsDescription() + " with context path '" + getContextPath() + "'");
        } catch (WebServerException ex) {
            stopSilently();
            throw ex;
        } catch (Exception ex) {
            stopSilently();
            throw new WebServerException("Unable to start embedded Jetty server", ex);
        }
    }
}
Also used : NetworkConnector(org.eclipse.jetty.server.NetworkConnector) Connector(org.eclipse.jetty.server.Connector) WebServerException(org.springframework.boot.web.server.WebServerException) Handler(org.eclipse.jetty.server.Handler) ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) StatisticsHandler(org.eclipse.jetty.server.handler.StatisticsHandler) NetworkConnector(org.eclipse.jetty.server.NetworkConnector) IOException(java.io.IOException) WebServerException(org.springframework.boot.web.server.WebServerException) IOException(java.io.IOException) PortInUseException(org.springframework.boot.web.server.PortInUseException)

Example 13 with WebServerException

use of org.springframework.boot.web.server.WebServerException in project spring-boot by spring-projects.

the class JettyWebServer method initialize.

private void initialize() {
    synchronized (this.monitor) {
        try {
            // Cache the connectors and then remove them to prevent requests being
            // handled before the application context is ready.
            this.connectors = this.server.getConnectors();
            JettyWebServer.this.server.setConnectors(null);
            // Start the server so that the ServletContext is available
            this.server.start();
            this.server.setStopAtShutdown(false);
        } catch (Throwable ex) {
            // Ensure process isn't left running
            stopSilently();
            throw new WebServerException("Unable to start embedded Jetty web server", ex);
        }
    }
}
Also used : WebServerException(org.springframework.boot.web.server.WebServerException)

Example 14 with WebServerException

use of org.springframework.boot.web.server.WebServerException in project spring-boot by spring-projects.

the class SslServerCustomizer method configureSslTrustStore.

private void configureSslTrustStore(SslContextFactory.Server factory, Ssl ssl) {
    if (ssl.getTrustStorePassword() != null) {
        factory.setTrustStorePassword(ssl.getTrustStorePassword());
    }
    if (ssl.getTrustStore() != null) {
        try {
            URL url = ResourceUtils.getURL(ssl.getTrustStore());
            factory.setTrustStoreResource(Resource.newResource(url));
        } catch (IOException ex) {
            throw new WebServerException("Could not find trust store '" + ssl.getTrustStore() + "'", ex);
        }
    }
    if (ssl.getTrustStoreType() != null) {
        factory.setTrustStoreType(ssl.getTrustStoreType());
    }
    if (ssl.getTrustStoreProvider() != null) {
        factory.setTrustStoreProvider(ssl.getTrustStoreProvider());
    }
}
Also used : WebServerException(org.springframework.boot.web.server.WebServerException) IOException(java.io.IOException) URL(java.net.URL)

Example 15 with WebServerException

use of org.springframework.boot.web.server.WebServerException in project spring-boot by spring-projects.

the class TomcatWebServer method stop.

@Override
public void stop() throws WebServerException {
    synchronized (this.monitor) {
        boolean wasStarted = this.started;
        try {
            this.started = false;
            try {
                if (this.gracefulShutdown != null) {
                    this.gracefulShutdown.abort();
                }
                stopTomcat();
                this.tomcat.destroy();
            } catch (LifecycleException ex) {
            // swallow and continue
            }
        } catch (Exception ex) {
            throw new WebServerException("Unable to stop embedded Tomcat", ex);
        } finally {
            if (wasStarted) {
                containerCounter.decrementAndGet();
            }
        }
    }
}
Also used : LifecycleException(org.apache.catalina.LifecycleException) WebServerException(org.springframework.boot.web.server.WebServerException) WebServerException(org.springframework.boot.web.server.WebServerException) NamingException(javax.naming.NamingException) PortInUseException(org.springframework.boot.web.server.PortInUseException) LifecycleException(org.apache.catalina.LifecycleException)

Aggregations

WebServerException (org.springframework.boot.web.server.WebServerException)17 PortInUseException (org.springframework.boot.web.server.PortInUseException)7 IOException (java.io.IOException)6 URL (java.net.URL)6 NamingException (javax.naming.NamingException)6 LifecycleException (org.apache.catalina.LifecycleException)6 Context (org.apache.catalina.Context)4 ConnectorStartFailedException (org.springframework.boot.web.embedded.tomcat.ConnectorStartFailedException)3 InputStream (java.io.InputStream)2 BindException (java.net.BindException)2 KeyStore (java.security.KeyStore)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ServletException (javax.servlet.ServletException)2 Undertow (io.undertow.Undertow)1 HttpHandler (io.undertow.server.HttpHandler)1 HttpServerExchange (io.undertow.server.HttpServerExchange)1 GracefulShutdownHandler (io.undertow.server.handlers.GracefulShutdownHandler)1 Closeable (java.io.Closeable)1