Exemplo n.º 1
0
  private static void initIdp() {
    try {
      idpServer = new Tomcat();
      idpServer.setPort(0);
      String currentDir = new File(".").getCanonicalPath();
      idpServer.setBaseDir(currentDir + File.separator + "target");

      idpServer.getHost().setAppBase("tomcat/idp/webapps");
      idpServer.getHost().setAutoDeploy(true);
      idpServer.getHost().setDeployOnStartup(true);

      Connector httpsConnector = new Connector();
      httpsConnector.setPort(Integer.parseInt(idpHttpsPort));
      httpsConnector.setSecure(true);
      httpsConnector.setScheme("https");
      // httpsConnector.setAttribute("keyAlias", keyAlias);
      httpsConnector.setAttribute("keystorePass", "tompass");
      httpsConnector.setAttribute("keystoreFile", "test-classes/server.jks");
      httpsConnector.setAttribute("truststorePass", "tompass");
      httpsConnector.setAttribute("truststoreFile", "test-classes/server.jks");
      httpsConnector.setAttribute("clientAuth", "want");
      // httpsConnector.setAttribute("clientAuth", "false");
      httpsConnector.setAttribute("sslProtocol", "TLS");
      httpsConnector.setAttribute("SSLEnabled", true);

      idpServer.getService().addConnector(httpsConnector);

      idpServer.addWebapp("/fediz-idp-sts", "fediz-idp-sts");
      idpServer.addWebapp("/fediz-idp", "fediz-idp");

      idpServer.start();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Exemplo n.º 2
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.º 3
0
  public static void main(String[] args) throws Exception {
    int port = 7070;
    if (args.length >= 1) {
      port = Integer.parseInt(args[0]);
    }

    // test_case_data/sandbox/ contains HDP 2.2 site xmls which is dev sandbox
    ClasspathUtil.addClasspath(new File("../examples/test_case_data/sandbox").getAbsolutePath());
    System.setProperty(KylinConfig.KYLIN_CONF, "../examples/test_case_data/sandbox");
    System.setProperty("hdp.version", "2.2.0.0-2041"); // mapred-site.xml ref this

    // workaround for job submission from win to linux --
    // https://issues.apache.org/jira/browse/MAPREDUCE-4052
    if (Shell.WINDOWS) {
      {
        Field field = Shell.class.getDeclaredField("WINDOWS");
        field.setAccessible(true);
        Field modifiersField = Field.class.getDeclaredField("modifiers");
        modifiersField.setAccessible(true);
        modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
        field.set(null, false);
      }
      {
        Field field = java.io.File.class.getDeclaredField("pathSeparator");
        field.setAccessible(true);
        Field modifiersField = Field.class.getDeclaredField("modifiers");
        modifiersField.setAccessible(true);
        modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
        field.set(null, ":");
      }
    }

    System.setProperty("spring.profiles.active", "testing");
    String webBase = new File("../webapp/app").getAbsolutePath();
    if (new File(webBase, "WEB-INF").exists() == false) {
      throw new RuntimeException(
          "In order to launch Kylin web app from IDE, please make a symblink from webapp/app/WEB-INF to server/src/main/webapp/WEB-INF");
    }

    Tomcat tomcat = new Tomcat();
    tomcat.setPort(port);
    tomcat.setBaseDir(".");

    // Add AprLifecycleListener
    StandardServer server = (StandardServer) tomcat.getServer();
    AprLifecycleListener listener = new AprLifecycleListener();
    server.addLifecycleListener(listener);

    Context webContext = tomcat.addWebapp("/kylin", webBase);
    ErrorPage notFound = new ErrorPage();
    notFound.setErrorCode(404);
    notFound.setLocation("/index.html");
    webContext.addErrorPage(notFound);
    webContext.addWelcomeFile("index.html");

    // tomcat start
    tomcat.start();
    tomcat.getServer().await();
  }
Exemplo n.º 4
0
  public void start() throws Exception {
    prepareWebApplication();

    String workingDir = System.getProperty("java.io.tmpdir");

    tomcat = new Tomcat();
    tomcat.setPort(8080);
    tomcat.setBaseDir(workingDir);
    tomcat.addWebapp("/", webRoot.getAbsolutePath());

    tomcat.start();
  }
Exemplo n.º 5
0
  public void launch() throws Exception {
    this.configurarProperties();
    final Tomcat server = new Tomcat();
    server.setPort(this.puerto);
    server.setBaseDir(this.baseDir);

    server.getHost().setAppBase(this.appBase);
    server.getHost().setAutoDeploy(true);
    server.getHost().setDeployOnStartup(true);
    server.addWebapp(this.nameSpace, this.warName + ".war");
    server.start();
  }
Exemplo n.º 6
0
  @Before
  @Override
  public void setUp() throws Exception {
    super.setUp();

    // Trigger loading of catalina.properties
    CatalinaProperties.getProperty("foo");

    File appBase = new File(getTemporaryDirectory(), "webapps");
    if (!appBase.exists() && !appBase.mkdir()) {
      fail("Unable to create appBase for test");
    }

    tomcat = new TomcatWithFastSessionIDs();

    String protocol = getProtocol();
    Connector connector = new Connector(protocol);
    // Listen only on localhost
    connector.setAttribute("address", InetAddress.getByName("localhost").getHostAddress());
    // Use random free port
    connector.setPort(0);
    // Mainly set to reduce timeouts during async tests
    connector.setAttribute("connectionTimeout", "3000");
    tomcat.getService().addConnector(connector);
    tomcat.setConnector(connector);

    // Add AprLifecycleListener if we are using the Apr connector
    if (protocol.contains("Apr")) {
      StandardServer server = (StandardServer) tomcat.getServer();
      AprLifecycleListener listener = new AprLifecycleListener();
      listener.setSSLRandomSeed("/dev/urandom");
      server.addLifecycleListener(listener);
      connector.setAttribute("pollerThreadCount", Integer.valueOf(1));
    }

    File catalinaBase = getTemporaryDirectory();
    tomcat.setBaseDir(catalinaBase.getAbsolutePath());
    tomcat.getHost().setAppBase(appBase.getAbsolutePath());

    accessLogEnabled = Boolean.parseBoolean(System.getProperty("tomcat.test.accesslog", "false"));
    if (accessLogEnabled) {
      AccessLogValve alv = new AccessLogValve();
      alv.setDirectory(getBuildDirectory() + "/logs");
      alv.setPattern("%h %l %u %t \"%r\" %s %b %I %D");
      tomcat.getHost().getPipeline().addValve(alv);
    }

    // Cannot delete the whole tempDir, because logs are there,
    // but delete known subdirectories of it.
    addDeleteOnTearDown(new File(catalinaBase, "webapps"));
    addDeleteOnTearDown(new File(catalinaBase, "work"));
  }
Exemplo n.º 7
0
  private static void initRp() {
    try {
      rpServer = new Tomcat();
      rpServer.setPort(0);
      String currentDir = new File(".").getCanonicalPath();
      rpServer.setBaseDir(currentDir + File.separator + "target");

      rpServer.getHost().setAppBase("tomcat/rp/webapps");
      rpServer.getHost().setAutoDeploy(true);
      rpServer.getHost().setDeployOnStartup(true);

      Connector httpsConnector = new Connector();
      httpsConnector.setPort(Integer.parseInt(rpHttpsPort));
      httpsConnector.setSecure(true);
      httpsConnector.setScheme("https");
      // httpsConnector.setAttribute("keyAlias", keyAlias);
      httpsConnector.setAttribute("keystorePass", "tompass");
      httpsConnector.setAttribute("keystoreFile", "test-classes/server.jks");
      httpsConnector.setAttribute("truststorePass", "tompass");
      httpsConnector.setAttribute("truststoreFile", "test-classes/server.jks");
      // httpsConnector.setAttribute("clientAuth", "false");
      httpsConnector.setAttribute("clientAuth", "want");
      httpsConnector.setAttribute("sslProtocol", "TLS");
      httpsConnector.setAttribute("SSLEnabled", true);

      rpServer.getService().addConnector(httpsConnector);

      // Context ctx =
      Context cxt = rpServer.addWebapp("/fedizhelloworld", "simpleWebapp");
      FederationAuthenticator fa = new FederationAuthenticator();
      fa.setConfigFile(
          currentDir
              + File.separator
              + "target"
              + File.separator
              + "test-classes"
              + File.separator
              + "fediz_config.xml");
      cxt.getPipeline().addValve(fa);

      rpServer.start();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Exemplo n.º 8
0
 @Override
 public EmbeddedServletContainer getEmbeddedServletContainer(
     ServletContextInitializer... initializers) {
   Tomcat tomcat = new Tomcat();
   File baseDir = (this.baseDirectory != null ? this.baseDirectory : createTempDir("tomcat"));
   tomcat.setBaseDir(baseDir.getAbsolutePath());
   Connector connector = new Connector(this.protocol);
   tomcat.getService().addConnector(connector);
   customizeConnector(connector);
   tomcat.setConnector(connector);
   tomcat.getHost().setAutoDeploy(false);
   tomcat.getEngine().setBackgroundProcessorDelay(-1);
   for (Connector additionalConnector : this.additionalTomcatConnectors) {
     tomcat.getService().addConnector(additionalConnector);
   }
   prepareContext(tomcat.getHost(), initializers);
   return getTomcatEmbeddedServletContainer(tomcat);
 }
Exemplo n.º 9
0
  public static void main(String[] args) throws Exception {

    final Tomcat tomcat = new Tomcat();
    tomcat.setBaseDir("."); // location where temp dir is created
    tomcat.setPort(8080);

    // configure context
    final File applicationPath = new File("./webapp"); // todo: change to your location
    Context rootContext =
        tomcat.addContext("/", "C:\\Users\\Ali\\git\\finder\\finder\\src\\main\\webapp");
    rootContext.addLifecycleListener(new ContextConfig());

    // JSP and Default Servlet setup, mime type mapping and welcome files
    Tomcat.initWebappDefaults(rootContext);

    // start server
    tomcat.start();
    tomcat.getServer().await();
  }
Exemplo n.º 10
0
  @BeforeClass
  public static void initTomcat() throws Exception {
    tomcat = new Tomcat();
    String baseDir = getBaseDirectory();
    tomcat.setBaseDir(baseDir);
    tomcat.setPort(8082);

    System.setProperty("app.server.base.url", "http://localhost:8082");
    System.setProperty("my.host.name", "localhost");
    URL dir = Tomcat7Test.class.getResource("/adapter-test/demorealm.json");
    File base = new File(dir.getFile()).getParentFile();
    tomcat.addWebapp("/customer-portal", new File(base, "customer-portal").toString());
    tomcat.addWebapp("/customer-db", new File(base, "customer-db").toString());
    tomcat.addWebapp("/product-portal", new File(base, "product-portal").toString());
    tomcat.addWebapp("/secure-portal", new File(base, "secure-portal").toString());
    tomcat.addWebapp("/session-portal", new File(base, "session-portal").toString());
    tomcat.addWebapp("/input-portal", new File(base, "input-portal").toString());

    tomcat.start();
    // tomcat.getServer().await();
  }
Exemplo n.º 11
0
  /**
   * Start the instance using the ports provided
   *
   * @param port the http port to use
   * @param securePort the secure https port to use
   */
  @SuppressWarnings("unchecked")
  public T start(final Integer port, final Integer securePort) {
    if (port == null && securePort == null)
      throw new IllegalStateException("You must specify a port or a secure port");
    if (isRunning()) throw new IllegalStateException("Server already running");
    final String startedMessage =
        "Started "
            + this.getClass().getSimpleName().replace("Runner", "")
            + " listening on:"
            + (port != null ? " standard port " + port : "")
            + (securePort != null ? " secure port " + securePort : "");

    try {
      String servletContext = "";

      tomcat = new Tomcat();
      tomcat.setBaseDir(
          new File(".").getCanonicalPath()
              + File.separatorChar
              + "tomcat"
              + (servletContext.length() > 0 ? "_" + servletContext : ""));

      // add http port
      tomcat.setPort(port != null ? port : securePort);

      if (securePort != null) {
        // add https connector
        SSLFactory.buildKeyStore();
        Connector httpsConnector = new Connector();
        httpsConnector.setPort(securePort);
        httpsConnector.setSecure(true);
        httpsConnector.setAttribute("keyAlias", SSLFactory.KEY_STORE_ALIAS);
        httpsConnector.setAttribute("keystorePass", SSLFactory.KEY_STORE_PASSWORD);
        logger.trace(
            "Loading key store from file ["
                + new File(SSLFactory.KEY_STORE_FILENAME).getAbsoluteFile()
                + "]");
        httpsConnector.setAttribute(
            "keystoreFile", new File(SSLFactory.KEY_STORE_FILENAME).getAbsoluteFile());
        httpsConnector.setAttribute("clientAuth", "false");
        httpsConnector.setAttribute("sslProtocol", "TLS");
        httpsConnector.setAttribute("SSLEnabled", true);

        Service service = tomcat.getService();
        service.addConnector(httpsConnector);

        Connector defaultConnector = tomcat.getConnector();
        defaultConnector.setRedirectPort(securePort);
      }

      // add servlet
      Context ctx = tomcat.addContext("/" + servletContext, new File(".").getAbsolutePath());
      tomcat.addServlet("/" + servletContext, "mockServerServlet", getServlet());
      ctx.addServletMapping("/*", "mockServerServlet");

      // start server
      tomcat.start();

      // create and start shutdown thread
      shutdownThread = new ShutdownThread(stopPort(port, securePort));
      shutdownThread.start();
      serverStarted(port, securePort);

      logger.info(startedMessage);
      System.out.println(startedMessage);

      join();
    } catch (Throwable t) {
      logger.error("Exception while starting server", t);
    }

    return (T) this;
  }