List of usage examples for org.springframework.boot.web.server WebServerException WebServerException
public WebServerException(String message, Throwable cause)
From source file:org.springframework.boot.web.embedded.jetty.JettyWebServer.java
private void initialize() { synchronized (this.monitor) { try {/*from w w w.j ava 2 s . co m*/ // 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); } } }
From source file:org.springframework.boot.web.embedded.jetty.JettyWebServer.java
@Override public void start() throws WebServerException { synchronized (this.monitor) { if (this.started) { return; }//from w w w .jav a 2s . c o m 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 (BindException ex) { if (connector instanceof NetworkConnector) { throw new PortInUseException(((NetworkConnector) connector).getPort()); } throw ex; } } this.started = true; JettyWebServer.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); } } }
From source file:org.springframework.boot.web.embedded.jetty.JettyWebServer.java
@Override public void stop() { synchronized (this.monitor) { this.started = false; try {/*from www .j a v a 2 s. com*/ this.server.stop(); } catch (InterruptedException ex) { Thread.currentThread().interrupt(); } catch (Exception ex) { throw new WebServerException("Unable to stop embedded Jetty server", ex); } } }
From source file:org.springframework.boot.web.embedded.netty.NettyWebServer.java
@Override public void start() throws WebServerException { if (this.disposableServer == null) { try {//from w ww .j av a 2 s.c o m 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); } NettyWebServer.logger.info("Netty started on port(s): " + getPort()); startDaemonAwaitThread(this.disposableServer); } }
From source file:org.springframework.boot.web.embedded.tomcat.TomcatWebServer.java
private void initialize() throws WebServerException { TomcatWebServer.logger.info("Tomcat initialized with port(s): " + getPortsDescription(false)); synchronized (this.monitor) { try {/*from w w w . j a v a2s .c o m*/ 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(); throw new WebServerException("Unable to start embedded Tomcat", ex); } } }
From source file:org.springframework.boot.web.embedded.tomcat.TomcatWebServer.java
@Override public void start() throws WebServerException { synchronized (this.monitor) { if (this.started) { return; }/*w ww. ja v a 2s . c o m*/ try { addPreviouslyRemovedConnectors(); Connector connector = this.tomcat.getConnector(); if (connector != null && this.autoStart) { performDeferredLoadOnStartup(); } checkThatConnectorsHaveStarted(); this.started = true; TomcatWebServer.logger.info("Tomcat started on port(s): " + getPortsDescription(true) + " with context path '" + getContextPath() + "'"); } catch (ConnectorStartFailedException ex) { stopSilently(); throw ex; } catch (Exception ex) { throw new WebServerException("Unable to start embedded Tomcat server", ex); } finally { Context context = findContext(); ContextBindings.unbindClassLoader(context, context.getNamingToken(), getClass().getClassLoader()); } } }
From source file:org.springframework.boot.web.embedded.tomcat.TomcatWebServer.java
private void performDeferredLoadOnStartup() { try {// w w w.ja v a 2 s . com for (Container child : this.tomcat.getHost().findChildren()) { if (child instanceof TomcatEmbeddedContext) { ((TomcatEmbeddedContext) child).deferredLoadOnStartup(); } } } catch (Exception ex) { TomcatWebServer.logger.error("Cannot start connector: ", ex); throw new WebServerException("Unable to start embedded Tomcat connectors", ex); } }
From source file:org.springframework.boot.web.embedded.tomcat.TomcatWebServer.java
@Override public void stop() throws WebServerException { synchronized (this.monitor) { boolean wasStarted = this.started; try {//from www .j a v a 2 s . c o m 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(); } } } }
From source file:org.springframework.boot.web.embedded.undertow.UndertowServletWebServer.java
@Override public void start() throws WebServerException { synchronized (this.monitor) { if (this.started) { return; }//from w w w. ja va 2 s. c om try { if (!this.autoStart) { return; } if (this.undertow == null) { this.undertow = createUndertowServer(); } this.undertow.start(); this.started = true; UndertowServletWebServer.logger.info("Undertow started on port(s) " + getPortsDescription() + " with context path '" + this.contextPath + "'"); } catch (Exception ex) { try { if (findBindException(ex) != null) { List<Port> failedPorts = getConfiguredPorts(); List<Port> actualPorts = getActualPorts(); failedPorts.removeAll(actualPorts); if (failedPorts.size() == 1) { throw new PortInUseException(failedPorts.iterator().next().getNumber()); } } throw new WebServerException("Unable to start embedded Undertow", ex); } finally { stopSilently(); } } } }
From source file:org.springframework.boot.web.embedded.undertow.UndertowServletWebServer.java
@Override public void stop() throws WebServerException { synchronized (this.monitor) { if (!this.started) { return; }//from w w w . j av a 2s . c o m this.started = false; try { this.manager.stop(); this.manager.undeploy(); this.undertow.stop(); } catch (Exception ex) { throw new WebServerException("Unable to stop undertow", ex); } } }