JawrIntegrationServer() {

    Properties prop = new Properties();
    InputStream inStream = getClass().getClassLoader().getResourceAsStream(PROP_FILE_NAME);
    if (inStream != null) {
      try {
        prop.load(inStream);
      } catch (IOException e) {
        throw new RuntimeException(e);
      }
      IOUtils.closeQuietly(inStream);
    }

    serverPort = Integer.parseInt(prop.getProperty(PORT_PROPERTY_NAME, DEFAULT_PORT));
    server = new Server(serverPort);
    // Setup JMX
    MBeanContainer mbContainer = new MBeanContainer(ManagementFactory.getPlatformMBeanServer());
    server.addEventListener(mbContainer);
    server.addBean(mbContainer);

    try {

      String host = "localhost";
      int jmxPort = 1099;
      String urlPath = String.format("/jndi/rmi://%s:%s/jmxrmi", host, jmxPort);
      JMXServiceURL serviceURL = new JMXServiceURL("rmi", host, jmxPort, urlPath);
      ConnectorServer connectorServer =
          new ConnectorServer(serviceURL, "org.eclipse.jetty.jmx:name=rmiconnectorserver");
      connectorServer.start();
    } catch (Exception e) {
      throw new RuntimeException(e);
    }

    server.setStopAtShutdown(true);
    String webappName = prop.getProperty(WEBAPP_PROPERTY_NAME, DEFAULT_WEBAPP_NAME);
    try {
      webAppRootDir = new File(TARGET_ROOT_DIR + webappName).getCanonicalFile().getAbsolutePath();
    } catch (IOException e) {
      throw new RuntimeException(e);
    }

    boolean useEmptyContextPath =
        Boolean.parseBoolean(
            prop.getProperty(
                USE_DEFAULT_CONTEXT_PATH_PROPERTY_NAME, DONT_USE_DEFAULT_CONTEXT_PATH));
    String webAppCtx = "";
    if (!useEmptyContextPath) {
      webAppCtx = "/" + webappName;
    }

    jettyWebAppContext = new WebAppContext(webAppRootDir, webAppCtx);
    jettyWebAppContext.setConfigurationClasses(
        new String[] {
          "org.eclipse.jetty.webapp.WebInfConfiguration",
          "org.eclipse.jetty.webapp.WebXmlConfiguration",
          "org.eclipse.jetty.webapp.JettyWebXmlConfiguration",
          "org.eclipse.jetty.annotations.AnnotationConfiguration"
        });

    ContextHandlerCollection contextHandlerCollection = new ContextHandlerCollection();
    contextHandlerCollection.setHandlers(new Handler[] {jettyWebAppContext});
    server.setHandler(contextHandlerCollection);
  }
Пример #2
0
  /**
   * Main function, starts the jetty server.
   *
   * @param args
   */
  public static void main(String[] args) {
    System.setProperty("wicket.configuration", "development");

    Server server = new Server();

    HttpConfiguration http_config = new HttpConfiguration();
    http_config.setSecureScheme("https");
    http_config.setSecurePort(8443);
    http_config.setOutputBufferSize(32768);

    ServerConnector http = new ServerConnector(server, new HttpConnectionFactory(http_config));
    http.setPort(8080);
    http.setIdleTimeout(1000 * 60 * 60);

    server.addConnector(http);

    Resource keystore = Resource.newClassPathResource("/keystore");
    if (keystore != null && keystore.exists()) {
      // if a keystore for a SSL certificate is available, start a SSL
      // connector on port 8443.
      // By default, the quickstart comes with a Apache Wicket Quickstart
      // Certificate that expires about half way september 2021. Do not
      // use this certificate anywhere important as the passwords are
      // available in the source.

      SslContextFactory sslContextFactory = new SslContextFactory();
      sslContextFactory.setKeyStoreResource(keystore);
      sslContextFactory.setKeyStorePassword("wicket");
      sslContextFactory.setKeyManagerPassword("wicket");

      HttpConfiguration https_config = new HttpConfiguration(http_config);
      https_config.addCustomizer(new SecureRequestCustomizer());

      ServerConnector https =
          new ServerConnector(
              server,
              new SslConnectionFactory(sslContextFactory, "http/1.1"),
              new HttpConnectionFactory(https_config));
      https.setPort(8443);
      https.setIdleTimeout(500000);

      server.addConnector(https);
      System.out.println("SSL access to the examples has been enabled on port 8443");
      System.out.println("You can access the application using SSL on https://localhost:8443");
      System.out.println();
    }

    WebAppContext bb = new WebAppContext();
    bb.setServer(server);
    bb.setContextPath("/");
    bb.setWar("src/main/webapp");

    // uncomment next line if you want to test with JSESSIONID encoded in the urls
    // ((AbstractSessionManager)
    // bb.getSessionHandler().getSessionManager()).setUsingCookies(false);

    server.setHandler(bb);

    MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
    MBeanContainer mBeanContainer = new MBeanContainer(mBeanServer);
    server.addEventListener(mBeanContainer);
    server.addBean(mBeanContainer);

    try {
      server.start();
      server.join();
    } catch (Exception e) {
      e.printStackTrace();
      System.exit(100);
    }
  }