Search in sources :

Example 6 with WebServerException

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

the class JettyWebServer method initialize.

private void initialize() {
    synchronized (this.monitor) {
        try {
            // Cache and clear the connectors to prevent requests being handled before
            // the application context is ready
            this.connectors = this.server.getConnectors();
            this.server.setConnectors(null);
            // Start the server so that the ServletContext is available
            this.server.start();
            this.server.setStopAtShutdown(false);
        } catch (Exception ex) {
            // Ensure process isn't left running
            stopSilently();
            throw new WebServerException("Unable to start embedded Jetty web server", ex);
        }
    }
}
Also used : WebServerException(org.springframework.boot.web.server.WebServerException) WebServerException(org.springframework.boot.web.server.WebServerException) BindException(java.net.BindException) PortInUseException(org.springframework.boot.web.server.PortInUseException)

Example 7 with WebServerException

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

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 (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());
        } catch (WebServerException ex) {
            throw ex;
        } catch (Exception ex) {
            throw new WebServerException("Unable to start embedded Jetty server", ex);
        }
    }
}
Also used : NetworkConnector(org.eclipse.jetty.server.NetworkConnector) Connector(org.eclipse.jetty.server.Connector) PortInUseException(org.springframework.boot.web.server.PortInUseException) WebServerException(org.springframework.boot.web.server.WebServerException) Handler(org.eclipse.jetty.server.Handler) BindException(java.net.BindException) NetworkConnector(org.eclipse.jetty.server.NetworkConnector) WebServerException(org.springframework.boot.web.server.WebServerException) BindException(java.net.BindException) PortInUseException(org.springframework.boot.web.server.PortInUseException)

Example 8 with WebServerException

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

the class UndertowWebServer method start.

@Override
public void start() throws WebServerException {
    synchronized (this.monitor) {
        if (this.started) {
            return;
        }
        try {
            if (!this.autoStart) {
                return;
            }
            if (this.undertow == null) {
                this.undertow = this.builder.build();
            }
            this.undertow.start();
            this.started = true;
            UndertowWebServer.logger.info("Undertow started on port(s) " + getPortsDescription());
        } catch (Exception ex) {
            if (findBindException(ex) != null) {
                List<UndertowWebServer.Port> failedPorts = getConfiguredPorts();
                List<UndertowWebServer.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);
        }
    }
}
Also used : PortInUseException(org.springframework.boot.web.server.PortInUseException) WebServerException(org.springframework.boot.web.server.WebServerException) ArrayList(java.util.ArrayList) List(java.util.List) WebServerException(org.springframework.boot.web.server.WebServerException) BindException(java.net.BindException) PortInUseException(org.springframework.boot.web.server.PortInUseException)

Example 9 with WebServerException

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

the class TomcatWebServer method stop.

@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();
            }
        }
    }
}
Also used : LifecycleException(org.apache.catalina.LifecycleException) WebServerException(org.springframework.boot.web.server.WebServerException) LifecycleException(org.apache.catalina.LifecycleException) WebServerException(org.springframework.boot.web.server.WebServerException) NamingException(javax.naming.NamingException)

Example 10 with WebServerException

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

the class UndertowServletWebServer method start.

@Override
public void start() throws WebServerException {
    synchronized (this.monitor) {
        if (this.started) {
            return;
        }
        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());
        } catch (Exception ex) {
            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);
        }
    }
}
Also used : PortInUseException(org.springframework.boot.web.server.PortInUseException) WebServerException(org.springframework.boot.web.server.WebServerException) ArrayList(java.util.ArrayList) List(java.util.List) ServletException(javax.servlet.ServletException) WebServerException(org.springframework.boot.web.server.WebServerException) BindException(java.net.BindException) PortInUseException(org.springframework.boot.web.server.PortInUseException)

Aggregations

WebServerException (org.springframework.boot.web.server.WebServerException)10 BindException (java.net.BindException)5 PortInUseException (org.springframework.boot.web.server.PortInUseException)5 NamingException (javax.naming.NamingException)3 LifecycleException (org.apache.catalina.LifecycleException)3 IOException (java.io.IOException)2 URL (java.net.URL)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ServletException (javax.servlet.ServletException)2 Context (org.apache.catalina.Context)2 Connector (org.apache.catalina.connector.Connector)1 Connector (org.eclipse.jetty.server.Connector)1 Handler (org.eclipse.jetty.server.Handler)1 NetworkConnector (org.eclipse.jetty.server.NetworkConnector)1