org.eclipse.jetty.server.handler.HandlerList Java Examples

The following examples show how to use org.eclipse.jetty.server.handler.HandlerList. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ConfigurationServerDriver.java    From candybean with GNU Affero General Public License v3.0 7 votes vote down vote up
public static void main (String args[]) throws Exception{
	logger.info("Starting JETTY server");
    Server server = new Server(8080);
    
       ResourceHandler resourceHandler = new ResourceHandler();
       resourceHandler.setDirectoriesListed(true);
       resourceHandler.setWelcomeFiles(new String[]{ "resources/html/configure.html" });
       resourceHandler.setResourceBase(".");
       
       ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
       resourceHandler.setWelcomeFiles(new String[]{ "resources/html/configure.html" });
       resourceHandler.setResourceBase(".");
       context.addServlet(new ServletHolder(new ConfigurationServlet()),"/cfg");
       context.addServlet(new ServletHolder(new SaveConfigurationServlet()),"/cfg/save");
       context.addServlet(new ServletHolder(new LoadConfigurationServlet()),"/cfg/load");
       
       HandlerList handlers = new HandlerList();
       handlers.setHandlers(new Handler[] { resourceHandler, context });
       server.setHandler(handlers);

       server.start();
	logger.info("Configuration server started at: http://localhost:8080/cfg");
       server.join();
}
 
Example #2
Source File: StatsServer.java    From cxf with Apache License 2.0 6 votes vote down vote up
public static void main(final String[] args) throws Exception {
    final Server server = new Server(8686);

    final ServletHolder staticHolder = new ServletHolder(new DefaultServlet());
    final ServletContextHandler staticContext = new ServletContextHandler();
    staticContext.setContextPath("/static");
    staticContext.addServlet(staticHolder, "/*");
    staticContext.setResourceBase(StatsServer.class.getResource("/web-ui").toURI().toString());

     // Register and map the dispatcher servlet
    final CXFCdiServlet cxfServlet = new CXFCdiServlet();
    final ServletHolder cxfServletHolder = new ServletHolder(cxfServlet);
    final ServletContextHandler context = new ServletContextHandler();
    context.setContextPath("/");
    context.addEventListener(new Listener());
    context.addEventListener(new BeanManagerResourceBindingListener());
    context.addServlet(cxfServletHolder, "/rest/*");

    HandlerList handlers = new HandlerList();
    handlers.addHandler(staticContext);
    handlers.addHandler(context);

    server.setHandler(handlers);
    server.start();
    server.join();
}
 
Example #3
Source File: PackageManagerCLITest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
public void start() throws Exception {
  server = new Server();

  connector = new ServerConnector(server);
  connector.setPort(port);
  server.addConnector(connector);
  server.setStopAtShutdown(true);

  ResourceHandler resourceHandler = new ResourceHandler();
  resourceHandler.setResourceBase(resourceDir);
  resourceHandler.setDirectoriesListed(true);

  HandlerList handlers = new HandlerList();
  handlers.setHandlers(new Handler[] {resourceHandler, new DefaultHandler()});
  server.setHandler(handlers);

  server.start();
}
 
Example #4
Source File: ChaosHttpProxy.java    From chaos-http-proxy with Apache License 2.0 6 votes vote down vote up
public ChaosHttpProxy(URI endpoint, ChaosConfig config)
        throws Exception {
    setChaosConfig(config);

    Supplier<Failure> supplier = new RandomFailureSupplier(
            config.getFailures());

    requireNonNull(endpoint);

    client = new HttpClient();

    server = new Server();
    HttpConnectionFactory httpConnectionFactory =
            new HttpConnectionFactory();
    // TODO: SSL
    ServerConnector connector = new ServerConnector(server,
            httpConnectionFactory);
    connector.setHost(endpoint.getHost());
    connector.setPort(endpoint.getPort());
    server.addConnector(connector);
    this.handler = new ChaosHttpProxyHandler(client, supplier);
    HandlerList handlers = new HandlerList();
    handlers.addHandler(new ChaosApiHandler(this, handler));
    handlers.addHandler(handler);
    server.setHandler(handlers);
}
 
Example #5
Source File: Main.java    From tp_java_2015_02 with MIT License 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    if (args.length != 1) {
        System.out.append("Use port as the first argument");
        System.exit(1);
    }

    String portString = args[0];
    int port = Integer.valueOf(portString);
    System.out.append("Starting at port: ").append(portString).append('\n');

    Server server = new Server(port);
    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
    context.addServlet(new ServletHolder(new AdminPageServlet()), AdminPageServlet.adminPageURL);

    ResourceHandler resource_handler = new ResourceHandler();
    resource_handler.setDirectoriesListed(true);
    resource_handler.setResourceBase("static");

    HandlerList handlers = new HandlerList();
    handlers.setHandlers(new Handler[]{resource_handler, context});
    server.setHandler(handlers);

    server.start();
    server.join();
}
 
Example #6
Source File: Main.java    From stepic_java_webserver with MIT License 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    Server server = new Server(8080);
    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);

    context.addServlet(new ServletHolder(new WebSocketChatServlet()), "/chat");

    ResourceHandler resource_handler = new ResourceHandler();
    resource_handler.setDirectoriesListed(true);
    resource_handler.setResourceBase("public_html");

    HandlerList handlers = new HandlerList();
    handlers.setHandlers(new Handler[]{resource_handler, context});
    server.setHandler(handlers);

    server.start();
    server.join();
}
 
Example #7
Source File: DashBoardServer.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 6 votes vote down vote up
public void prepare() {
    try {
        Tools.verifyLocalPort("DBServer ", port());
        server = new Server();
        DefaultHandler webHandler = new DefaultHandler();
        HandlerList handlers = new HandlerList();
        handlers.setHandlers(new Handler[]{getResourceHandler(),
            getUIWSHandler(), webHandler});

        ServerConnector connector = new ServerConnector(server);
        connector.setPort(port());
        server.setConnectors(new Connector[]{connector});
        server.setHandler(handlers);

        LOG.log(Level.INFO, "DB Server on : http://{0}:{1}",
                new Object[]{Tools.IP(), port() + ""});

    } catch (Exception ex) {
        LOG.log(Level.SEVERE, ex.getMessage(), ex);
    }
}
 
Example #8
Source File: Main.java    From stepic_java_webserver with MIT License 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    AccountService accountService = new AccountService();

    accountService.addNewUser(new UserProfile("admin"));
    accountService.addNewUser(new UserProfile("test"));

    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
    context.addServlet(new ServletHolder(new UsersServlet(accountService)), "/api/v1/users");
    context.addServlet(new ServletHolder(new SessionsServlet(accountService)), "/api/v1/sessions");

    ResourceHandler resource_handler = new ResourceHandler();
    resource_handler.setResourceBase("public_html");

    HandlerList handlers = new HandlerList();
    handlers.setHandlers(new Handler[]{resource_handler, context});

    Server server = new Server(8080);
    server.setHandler(handlers);

    server.start();
    server.join();
}
 
Example #9
Source File: NodeAgent.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
private void customJar(String simpleName, byte[] bytes) throws Exception {
	File jar = new File(Config.dir_custom_jars(true), simpleName + ".jar");
	FileUtils.writeByteArrayToFile(jar, bytes, false);
	List<String> contexts = new ArrayList<>();
	for (String s : Config.dir_custom().list(new WildcardFileFilter("*.war"))) {
		contexts.add("/" + FilenameUtils.getBaseName(s));
	}
	if (Servers.applicationServerIsRunning()) {
		GzipHandler gzipHandler = (GzipHandler) Servers.applicationServer.getHandler();
		HandlerList hanlderList = (HandlerList) gzipHandler.getHandler();
		for (Handler handler : hanlderList.getHandlers()) {
			if (QuickStartWebApp.class.isAssignableFrom(handler.getClass())) {
				QuickStartWebApp app = (QuickStartWebApp) handler;
				if (contexts.contains(app.getContextPath())) {
					app.stop();
					Thread.sleep(2000);
					app.start();
				}
			}
		}
	}
}
 
Example #10
Source File: NodeAgent.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
private void customWar(String simpleName, byte[] bytes) throws Exception {
	File war = new File(Config.dir_custom(true), simpleName + ".war");
	File dir = new File(Config.dir_servers_applicationServer_work(), simpleName);
	FileUtils.writeByteArrayToFile(war, bytes, false);
	if (Servers.applicationServerIsRunning()) {
		GzipHandler gzipHandler = (GzipHandler) Servers.applicationServer.getHandler();
		HandlerList hanlderList = (HandlerList) gzipHandler.getHandler();
		for (Handler handler : hanlderList.getHandlers()) {
			if (QuickStartWebApp.class.isAssignableFrom(handler.getClass())) {
				QuickStartWebApp app = (QuickStartWebApp) handler;
				if (StringUtils.equals("/" + simpleName, app.getContextPath())) {
					app.stop();
					this.modified(bytes, war, dir);
					app.start();
				}
			}
		}
	}
}
 
Example #11
Source File: GraphQlServer.java    From rejoiner with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
  // Embedded Jetty server
  Server server = new Server(HTTP_PORT);
  ResourceHandler resourceHandler = new ResourceHandler();
  resourceHandler.setWelcomeFiles(new String[] {"index.html"});
  resourceHandler.setDirectoriesListed(true);
  // resource base is relative to the WORKSPACE file
  resourceHandler.setResourceBase("./src/main/resources");
  HandlerList handlerList = new HandlerList();
  handlerList.setHandlers(
      new Handler[] {resourceHandler, new GraphQlHandler(), new DefaultHandler()});
  server.setHandler(handlerList);
  server.start();
  logger.info("Server running on port " + HTTP_PORT);
  server.join();
}
 
Example #12
Source File: HttpServer.java    From calcite-avatica with Apache License 2.0 6 votes vote down vote up
private HandlerList configureHandlers() {
  final HandlerList handlerList = new HandlerList();
  Handler avaticaHandler = handler;

  // Wrap the provided handler for security if we made one
  if (null != config) {
    ConstraintSecurityHandler securityHandler = getSecurityHandler();
    securityHandler.setHandler(handler);
    avaticaHandler = securityHandler;
  }

  handlerList.setHandlers(new Handler[] {avaticaHandler, new DefaultHandler()});

  server.setHandler(handlerList);
  return handlerList;
}
 
Example #13
Source File: HelloServer.java    From new-bull with MIT License 6 votes vote down vote up
@Override
public void run(String... strings) throws Exception {
    Server server = new Server(8888);

    ServletContextHandler helloHandler = new ServletContextHandler(SESSIONS);
    helloHandler.setContextPath("/hello");
    helloHandler.addServlet(HelloServlet.class, "/*");
    helloHandler.addFilter(HelloFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));

    HandlerList handlers = new HandlerList();
    handlers.setHandlers(new Handler[] {helloHandler});
    server.setHandler(handlers);
    server.start();
    log.info("hello server started");
    server.join();
}
 
Example #14
Source File: StatsServer.java    From cxf with Apache License 2.0 6 votes vote down vote up
public static void main(final String[] args) throws Exception {
    final Server server = new Server(8686);

    final ServletHolder staticHolder = new ServletHolder(new DefaultServlet());
    final ServletContextHandler staticContext = new ServletContextHandler();
    staticContext.setContextPath("/static");
    staticContext.addServlet(staticHolder, "/*");
    staticContext.setResourceBase(StatsServer.class.getResource("/web-ui").toURI().toString());

     // Register and map the dispatcher servlet
    final ServletHolder cxfServletHolder = new ServletHolder(new CXFServlet());
    final ServletContextHandler context = new ServletContextHandler();
    context.setContextPath("/");
    context.addEventListener(new ContextLoaderListener());
    context.addServlet(cxfServletHolder, "/rest/*");
    context.setInitParameter("contextClass", AnnotationConfigWebApplicationContext.class.getName());
    context.setInitParameter("contextConfigLocation", StatsConfig.class.getName());

    HandlerList handlers = new HandlerList();
    handlers.addHandler(staticContext);
    handlers.addHandler(context);

    server.setHandler(handlers);
    server.start();
    server.join();
}
 
Example #15
Source File: JettyAppServer.java    From selenium with Apache License 2.0 6 votes vote down vote up
protected ServletContextHandler addResourceHandler(String contextPath, Path resourceBase) {
  ServletContextHandler context = new ServletContextHandler();

  ResourceHandler staticResource = new ResourceHandler();
  staticResource.setDirectoriesListed(true);
  staticResource.setWelcomeFiles(new String[] { "index.html" });
  staticResource.setResourceBase(resourceBase.toAbsolutePath().toString());
  MimeTypes mimeTypes = new MimeTypes();
  mimeTypes.addMimeMapping("appcache", "text/cache-manifest");
  staticResource.setMimeTypes(mimeTypes);

  context.setContextPath(contextPath);
  context.setAliasChecks(Arrays.asList(new ApproveAliases(), new AllowSymLinkAliasChecker()));

  HandlerList allHandlers = new HandlerList();
  allHandlers.addHandler(staticResource);
  allHandlers.addHandler(context.getHandler());
  context.setHandler(allHandlers);

  handlers.addHandler(context);

  return context;
}
 
Example #16
Source File: CustomAuthHttpServerTest.java    From calcite-avatica with Apache License 2.0 6 votes vote down vote up
@Override public void customize(Server server) {
  HttpServer avaticaServer = getAvaticaServer();

  HandlerFactory factory = new HandlerFactory();
  Handler avaticaHandler = factory.getHandler(service,
          Driver.Serialization.PROTOBUF, null, configuration);

  if (isBasicAuth) {
    ConstraintSecurityHandler securityHandler =
            avaticaServer.configureBasicAuthentication(server, configuration);
    securityHandler.setHandler(avaticaHandler);
    avaticaHandler = securityHandler;
  }

  HandlerList handlerList = new HandlerList();
  handlerList.setHandlers(new Handler[] { avaticaHandler, new DefaultHandler()});
  server.setHandler(handlerList);
}
 
Example #17
Source File: WebServerTestCase.java    From htmlunit with Apache License 2.0 6 votes vote down vote up
/**
 * Starts the web server on the default {@link #PORT}.
 * The given resourceBase is used to be the ROOT directory that serves the default context.
 * <p><b>Don't forget to stop the returned HttpServer after the test</b>
 *
 * @param resourceBase the base of resources for the default context
 * @throws Exception if the test fails
 */
protected void startWebServer(final String resourceBase) throws Exception {
    if (server_ != null) {
        throw new IllegalStateException("startWebServer() can not be called twice");
    }
    final Server server = buildServer(PORT);

    final WebAppContext context = new WebAppContext();
    context.setContextPath("/");
    context.setResourceBase(resourceBase);

    final ResourceHandler resourceHandler = new ResourceHandler();
    resourceHandler.setResourceBase(resourceBase);
    final MimeTypes mimeTypes = new MimeTypes();
    mimeTypes.addMimeMapping("js", MimeType.APPLICATION_JAVASCRIPT);
    resourceHandler.setMimeTypes(mimeTypes);

    final HandlerList handlers = new HandlerList();
    handlers.setHandlers(new Handler[]{resourceHandler, context});
    server.setHandler(handlers);
    server.setHandler(resourceHandler);

    tryStart(PORT, server);
    server_ = server;
}
 
Example #18
Source File: Main.java    From homework_tester with MIT License 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    Server server = new Server(8080);
    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);

    context.addServlet(new ServletHolder(new WebSocketChatServlet()), "/chat");

    ResourceHandler resource_handler = new ResourceHandler();
    resource_handler.setDirectoriesListed(true);
    resource_handler.setResourceBase("public_html");

    HandlerList handlers = new HandlerList();
    handlers.setHandlers(new Handler[]{resource_handler, context});
    server.setHandler(handlers);

    server.start();
    System.out.println("Server started!");
    server.join();
}
 
Example #19
Source File: WebServer.java    From haxademic with MIT License 6 votes vote down vote up
protected void configServer() {
       // init static web server
       WebAppContext webAppContext = new WebAppContext(wwwPath, "/");
       
       // turn off file locking! 
       // without this, we were blocked from dynamically replace static files in the web server directory at runtime
       webAppContext.setInitParameter("org.eclipse.jetty.servlet.Default.useFileMappedBuffer", "false");
       
       // set custom & static handlers
       HandlerList handlers = new HandlerList();
       handlers.setHandlers(new Handler[] { 
   		this.handler, 
   		webAppContext 			// Jetty's built-in static asset web server. this catches any request not handled by the custom handler
       });
       server.setHandler(handlers);
}
 
Example #20
Source File: CompletionServer.java    From M2Doc with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Starts the server.
 * 
 * @param host
 *            the host to listen
 * @param port
 *            the port to listen
 * @throws Exception
 *             if the server can't be started
 */
public void start(String host, int port) throws Exception {
    server = new Server();

    @SuppressWarnings("resource")
    final ServerConnector connector = new ServerConnector(server);
    connector.setPort(port);
    connector.setHost(host);
    server.setConnectors(new Connector[] {connector });

    final ServletHandler servletHandler = new ServletHandler();
    server.setHandler(servletHandler);
    servletHandler.addServletWithMapping(AddInServlet.class, "/*");

    final HandlerList handlers = new HandlerList();
    handlers.setHandlers(new Handler[] {servletHandler, new DefaultHandler() });
    server.setHandler(handlers);

    server.start();
}
 
Example #21
Source File: JettyStarter.java    From scheduling with GNU Affero General Public License v3.0 6 votes vote down vote up
private void addWarsToHandlerList(HandlerList handlerList, String[] virtualHost) {
    File warFolder = new File(getSchedulerHome() + FOLDER_TO_DEPLOY);
    File[] warFolderContent = warFolder.listFiles((dir, name) -> !"getstarted".equals(name));

    if (warFolderContent != null) {
        for (File fileToDeploy : warFolderContent) {
            if (isExplodedWebApp(fileToDeploy)) {
                addExplodedWebApp(handlerList, fileToDeploy, virtualHost);
            } else if (isWarFile(fileToDeploy)) {
                addWarFile(handlerList, fileToDeploy, virtualHost);
            } else if (isStaticFolder(fileToDeploy)) {
                addStaticFolder(handlerList, fileToDeploy, virtualHost);
            }
        }
    }

    addGetStartedApplication(handlerList, new File(warFolder, "getstarted"), virtualHost);
}
 
Example #22
Source File: WebServer.java    From ironjacamar with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Constructs the web server
 */
public WebServer()
{
   SecurityActions.setSystemProperty("org.eclipse.jetty.util.log.class", JavaUtilLog.class.getName());
   Log.setLog(new JavaUtilLog());

   this.server = null;
   this.host = "localhost";
   this.port = 8080;
   this.mbeanServer = null;
   this.acceptQueueSize = 64;
   this.executorService = null;
   this.handlers = new HandlerList();
}
 
Example #23
Source File: RestTestBase.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
public Server createJettyServer(String host, int port) throws Exception {
   server = new Server();
   ServerConnector connector = new ServerConnector(server);
   connector.setHost(host);
   connector.setPort(port);
   server.setConnectors(new Connector[]{connector});

   handlers = new HandlerList();

   server.setHandler(handlers);
   return server;
}
 
Example #24
Source File: JettyStarter.java    From scheduling with GNU Affero General Public License v3.0 5 votes vote down vote up
private List<String> printDeployedApplications(Server server, String schedulerHost, int restPort,
        String httpProtocol) {
    HandlerList handlerList = (HandlerList) server.getHandler();
    ArrayList<String> applicationsUrls = new ArrayList<>();
    if (handlerList.getHandlers() != null) {
        for (Handler handler : handlerList.getHandlers()) {
            if (!(handler instanceof WebAppContext)) {
                continue;
            }

            WebAppContext webAppContext = (WebAppContext) handler;
            Throwable startException = webAppContext.getUnavailableException();
            if (startException == null) {
                if (!"/".equals(webAppContext.getContextPath())) {
                    String applicationUrl = getApplicationUrl(httpProtocol, schedulerHost, restPort, webAppContext);
                    applicationsUrls.add(applicationUrl);
                    logger.info("The web application " + webAppContext.getContextPath() + " created on " +
                                applicationUrl);
                }
            } else {
                logger.warn("Failed to start context " + webAppContext.getContextPath(), startException);
            }
        }
        logger.info("*** Get started at " + httpProtocol + "://" + schedulerHost + ":" + restPort + " ***");
    }
    return applicationsUrls;
}
 
Example #25
Source File: Main.java    From stepic_java_webserver with MIT License 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    if (args.length != 1) {
        logger.error("Use port as the first argument");
        System.exit(1);
    }

    String portString = args[0];
    int port = Integer.valueOf(portString);

    logger.info("Starting at http://127.0.0.1:" + portString);

    AccountServerI accountServer = new AccountServer(1);

    AccountServerControllerMBean serverStatistics = new AccountServerController(accountServer);
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    ObjectName name = new ObjectName("ServerManager:type=AccountServerController");
    mbs.registerMBean(serverStatistics, name);

    Server server = new Server(port);
    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
    context.addServlet(new ServletHolder(new HomePageServlet(accountServer)), HomePageServlet.PAGE_URL);

    ResourceHandler resource_handler = new ResourceHandler();
    resource_handler.setDirectoriesListed(true);
    resource_handler.setResourceBase("static");

    HandlerList handlers = new HandlerList();
    handlers.setHandlers(new Handler[]{resource_handler, context});
    server.setHandler(handlers);

    server.start();
    logger.info("Server started");

    server.join();
}
 
Example #26
Source File: JettyStarter.java    From scheduling with GNU Affero General Public License v3.0 5 votes vote down vote up
private void addGetStartedApplication(HandlerList handlerList, File file, String[] virtualHost) {
    if (file.exists()) {
        String contextPath = "/";
        WebAppContext webApp = createWebAppContext(contextPath, virtualHost);
        webApp.setWar(file.getAbsolutePath());
        handlerList.addHandler(webApp);
    }
}
 
Example #27
Source File: JettyStarter.java    From scheduling with GNU Affero General Public License v3.0 5 votes vote down vote up
private void addStaticFolder(HandlerList handlerList, File file, String[] virtualHost) {
    String contextPath = "/" + file.getName();
    WebAppContext webApp = createWebAppContext(contextPath, virtualHost);
    webApp.setWar(file.getAbsolutePath());
    handlerList.addHandler(webApp);
    logger.debug("Deploying " + contextPath + " using folder " + file);
}
 
Example #28
Source File: JettyStarter.java    From scheduling with GNU Affero General Public License v3.0 5 votes vote down vote up
private void addExplodedWebApp(HandlerList handlerList, File file, String[] virtualHost) {
    String contextPath = "/" + file.getName();
    WebAppContext webApp = createWebAppContext(contextPath, virtualHost);

    // Don't scan classes for annotations. Saves 1 second at startup.
    webApp.setAttribute("org.eclipse.jetty.server.webapp.WebInfIncludeJarPattern", "^$");
    webApp.setAttribute("org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern", "^$");

    webApp.setDescriptor(new File(file, "/WEB-INF/web.xml").getAbsolutePath());
    webApp.setResourceBase(file.getAbsolutePath());
    handlerList.addHandler(webApp);
    logger.debug("Deploying " + contextPath + " using exploded war " + file);
}
 
Example #29
Source File: JettyStarter.java    From scheduling with GNU Affero General Public License v3.0 5 votes vote down vote up
private void addWarFile(HandlerList handlerList, File file, String[] virtualHost) {
    String contextPath = "/" + FilenameUtils.getBaseName(file.getName());
    WebAppContext webApp = createWebAppContext(contextPath, virtualHost);
    webApp.setWar(file.getAbsolutePath());
    handlerList.addHandler(webApp);
    logger.debug("Deploying " + contextPath + " using war file " + file);
}
 
Example #30
Source File: BaleenWebApi.java    From baleen with Apache License 2.0 5 votes vote down vote up
private void installWars(HandlerList handlers, List<Object> wars) {
  // NOTE: There is no security (via webauth) applied to this at present
  if (wars == null || wars.isEmpty()) {
    return;
  }

  for (Object war : wars) {
    String file = null;
    String context = null;

    if (war instanceof String) {
      LOGGER.debug("Adding shorthand described WAR");

      file = (String) war;
      context = (String) war;
      if (context.toLowerCase().endsWith(".war")) {
        context = context.substring(0, context.length() - 4);
      }

      installWar(handlers, file, context);
    } else if (war instanceof Map) {
      LOGGER.debug("Adding fully described WAR");

      try {
        @SuppressWarnings("unchecked")
        Map<String, Object> warDesc = (Map<String, Object>) war;
        file = (String) warDesc.get("file");
        context = (String) warDesc.get("context");
      } catch (ClassCastException cce) {
        LOGGER.warn("Malformed WAR configuration; skipping", cce);
        file = null;
      }

      installWar(handlers, file, context);
    } else {
      LOGGER.warn("Unexpected WAR configuration found; skipping");
    }
  }
}