|
@@ -19,9 +19,6 @@ import org.cobbzilla.wizard.server.config.factory.ConfigurationSource; |
|
|
import org.cobbzilla.wizard.server.config.factory.StreamConfigurationSource; |
|
|
import org.cobbzilla.wizard.server.config.factory.StreamConfigurationSource; |
|
|
import org.cobbzilla.wizard.server.handler.StaticAssetHandler; |
|
|
import org.cobbzilla.wizard.server.handler.StaticAssetHandler; |
|
|
import org.cobbzilla.wizard.validation.Validator; |
|
|
import org.cobbzilla.wizard.validation.Validator; |
|
|
import org.eclipse.jetty.server.Handler; |
|
|
|
|
|
import org.eclipse.jetty.server.Server; |
|
|
|
|
|
import org.eclipse.jetty.server.handler.ContextHandlerCollection; |
|
|
|
|
|
import org.glassfish.grizzly.http.server.*; |
|
|
import org.glassfish.grizzly.http.server.*; |
|
|
import org.glassfish.grizzly.nio.transport.TCPNIOTransport; |
|
|
import org.glassfish.grizzly.nio.transport.TCPNIOTransport; |
|
|
import org.glassfish.grizzly.threadpool.ThreadPoolConfig; |
|
|
import org.glassfish.grizzly.threadpool.ThreadPoolConfig; |
|
@@ -164,14 +161,9 @@ public abstract class RestServerBase<C extends RestServerConfiguration> implemen |
|
|
|
|
|
|
|
|
@Override public boolean isRunning() { return httpServer != null && httpServer.isStarted(); } |
|
|
@Override public boolean isRunning() { return httpServer != null && httpServer.isStarted(); } |
|
|
|
|
|
|
|
|
@Getter(lazy=true) private final Server jetty = initJetty(); |
|
|
|
|
|
private Server initJetty() { |
|
|
|
|
|
final HttpConfiguration httpConfiguration = getConfiguration().getHttp(); |
|
|
|
|
|
if (!httpConfiguration.hasWebPort()) { |
|
|
|
|
|
httpConfiguration.setWebPort(PortPicker.pickOrDie()); |
|
|
|
|
|
} |
|
|
|
|
|
return new Server(httpConfiguration.getWebPort()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// RestWebappServerBase overrides these to enable support for Servlets/Webapps via Jetty |
|
|
|
|
|
protected void initWebapps(C configuration, ConfigurableApplicationContext applicationContext) { notSupported("initWebapps"); } |
|
|
|
|
|
protected void stopWebapps() { notSupported("stopWebapps"); } |
|
|
|
|
|
|
|
|
public HttpServer buildServer(String serverName) throws IOException { |
|
|
public HttpServer buildServer(String serverName) throws IOException { |
|
|
|
|
|
|
|
@@ -219,22 +211,7 @@ public abstract class RestServerBase<C extends RestServerConfiguration> implemen |
|
|
final ServerConfiguration serverConfig = httpServer.getServerConfiguration(); |
|
|
final ServerConfiguration serverConfig = httpServer.getServerConfiguration(); |
|
|
|
|
|
|
|
|
// add handlers -- first the optional webapps |
|
|
// add handlers -- first the optional webapps |
|
|
if (configuration.hasWebapps()) { |
|
|
|
|
|
final ContextHandlerCollection contexts = new ContextHandlerCollection(); |
|
|
|
|
|
final List<Handler> handlers = new ArrayList<>(); |
|
|
|
|
|
for (WebappConfiguration config : configuration.getWebapps()) { |
|
|
|
|
|
handlers.add(config.deploy(applicationContext)); |
|
|
|
|
|
} |
|
|
|
|
|
try { |
|
|
|
|
|
contexts.setHandlers((Handler[]) handlers.toArray()); |
|
|
|
|
|
final Server jetty = getJetty(); |
|
|
|
|
|
jetty.setHandler(contexts); |
|
|
|
|
|
jetty.setStopAtShutdown(true); |
|
|
|
|
|
jetty.start(); |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
return die("buildServer: error starting Jetty to run webapps: "+e, e); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if (configuration.hasWebapps()) initWebapps(configuration, applicationContext); |
|
|
|
|
|
|
|
|
// then the REST/Jersey handler |
|
|
// then the REST/Jersey handler |
|
|
final HttpHandler processor = ContainerFactory.createContainer(GrizzlyHttpContainer.class, rc); |
|
|
final HttpHandler processor = ContainerFactory.createContainer(GrizzlyHttpContainer.class, rc); |
|
@@ -344,13 +321,7 @@ public abstract class RestServerBase<C extends RestServerConfiguration> implemen |
|
|
|
|
|
|
|
|
public synchronized void stopServer() { |
|
|
public synchronized void stopServer() { |
|
|
// stop jetty first, if running |
|
|
// stop jetty first, if running |
|
|
if (configuration.hasWebapps()) { |
|
|
|
|
|
try { |
|
|
|
|
|
getJetty().stop(); |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
log.warn("stopServer: error stopping jetty: "+e, e); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if (configuration.hasWebapps()) stopWebapps(); |
|
|
if (httpServer != null && httpServer.isStarted()) { |
|
|
if (httpServer != null && httpServer.isStarted()) { |
|
|
log.info("stopServer: stopping " + configuration.getServerName() + "..."); |
|
|
log.info("stopServer: stopping " + configuration.getServerName() + "..."); |
|
|
for (RestServerLifecycleListener<C> listener : listeners.values()) listener.beforeStop(this); |
|
|
for (RestServerLifecycleListener<C> listener : listeners.values()) listener.beforeStop(this); |
|
|