Search in sources :

Example 21 with DefaultServlet

use of org.eclipse.jetty.servlet.DefaultServlet in project groovity by disney.

the class GroovityStandalone method main.

public static void main(String[] args) {
    try {
        int port = -1;
        int securePort = -1;
        String keyStoreLocation = null;
        String keyStorePassword = null;
        if (args.length > 0) {
            port = Integer.parseInt(args[0]);
            if (args.length > 1) {
                securePort = Integer.parseInt(args[1]);
                if (args.length > 2) {
                    keyStoreLocation = args[2];
                    if (args.length > 3) {
                        keyStorePassword = args[3];
                    } else {
                        keyStorePassword = "";
                    }
                }
            }
        }
        File workingDirectory = new File("").getAbsoluteFile();
        File groovityDirectory = new File(workingDirectory, "groovity");
        if (!groovityDirectory.exists() || !groovityDirectory.isDirectory()) {
            throw new FileNotFoundException("No directory found at " + groovityDirectory.getAbsolutePath());
        }
        List<URL> projectClasspathList = new ArrayList<URL>();
        File libDirectory = new File(workingDirectory, "lib");
        if (libDirectory.exists() && libDirectory.isDirectory()) {
            File[] jars = libDirectory.listFiles(new FilenameFilter() {

                @Override
                public boolean accept(File dir, String name) {
                    return name.toLowerCase().endsWith(".jar");
                }
            });
            if (jars != null && jars.length > 0) {
                for (int i = 0; i < jars.length; i++) {
                    projectClasspathList.add(jars[i].toURI().toURL());
                }
            }
        }
        File resourceDirectory = new File(workingDirectory, "static");
        if (!resourceDirectory.exists() || !resourceDirectory.isDirectory()) {
            resourceDirectory = null;
        }
        File jarDirectory = new File(workingDirectory, "target");
        if (!jarDirectory.exists() || !jarDirectory.isDirectory()) {
            jarDirectory = null;
        }
        File confDirectory = new File(workingDirectory, "conf");
        if (!confDirectory.exists() || !confDirectory.isDirectory()) {
            confDirectory = null;
        }
        URLClassLoader loader = new URLClassLoader(projectClasspathList.toArray(new URL[0]), Thread.currentThread().getContextClassLoader());
        GroovityServletContainerBuilder groovityServletContainerBuilder = new GroovityServletContainerBuilder().addSourceLocation(groovityDirectory.toURI(), true).setPort(port).setSecurePort(Integer.valueOf(securePort)).setSecureKeyStoreLocation(keyStoreLocation).setSecureKeyStorePassword(keyStorePassword).setWebappDirectory(workingDirectory).setClassLoader(loader);
        if (jarDirectory != null) {
            groovityServletContainerBuilder.setJarDirectory(jarDirectory);
        }
        if (confDirectory != null) {
            groovityServletContainerBuilder.setPropsFile(confDirectory.getAbsolutePath());
        }
        DefaultServlet resourceServlet = new DefaultServlet();
        ServletHolder resourceServletHolder = new ServletHolder(resourceServlet);
        GroovityServletContainer container = groovityServletContainerBuilder.build();
        WebAppContext context = container.getContext();
        context.addServlet(resourceServletHolder, "/static/*");
        container.start();
        try {
            container.enterConsole();
        } finally {
            container.stop();
        }
    } catch (Throwable e) {
        logger.log(Level.SEVERE, "Error in groovity standalone", e);
    }
    System.exit(0);
}
Also used : GroovityServletContainer(com.disney.groovity.servlet.container.GroovityServletContainer) GroovityServletContainerBuilder(com.disney.groovity.servlet.container.GroovityServletContainerBuilder) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) FileNotFoundException(java.io.FileNotFoundException) ArrayList(java.util.ArrayList) URL(java.net.URL) FilenameFilter(java.io.FilenameFilter) WebAppContext(org.eclipse.jetty.webapp.WebAppContext) URLClassLoader(java.net.URLClassLoader) DefaultServlet(org.eclipse.jetty.servlet.DefaultServlet) File(java.io.File)

Aggregations

DefaultServlet (org.eclipse.jetty.servlet.DefaultServlet)21 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)20 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)9 HandlerList (org.eclipse.jetty.server.handler.HandlerList)7 WebAppContext (org.eclipse.jetty.webapp.WebAppContext)7 File (java.io.File)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 FilterHolder (org.eclipse.jetty.servlet.FilterHolder)4 Json (org.apache.druid.guice.annotations.Json)3 Authenticator (org.apache.druid.server.security.Authenticator)3 AuthenticatorMapper (org.apache.druid.server.security.AuthenticatorMapper)3 Server (org.eclipse.jetty.server.Server)3 DefaultHandler (org.eclipse.jetty.server.handler.DefaultHandler)3 DispatcherType (javax.servlet.DispatcherType)2 HttpServer (org.apache.samza.coordinator.server.HttpServer)2 Handler (org.eclipse.jetty.server.Handler)2 Before (org.junit.Before)2 GroovityServletContainer (com.disney.groovity.servlet.container.GroovityServletContainer)1 GroovityServletContainerBuilder (com.disney.groovity.servlet.container.GroovityServletContainerBuilder)1 CertificateAndKey (com.fathomdb.crypto.CertificateAndKey)1