Search in sources :

Example 6 with WebAppContext

use of org.mortbay.jetty.webapp.WebAppContext in project nhin-d by DirectProject.

the class ConfigServiceRunner method startConfigService.

public static synchronized void startConfigService() throws Exception {
    if (server == null) {
        /*
			 * Setup the configuration service server
			 */
        server = new Server();
        SocketConnector connector = new SocketConnector();
        HTTPPort = AvailablePortFinder.getNextAvailable(1024);
        connector.setPort(HTTPPort);
        WebAppContext context = new WebAppContext();
        context.setContextPath("/config");
        context.setServer(server);
        context.setWar("war/config-service.war");
        server.setSendServerVersion(false);
        server.addConnector(connector);
        server.addHandler(context);
        server.start();
        configServiceURL = "http://localhost:" + HTTPPort + "/config/ConfigurationService";
    }
}
Also used : WebAppContext(org.mortbay.jetty.webapp.WebAppContext) Server(org.mortbay.jetty.Server) SocketConnector(org.mortbay.jetty.bio.SocketConnector)

Example 7 with WebAppContext

use of org.mortbay.jetty.webapp.WebAppContext in project OpenRefine by OpenRefine.

the class ShutdownSignalHandler method init.

public void init(String host, int port) throws Exception {
    logger.info("Starting Server bound to '" + host + ":" + port + "'");
    String memory = Configurations.get("refine.memory");
    if (memory != null) {
        logger.info("refine.memory size: " + memory + " JVM Max heap: " + Runtime.getRuntime().maxMemory());
    }
    int maxThreads = Configurations.getInteger("refine.queue.size", 30);
    int maxQueue = Configurations.getInteger("refine.queue.max_size", 300);
    long keepAliveTime = Configurations.getInteger("refine.queue.idle_time", 60);
    LinkedBlockingQueue<Runnable> queue = new LinkedBlockingQueue<Runnable>(maxQueue);
    threadPool = new ThreadPoolExecutor(maxThreads, maxQueue, keepAliveTime, TimeUnit.SECONDS, queue);
    this.setThreadPool(new ThreadPoolExecutorAdapter(threadPool));
    Connector connector = new SocketConnector();
    connector.setPort(port);
    connector.setHost(host);
    connector.setMaxIdleTime(Configurations.getInteger("refine.connection.max_idle_time", 60000));
    connector.setStatsOn(false);
    this.addConnector(connector);
    File webapp = new File(Configurations.get("refine.webapp", "main/webapp"));
    if (!isWebapp(webapp)) {
        webapp = new File("main/webapp");
        if (!isWebapp(webapp)) {
            webapp = new File("webapp");
            if (!isWebapp(webapp)) {
                logger.warn("Warning: Failed to find web application at '" + webapp.getAbsolutePath() + "'");
                System.exit(-1);
            }
        }
    }
    final String contextPath = Configurations.get("refine.context_path", "/");
    final int maxFormContentSize = Configurations.getInteger("refine.max_form_content_size", 1048576);
    logger.info("Initializing context: '" + contextPath + "' from '" + webapp.getAbsolutePath() + "'");
    WebAppContext context = new WebAppContext(webapp.getAbsolutePath(), contextPath);
    context.setMaxFormContentSize(maxFormContentSize);
    this.setHandler(context);
    this.setStopAtShutdown(true);
    this.setSendServerVersion(true);
    // Enable context autoreloading
    if (Configurations.getBoolean("refine.autoreload", false)) {
        scanForUpdates(webapp, context);
    }
    // start the server
    try {
        this.start();
    } catch (BindException e) {
        logger.error("Failed to start server - is there another copy running already on this port/address?");
        throw e;
    }
    configure(context);
}
Also used : Connector(org.mortbay.jetty.Connector) SocketConnector(org.mortbay.jetty.bio.SocketConnector) ThreadPoolExecutorAdapter(com.google.util.threads.ThreadPoolExecutorAdapter) BindException(java.net.BindException) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) WebAppContext(org.mortbay.jetty.webapp.WebAppContext) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) SocketConnector(org.mortbay.jetty.bio.SocketConnector) File(java.io.File)

Example 8 with WebAppContext

use of org.mortbay.jetty.webapp.WebAppContext in project maven-plugins by apache.

the class ProjectInfoReportUtilsTest method startJetty.

private void startJetty(boolean isSSL, boolean withAuth) throws Exception {
    jettyServer = new Server();
    jettyServer.setStopAtShutdown(true);
    Connector connector = (isSSL ? getSSLConnector() : getDefaultConnector());
    jettyServer.setConnectors(new Connector[] { connector });
    WebAppContext webapp = new WebAppContext();
    webapp.setContextPath("/");
    webapp.setResourceBase(getBasedir() + "/target/classes/");
    webapp.setServer(jettyServer);
    if (withAuth) {
        Constraint constraint = new Constraint();
        constraint.setName(Constraint.__BASIC_AUTH);
        constraint.setRoles(new String[] { "user", "admin" });
        constraint.setAuthenticate(true);
        ConstraintMapping cm = new ConstraintMapping();
        cm.setConstraint(constraint);
        cm.setPathSpec("/*");
        SecurityHandler sh = new SecurityHandler();
        sh.setUserRealm(new HashUserRealm("MyRealm", getBasedir() + "/src/test/resources/realm.properties"));
        sh.setConstraintMappings(new ConstraintMapping[] { cm });
        webapp.addHandler(sh);
    }
    DefaultHandler defaultHandler = new DefaultHandler();
    defaultHandler.setServer(jettyServer);
    Handler[] handlers = new Handler[2];
    handlers[0] = webapp;
    handlers[1] = defaultHandler;
    jettyServer.setHandlers(handlers);
    jettyServer.start();
    port = connector.getLocalPort();
}
Also used : Connector(org.mortbay.jetty.Connector) SelectChannelConnector(org.mortbay.jetty.nio.SelectChannelConnector) SslSocketConnector(org.mortbay.jetty.security.SslSocketConnector) WebAppContext(org.mortbay.jetty.webapp.WebAppContext) SecurityHandler(org.mortbay.jetty.security.SecurityHandler) ConstraintMapping(org.mortbay.jetty.security.ConstraintMapping) Server(org.mortbay.jetty.Server) Constraint(org.mortbay.jetty.security.Constraint) Handler(org.mortbay.jetty.Handler) SecurityHandler(org.mortbay.jetty.security.SecurityHandler) DefaultHandler(org.mortbay.jetty.handler.DefaultHandler) HashUserRealm(org.mortbay.jetty.security.HashUserRealm) DefaultHandler(org.mortbay.jetty.handler.DefaultHandler)

Example 9 with WebAppContext

use of org.mortbay.jetty.webapp.WebAppContext in project roboguice by roboguice.

the class Main method main.

public static void main(String[] args) throws Exception {
    Server server = new Server();
    Connector connector = new SelectChannelConnector();
    connector.setPort(8080);
    server.setConnectors(new Connector[] { connector });
    WebAppContext webapp = new WebAppContext("./root", "/example");
    server.addHandler(webapp);
    server.start();
    server.join();
}
Also used : Connector(org.mortbay.jetty.Connector) SelectChannelConnector(org.mortbay.jetty.nio.SelectChannelConnector) WebAppContext(org.mortbay.jetty.webapp.WebAppContext) SelectChannelConnector(org.mortbay.jetty.nio.SelectChannelConnector) Server(org.mortbay.jetty.Server)

Example 10 with WebAppContext

use of org.mortbay.jetty.webapp.WebAppContext in project exhibitor by soabase.

the class ExhibitorMain method addSecurityFile.

private void addSecurityFile(HashUserRealm realm, String securityFile, Context root) throws Exception {
    // create a temp Jetty context to parse the security portion of the web.xml file
    /*
            TODO

            This code assumes far too much internal knowledge of Jetty. I don't know
            of simple way to parse the web.xml though and don't want to write it myself.
         */
    final URL url = new URL("file", null, securityFile);
    final WebXmlConfiguration webXmlConfiguration = new WebXmlConfiguration();
    WebAppContext context = new WebAppContext();
    context.setServer(server);
    webXmlConfiguration.setWebAppContext(context);
    ContextHandler contextHandler = new ContextHandler("/") {

        @Override
        protected void startContext() throws Exception {
            super.startContext();
            setServer(server);
            webXmlConfiguration.configure(url.toString());
        }
    };
    contextHandler.start();
    try {
        SecurityHandler securityHandler = webXmlConfiguration.getWebAppContext().getSecurityHandler();
        if (realm != null) {
            securityHandler.setUserRealm(realm);
        }
        root.setSecurityHandler(securityHandler);
    } finally {
        contextHandler.stop();
    }
}
Also used : ContextHandler(org.mortbay.jetty.handler.ContextHandler) WebAppContext(org.mortbay.jetty.webapp.WebAppContext) SecurityHandler(org.mortbay.jetty.security.SecurityHandler) WebXmlConfiguration(org.mortbay.jetty.webapp.WebXmlConfiguration) URL(java.net.URL)

Aggregations

WebAppContext (org.mortbay.jetty.webapp.WebAppContext)17 Server (org.mortbay.jetty.Server)14 SocketConnector (org.mortbay.jetty.bio.SocketConnector)11 Connector (org.mortbay.jetty.Connector)5 SelectChannelConnector (org.mortbay.jetty.nio.SelectChannelConnector)4 File (java.io.File)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)2 MojoFailureException (org.apache.maven.plugin.MojoFailureException)2 Handler (org.mortbay.jetty.Handler)2 DefaultHandler (org.mortbay.jetty.handler.DefaultHandler)2 SecurityHandler (org.mortbay.jetty.security.SecurityHandler)2 WebXmlConfiguration (org.mortbay.jetty.webapp.WebXmlConfiguration)2 ThreadPoolExecutorAdapter (com.google.util.threads.ThreadPoolExecutorAdapter)1 FileOutputStream (java.io.FileOutputStream)1 InputStream (java.io.InputStream)1 BindException (java.net.BindException)1 URL (java.net.URL)1 HashMap (java.util.HashMap)1