예제 #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();
    }
  }
예제 #2
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);
 }
예제 #3
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"));
  }
예제 #4
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();
    }
  }
예제 #5
0
  @Override
  public void construct() {
    tomcat = new Tomcat();

    Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
    connector.setURIEncoding("UTF-8");
    connector.setPort(5000);
    tomcat.getService().addConnector(connector);
    tomcat.setConnector(connector);

    try {
      Context ctx;

      if (new File(Configuration.WEBROOT_PATH).exists()) {
        L.i("Static web client found.");

        ctx = tomcat.addContext("", Configuration.WEBROOT_PATH);
        ctx.addWelcomeFile("index.html");

        Wrapper wrapper = tomcat.addServlet(ctx, "DefaultServlet", new DefaultServlet());
        wrapper.setAsyncSupported(true);
        wrapper.addInitParameter("listings", "false");
        wrapper.addMapping("/");
        wrapper.setLoadOnStartup(1);
      } else {
        L.w("No static web client found, web interface will not be available.");
        ctx = tomcat.addContext("/", "/tmp");
      }

      configureMimeMappings(ctx);

      addSessionFilter(ctx);
      addCharacterEncodingFilter(ctx);

      Wrapper wrapper = tomcat.addServlet(ctx, "JerseyServlet", new ServletContainer());
      wrapper.setAsyncSupported(true);
      wrapper.addInitParameter("javax.ws.rs.Application", JerseyApplication.class.getName());
      wrapper.addMapping("/api/*");
      wrapper.setLoadOnStartup(1);

      tomcat.start();
    } catch (Exception e) {
      L.e("Failed to start RestApiModule.", e);
    }
  }
예제 #6
0
 private static void configureHttpsConnector(Tomcat tomcat, TomcatConfig tomcatConfig) {
   Connector connector = new Connector();
   connector.setProperty("server", "jlot");
   connector.setPort(tomcatConfig.getSslPort());
   connector.setSecure(true);
   connector.setEnableLookups(false);
   connector.setScheme("https");
   connector.setAttribute("SSLEnabled", true);
   File file = new File("../kicktipp.org.keystore");
   String keystoreFile = file.getAbsolutePath();
   connector.setAttribute("keystoreFile", keystoreFile);
   connector.setAttribute("keyAlias", "tomcat");
   connector.setAttribute("keystorePass", "tomcat");
   connector.setAttribute("clientAuth", "false");
   connector.setAttribute("sslProtocol", "TLS");
   addCompression(connector);
   tomcat.getService().addConnector(connector);
 }
예제 #7
0
파일: Server.java 프로젝트: jcooky/troll
  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();
  }
예제 #8
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;
  }