Exemplo n.º 1
0
  public static Tomcat startServer(final TomcatConfig tomcatConfig) throws Exception {
    final Tomcat tomcat = new Tomcat();

    Map<String, String> map = tomcatConfig.getProperties();
    for (String key : map.keySet()) {
      System.setProperty(key, map.get(key));
    }

    tomcat.setBaseDir("./target/tomcat");
    tomcat.setSilent(true);
    // um zu verhindern dass sich die jmx namen mit www/info überschneiden
    tomcat.getEngine().setName(tomcatConfig.getName());
    configureHttpConnector(tomcat, tomcatConfig);
    configureHttpsConnector(tomcat, tomcatConfig);
    // jndi wird gestartet, sonst bekommen wir eine hässliche Warnung, weil
    // wir in der HibernateConfig das Property
    // hibernate.session_factory_name setzen
    tomcat.enableNaming();
    String absolutePath = new File(tomcatConfig.getPath()).getAbsolutePath();
    Context context = tomcat.addWebapp("", absolutePath);
    VirtualWebappLoader virtualWebappLoader = new VirtualWebappLoader();
    virtualWebappLoader.setVirtualClasspath("../jlot-web/target/classes");
    context.setLoader(virtualWebappLoader);
    context.setUseHttpOnly(false);
    tomcat.getServer().addLifecycleListener(new TomcatStartupTimeLogger(tomcatConfig.getName()));
    tomcat.start();
    new TomcatRunThread(tomcat).start();
    return tomcat;
  }
Exemplo n.º 2
0
  @Test
  public void testBug54379() throws Exception {
    Tomcat tomcat = getTomcatInstance();

    File appDir = new File("test/webapp-fragments");
    Context context = tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());

    Tomcat.addServlet(
        context, "TestServlet", "org.apache.catalina.startup.TesterServletWithLifeCycleMethods");
    context.addServletMapping("/testServlet", "TestServlet");

    tomcat.enableNaming();

    tomcat.start();

    assertPageContains("/test/testServlet", "postConstruct1()");
  }
Exemplo n.º 3
0
  @Test
  public void testBug54448and54450() throws Exception {
    Tomcat tomcat = getTomcatInstance();

    File appDir = new File("test/webapp-fragments");
    Context context = tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());

    Tomcat.addServlet(
        context, "TestServlet", "org.apache.catalina.startup.TesterServletWithAnnotations");
    context.addServletMapping("/testServlet", "TestServlet");

    tomcat.enableNaming();

    tomcat.start();

    assertPageContains(
        "/test/testServlet",
        "envEntry1: 1 envEntry2: 2 envEntry3: 33 envEntry4: 4 envEntry5: 55 envEntry6: 66");
  }
Exemplo n.º 4
0
  public static void main(String[] args) throws Exception {
    String webappDirLocation = "src/main/webapp/";
    Tomcat tomcat = new Tomcat();

    // The port that we should run on can be set into an environment variable
    // Look for that variable and default to 8080 if it isn't there.
    String webPort = System.getenv("PORT");
    if (webPort == null || webPort.isEmpty()) {
      webPort = "8080";
    }

    tomcat.setPort(Integer.valueOf(webPort));
    tomcat.enableNaming();

    Connector connector = new Connector(MinaProtocol.class.getName());
    connector.setPort(8090);
    tomcat.getService().addConnector(connector);

    Context ctx = tomcat.addWebapp("/", new File(webappDirLocation).getAbsolutePath());
    ((StandardJarScanner) ctx.getJarScanner()).setScanAllDirectories(true);

    tomcat.start();
    tomcat.getServer().await();
  }