@Override public void stop() { synchronized (this.monitor) { this.started = false; try { this.server.stop(); } catch (InterruptedException ex) { Thread.currentThread().interrupt(); } catch (Exception ex) { throw new WebServerException("Unable to stop embedded Jetty server", ex); } } }
@Override public void stop() throws WebServerException { synchronized (this.monitor) { if (!this.started) { return; } this.started = false; try { this.undertow.stop(); if (this.closeable != null) { this.closeable.close(); } } catch (Exception ex) { throw new WebServerException("Unable to stop undertow", ex); } } }
@Override public synchronized void stop() { try { if (isRunning) { server.stop().get(); isRunning = false; } } catch (Exception cause) { throw new WebServerException("Failed to stop " + ArmeriaWebServer.class.getSimpleName(), Exceptions.peel(cause)); } }
/** * Return the absolute temp dir for given web server. * @param prefix server name * @return the temp dir for given server. */ protected final File createTempDir(String prefix) { try { File tempDir = File.createTempFile(prefix + ".", "." + getPort()); tempDir.delete(); tempDir.mkdir(); tempDir.deleteOnExit(); return tempDir; } catch (IOException ex) { throw new WebServerException( "Unable to create tempDir. java.io.tmpdir is set to " + System.getProperty("java.io.tmpdir"), ex); } }
public X509Certificate[] getTrustedX509CertificatesForTrustManager() { try { CertificateFactory certificateFactory = CertificateFactory .getInstance("X.509"); ArrayList<Certificate> allCerts = new ArrayList<>(); for (String trustedCert : ssl.getTrustedX509Certificates()) { try { URL url = ResourceUtils.getURL(trustedCert); Collection<? extends Certificate> certs = certificateFactory .generateCertificates(url.openStream()); allCerts.addAll(certs); } catch (IOException e) { throw new WebServerException( "Could not load certificate '" + trustedCert + "'", e); } } return allCerts.toArray(new X509Certificate[allCerts.size()]); } catch (CertificateException e1) { throw new WebServerException("Could not load CertificateFactory X.509", e1); } }
@Override public synchronized void start() { try { if (!isRunning) { server.start().get(); if (port == 0) { // Replace the specified port number with the primary port number. // Server#activePort doesn't return the first added port, so we need to find that. final Optional<ServerPort> port = server.activePorts().values().stream() .filter(p -> p.protocols().contains(protocol)) .filter(p -> address == null || Arrays.equals(address.getAddress(), p.localAddress().getAddress().getAddress())) .findFirst(); assert port.isPresent() : "the primary port doest not exist."; this.port = port.get().localAddress().getPort(); } isRunning = true; } } catch (Exception cause) { throw new WebServerException("Failed to start " + ArmeriaWebServer.class.getSimpleName(), Exceptions.peel(cause)); } }
@Override public void stop() throws WebServerException { synchronized (this.monitor) { boolean wasStarted = this.started; try { this.started = false; try { 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(); } } } }
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(); this.server.addBean(new AbstractLifeCycle() { @Override protected void doStart() throws Exception { for (Connector connector : JettyWebServer.this.connectors) { Assert.state(connector.isStopped(), () -> "Connector " + connector + " has been started prematurely"); } 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); } } }
private void performDeferredLoadOnStartup() { try { for (Container child : this.tomcat.getHost().findChildren()) { if (child instanceof TomcatEmbeddedContext) { ((TomcatEmbeddedContext) child).deferredLoadOnStartup(); } } } catch (Exception ex) { if (ex instanceof WebServerException) { throw (WebServerException) ex; } throw new WebServerException("Unable to start embedded Tomcat connectors", ex); } }
@Override public void stop() throws WebServerException { synchronized (this.monitor) { if (!this.started) { return; } this.started = false; try { this.manager.stop(); this.manager.undeploy(); this.undertow.stop(); } catch (Exception ex) { throw new WebServerException("Unable to stop undertow", ex); } } }
@Override public void start() throws WebServerException { if (this.disposableServer == null) { try { this.disposableServer = startHttpServer(); } catch (Exception ex) { ChannelBindException bindException = findBindException(ex); if (bindException != null) { throw new PortInUseException(bindException.localPort()); } throw new WebServerException("Unable to start Netty", ex); } logger.info("Netty started on port(s): " + getPort()); startDaemonAwaitThread(this.disposableServer); } }
throw new WebServerException("Unable to start embedded Undertow", ex);
private void configureSslKeyStore(AbstractHttp11JsseProtocol<?> protocol, Ssl ssl) { try { protocol.setKeystoreFile(ResourceUtils.getURL(ssl.getKeyStore()).toString()); } catch (FileNotFoundException ex) { throw new WebServerException("Could not load key store: " + ex.getMessage(), ex); } if (ssl.getKeyStoreType() != null) { protocol.setKeystoreType(ssl.getKeyStoreType()); } if (ssl.getKeyStoreProvider() != null) { protocol.setKeystoreProvider(ssl.getKeyStoreProvider()); } }
throw new WebServerException("Unable to start embedded Undertow", ex);
protected void configureSslStoreProvider(AbstractHttp11JsseProtocol<?> protocol, SslStoreProvider sslStoreProvider) { Assert.isInstanceOf(Http11NioProtocol.class, protocol, "SslStoreProvider can only be used with Http11NioProtocol"); TomcatURLStreamHandlerFactory instance = TomcatURLStreamHandlerFactory .getInstance(); instance.addUserFactory( new SslStoreProviderUrlStreamHandlerFactory(sslStoreProvider)); try { if (sslStoreProvider.getKeyStore() != null) { protocol.setKeystorePass(""); protocol.setKeystoreFile( SslStoreProviderUrlStreamHandlerFactory.KEY_STORE_URL); } if (sslStoreProvider.getTrustStore() != null) { protocol.setTruststorePass(""); protocol.setTruststoreFile( SslStoreProviderUrlStreamHandlerFactory.TRUST_STORE_URL); } } catch (Exception ex) { throw new WebServerException("Could not load store: " + ex.getMessage(), ex); } }
throw new WebServerException("Unable to start embedded Tomcat server", ex);
throw new WebServerException("Unable to start embedded Tomcat", ex);
throw new WebServerException("Unable to start embedded Jetty server", ex);
private void configureSslTrustStore(AbstractHttp11JsseProtocol<?> protocol, Ssl ssl) { if (ssl.getTrustStore() != null) { try { protocol.setTruststoreFile( ResourceUtils.getURL(ssl.getTrustStore()).toString()); } catch (FileNotFoundException ex) { throw new WebServerException( "Could not load trust store: " + ex.getMessage(), ex); } } protocol.setTruststorePass(ssl.getTrustStorePassword()); if (ssl.getTrustStoreType() != null) { protocol.setTruststoreType(ssl.getTrustStoreType()); } if (ssl.getTrustStoreProvider() != null) { protocol.setTruststoreProvider(ssl.getTrustStoreProvider()); } }
private void load(Wrapper wrapper) { try { wrapper.load(); } catch (ServletException ex) { String message = sm.getString("standardContext.loadOnStartup.loadException", getName(), wrapper.getName()); if (getComputedFailCtxIfServletStartFails()) { throw new WebServerException(message, ex); } getLogger().error(message, StandardWrapper.getRootCause(ex)); } }