Commits

Sam Adams committed 184d44a

Refactored to use new ChempoundWebappLauncher

  • Participants
  • Parent commits 3a579ab

Comments (0)

Files changed (2)

 \.old$
 ^temp/
 /temp/
+^workspace/

File src/main/java/uk/ac/cam/ch/wwmm/quixote/QuixoteWebappLauncher.java

 package uk.ac.cam.ch.wwmm.quixote;
 
 import com.google.inject.AbstractModule;
-import com.google.inject.Guice;
-import com.google.inject.Injector;
-import com.google.inject.Module;
-import org.restlet.Application;
-import org.restlet.Component;
-import org.restlet.data.Protocol;
-import uk.ac.cam.ch.wwmm.chempound.DefaultChempoundModule;
 import uk.ac.cam.ch.wwmm.chempound.compchem.CompChemModule;
-import uk.ac.cam.ch.wwmm.chempound.config.ChempoundConfiguration;
-import uk.ac.cam.ch.wwmm.chempound.config.DefaultChempoundConfiguration;
 import uk.ac.cam.ch.wwmm.chempound.crystal.CrystallographyModule;
 import uk.ac.cam.ch.wwmm.chempound.plugins.jmol.JmolModule;
 import uk.ac.cam.ch.wwmm.chempound.plugins.jquery.JQueryModule;
-import uk.ac.cam.ch.wwmm.chempound.webapp.DefaultChempoundWebModule;
+import uk.ac.cam.ch.wwmm.chempound.webapp.ChempoundWebappLauncher;
 import uk.ac.cam.ch.wwmm.chempound.webapp.search.chemistry.StructureSearchProviderModule;
 
-import java.io.File;
-import java.io.IOException;
-import java.net.URI;
-
 /**
  * @author Sam Adams
  */
-public class QuixoteWebappLauncher {
+public class QuixoteWebappLauncher extends ChempoundWebappLauncher {
 
     public static void main(String[] args) throws Exception {
-
-        Injector injector = Guice.createInjector(
-                getConfigurationModule(),
-                new DefaultChempoundModule(),
-                new DefaultChempoundWebModule(),
-                getPluginsModule()
-        );
-
-        ChempoundConfiguration config = injector.getInstance(ChempoundConfiguration.class);
-        URI uri = config.getBaseUri();
-        int port = uri.getPort() == -1 ? 80 : uri.getPort();
-
-        Component component = injector.getInstance(Component.class);
-        component.getServers().add(Protocol.HTTP, port)
-                .getContext().getParameters().add("maxThreads", "256");
-        component.getDefaultHost().attach(injector.getInstance(Application.class));
-        component.start();
-
+        QuixoteWebappLauncher launcher = new QuixoteWebappLauncher();
+        launcher.start();
     }
 
-    protected static Module getConfigurationModule() {
+    @Override
+    protected AbstractModule getPluginsModule() {
         return new AbstractModule() {
             @Override
             protected void configure() {
-                try {
-                    ChempoundConfiguration config = getConfiguration();
-                    bind(ChempoundConfiguration.class).toInstance(config);
-                } catch (IOException e) {
-                    throw new RuntimeException("Error initialising chempound", e);
-                }
-            }
-        };
-    }
-
-    private static ChempoundConfiguration getConfiguration() throws IOException {
-        String workspace = System.getProperty("chempound.workspace");
-        String baseUri = System.getProperty("chempound.uri");
-        File workspaceDir = new File(workspace);
-        URI uri = URI.create(baseUri);
-        return DefaultChempoundConfiguration.load(uri, workspaceDir);
-    }
-
-    protected static AbstractModule getPluginsModule() {
-        return new AbstractModule() {
-            @Override
-            protected void configure() {
-
                 install(new StructureSearchProviderModule());
                 install(new CrystallographyModule());
                 install(new CompChemModule());
 
                 install(new JQueryModule());
                 install(new JmolModule());
-
             }
         };
     }