Search in sources :

Example 1 with WebServerException

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

the class UndertowServletWebServer method stop.

@Override
public void stop() throws WebServerException {
    synchronized (this.monitor) {
        if (!this.started) {
            return;
        }
        this.started = false;
        try {
            this.manager.stop();
            this.undertow.stop();
        } catch (Exception ex) {
            throw new WebServerException("Unable to stop undertow", ex);
        }
    }
}
Also used : WebServerException(org.springframework.boot.web.server.WebServerException) ServletException(javax.servlet.ServletException) WebServerException(org.springframework.boot.web.server.WebServerException) BindException(java.net.BindException) PortInUseException(org.springframework.boot.web.server.PortInUseException)

Example 2 with WebServerException

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

the class TomcatWebServer method start.

@Override
public void start() throws WebServerException {
    synchronized (this.monitor) {
        if (this.started) {
            return;
        }
        try {
            addPreviouslyRemovedConnectors();
            Connector connector = this.tomcat.getConnector();
            if (connector != null && this.autoStart) {
                performDeferredLoadOnStartup();
            }
            checkThatConnectorsHaveStarted();
            this.started = true;
            logger.info("Tomcat started on port(s): " + getPortsDescription(true) + " with context path '" + getContextPath() + "'");
        } catch (ConnectorStartFailedException ex) {
            stopSilently();
            throw ex;
        } catch (Exception ex) {
            PortInUseException.throwIfPortBindingException(ex, () -> this.tomcat.getConnector().getPort());
            throw new WebServerException("Unable to start embedded Tomcat server", ex);
        } finally {
            Context context = findContext();
            ContextBindings.unbindClassLoader(context, context.getNamingToken(), getClass().getClassLoader());
        }
    }
}
Also used : Context(org.apache.catalina.Context) Connector(org.apache.catalina.connector.Connector) 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)

Example 3 with WebServerException

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

the class TomcatWebServer method initialize.

private void initialize() throws WebServerException {
    logger.info("Tomcat initialized with port(s): " + getPortsDescription(false));
    synchronized (this.monitor) {
        try {
            addInstanceIdToEngineName();
            Context context = findContext();
            context.addLifecycleListener((event) -> {
                if (context.equals(event.getSource()) && Lifecycle.START_EVENT.equals(event.getType())) {
                    // Remove service connectors so that protocol binding doesn't
                    // happen when the service is started.
                    removeServiceConnectors();
                }
            });
            // Start the server to trigger initialization listeners
            this.tomcat.start();
            // We can re-throw failure exception directly in the main thread
            rethrowDeferredStartupExceptions();
            try {
                ContextBindings.bindClassLoader(context, context.getNamingToken(), getClass().getClassLoader());
            } catch (NamingException ex) {
            // Naming is not enabled. Continue
            }
            // Unlike Jetty, all Tomcat threads are daemon threads. We create a
            // blocking non-daemon to stop immediate shutdown
            startDaemonAwaitThread();
        } catch (Exception ex) {
            stopSilently();
            destroySilently();
            throw new WebServerException("Unable to start embedded Tomcat", ex);
        }
    }
}
Also used : Context(org.apache.catalina.Context) WebServerException(org.springframework.boot.web.server.WebServerException) NamingException(javax.naming.NamingException) WebServerException(org.springframework.boot.web.server.WebServerException) NamingException(javax.naming.NamingException) PortInUseException(org.springframework.boot.web.server.PortInUseException) LifecycleException(org.apache.catalina.LifecycleException)

Example 4 with WebServerException

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

the class SslBuilderCustomizer method loadStore.

private KeyStore loadStore(String type, String provider, String resource, String password) throws Exception {
    type = (type != null) ? type : "JKS";
    KeyStore store = (provider != null) ? KeyStore.getInstance(type, provider) : KeyStore.getInstance(type);
    try {
        URL url = ResourceUtils.getURL(resource);
        try (InputStream stream = url.openStream()) {
            store.load(stream, (password != null) ? password.toCharArray() : null);
        }
        return store;
    } catch (Exception ex) {
        throw new WebServerException("Could not load key store '" + resource + "'", ex);
    }
}
Also used : InputStream(java.io.InputStream) WebServerException(org.springframework.boot.web.server.WebServerException) KeyStore(java.security.KeyStore) URL(java.net.URL) WebServerException(org.springframework.boot.web.server.WebServerException) KeyManagementException(java.security.KeyManagementException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 5 with WebServerException

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

the class SslServerCustomizer method loadStore.

private KeyStore loadStore(String type, String provider, String resource, String password) throws Exception {
    type = (type != null) ? type : "JKS";
    KeyStore store = (provider != null) ? KeyStore.getInstance(type, provider) : KeyStore.getInstance(type);
    try {
        URL url = ResourceUtils.getURL(resource);
        try (InputStream stream = url.openStream()) {
            store.load(stream, (password != null) ? password.toCharArray() : null);
        }
        return store;
    } catch (Exception ex) {
        throw new WebServerException("Could not load key store '" + resource + "'", ex);
    }
}
Also used : InputStream(java.io.InputStream) WebServerException(org.springframework.boot.web.server.WebServerException) KeyStore(java.security.KeyStore) URL(java.net.URL) WebServerException(org.springframework.boot.web.server.WebServerException) KeyStoreException(java.security.KeyStoreException) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) UnrecoverableKeyException(java.security.UnrecoverableKeyException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Aggregations

WebServerException (org.springframework.boot.web.server.WebServerException)14 PortInUseException (org.springframework.boot.web.server.PortInUseException)7 IOException (java.io.IOException)6 URL (java.net.URL)6 NamingException (javax.naming.NamingException)3 LifecycleException (org.apache.catalina.LifecycleException)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 Context (org.apache.catalina.Context)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 Field (java.lang.reflect.Field)1