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);
}
}
}
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);
}
}
}
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());
}
}
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);
}
}
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);
}
}
Aggregations