1) Pull try/catch check in the JettyServerInitializer out of the initializer.

This commit is contained in:
cheddar 2013-07-29 14:35:30 -07:00
parent 9cd26c70c0
commit 4c9be81912
2 changed files with 21 additions and 20 deletions

View File

@ -2,12 +2,15 @@ package com.metamx.druid.initialization;
import com.google.common.base.Throwables; import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.inject.Binder; import com.google.inject.Binder;
import com.google.inject.ConfigurationException;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.Injector; import com.google.inject.Injector;
import com.google.inject.Key; import com.google.inject.Key;
import com.google.inject.Provides; import com.google.inject.Provides;
import com.google.inject.ProvisionException;
import com.google.inject.Scopes; import com.google.inject.Scopes;
import com.google.inject.TypeLiteral; import com.google.inject.TypeLiteral;
import com.google.inject.name.Named; import com.google.inject.name.Named;
@ -110,7 +113,13 @@ public class JettyServerModule extends JerseyServletModule
public Server getServer(Injector injector, Lifecycle lifecycle, ServerConfig config) public Server getServer(Injector injector, Lifecycle lifecycle, ServerConfig config)
{ {
final Server server = Initialization.makeJettyServer(config); final Server server = Initialization.makeJettyServer(config);
initializer.initialize(server, injector); try {
initializer.initialize(server, injector);
}
catch (ConfigurationException e) {
throw new ProvisionException(Iterables.getFirst(e.getErrorMessages(), null).getMessage());
}
lifecycle.addHandler( lifecycle.addHandler(
new Lifecycle.Handler() new Lifecycle.Handler()

View File

@ -19,10 +19,7 @@
package com.metamx.druid.http; package com.metamx.druid.http;
import com.google.common.collect.Iterables;
import com.google.inject.ConfigurationException;
import com.google.inject.Injector; import com.google.inject.Injector;
import com.google.inject.ProvisionException;
import com.google.inject.servlet.GuiceFilter; import com.google.inject.servlet.GuiceFilter;
import com.metamx.common.lifecycle.Lifecycle; import com.metamx.common.lifecycle.Lifecycle;
import com.metamx.common.logger.Logger; import com.metamx.common.logger.Logger;
@ -98,25 +95,20 @@ public class MasterMain
@Override @Override
public void initialize(Server server, Injector injector) public void initialize(Server server, Injector injector)
{ {
try { ResourceHandler resourceHandler = new ResourceHandler();
ResourceHandler resourceHandler = new ResourceHandler(); resourceHandler.setResourceBase(MasterMain.class.getClassLoader().getResource("static").toExternalForm());
resourceHandler.setResourceBase(MasterMain.class.getClassLoader().getResource("static").toExternalForm());
final ServletContextHandler root = new ServletContextHandler(ServletContextHandler.SESSIONS); final ServletContextHandler root = new ServletContextHandler(ServletContextHandler.SESSIONS);
root.setContextPath("/"); root.setContextPath("/");
HandlerList handlerList = new HandlerList(); HandlerList handlerList = new HandlerList();
handlerList.setHandlers(new Handler[]{resourceHandler, root, new DefaultHandler()}); handlerList.setHandlers(new Handler[]{resourceHandler, root, new DefaultHandler()});
server.setHandler(handlerList); server.setHandler(handlerList);
root.addServlet(new ServletHolder(new DefaultServlet()), "/*"); root.addServlet(new ServletHolder(new DefaultServlet()), "/*");
root.addFilter(GzipFilter.class, "/*", null); root.addFilter(GzipFilter.class, "/*", null);
root.addFilter(new FilterHolder(injector.getInstance(RedirectFilter.class)), "/*", null); root.addFilter(new FilterHolder(injector.getInstance(RedirectFilter.class)), "/*", null);
root.addFilter(GuiceFilter.class, "/*", null); root.addFilter(GuiceFilter.class, "/*", null);
}
catch (ConfigurationException e) {
throw new ProvisionException(Iterables.getFirst(e.getErrorMessages(), null).getMessage());
}
} }
} }
} }