Search in sources :

Example 1 with WebServerException

use of cn.taketoday.framework.web.server.WebServerException in project today-infrastructure by TAKETODAY.

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;
            LoggerFactory.getLogger(JettyWebServer.class).info("Jetty started on port(s) {} with context path '{}'", getActualPortsDescription(), 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(cn.taketoday.framework.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) IOException(java.io.IOException) WebServerException(cn.taketoday.framework.web.server.WebServerException) PortInUseException(cn.taketoday.framework.web.server.PortInUseException)

Example 2 with WebServerException

use of cn.taketoday.framework.web.server.WebServerException in project today-infrastructure by TAKETODAY.

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(cn.taketoday.framework.web.server.WebServerException)

Example 3 with WebServerException

use of cn.taketoday.framework.web.server.WebServerException in project today-infrastructure by TAKETODAY.

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(cn.taketoday.framework.web.server.WebServerException) IOException(java.io.IOException) URL(java.net.URL)

Example 4 with WebServerException

use of cn.taketoday.framework.web.server.WebServerException in project today-infrastructure by TAKETODAY.

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(cn.taketoday.framework.web.server.WebServerException) KeyStore(java.security.KeyStore) URL(java.net.URL) KeyManagementException(java.security.KeyManagementException) WebServerException(cn.taketoday.framework.web.server.WebServerException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 5 with WebServerException

use of cn.taketoday.framework.web.server.WebServerException in project today-infrastructure by TAKETODAY.

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(cn.taketoday.framework.web.server.WebServerException) KeyStore(java.security.KeyStore) URL(java.net.URL) KeyStoreException(java.security.KeyStoreException) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) UnrecoverableKeyException(java.security.UnrecoverableKeyException) WebServerException(cn.taketoday.framework.web.server.WebServerException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Aggregations

WebServerException (cn.taketoday.framework.web.server.WebServerException)16 URL (java.net.URL)8 PortInUseException (cn.taketoday.framework.web.server.PortInUseException)6 IOException (java.io.IOException)6 InputStream (java.io.InputStream)4 KeyStore (java.security.KeyStore)4 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)4 NamingException (javax.naming.NamingException)3 LifecycleException (org.apache.catalina.LifecycleException)3 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)2 KeyManagementException (java.security.KeyManagementException)2 KeyStoreException (java.security.KeyStoreException)2 UnrecoverableKeyException (java.security.UnrecoverableKeyException)2 Context (org.apache.catalina.Context)2 Connector (org.eclipse.jetty.server.Connector)2 Handler (org.eclipse.jetty.server.Handler)2 NetworkConnector (org.eclipse.jetty.server.NetworkConnector)2 ContextHandler (org.eclipse.jetty.server.handler.ContextHandler)2 StatisticsHandler (org.eclipse.jetty.server.handler.StatisticsHandler)2 GracefulShutdownCallback (cn.taketoday.framework.web.server.GracefulShutdownCallback)1