Java 类org.eclipse.jetty.server.ssl.SslSocketConnector 实例源码

项目:i2p.plugins.i2pcontrol    文件:I2PControlController.java   
/**
 * Creates a SSLListener with all the default options. The listener will use all the default options.
 * @param address - The address the listener will listen to.
 * @param port - The port the listener will listen to.
 * @return - Newly created listener
 * @throws UnknownHostException
 */
public static SslSocketConnector buildSslListener(String address, int port) throws UnknownHostException {
    int listeners = 0;
    if (_server != null) {
        listeners = _server.getConnectors().length;
    }

    SslSocketConnector ssl = new SslSocketConnector();
    ssl.setProvider(_secMan.getSecurityProvider());
    //ssl.setCipherSuites(_secMan.getSupprtedSSLCipherSuites()); Removed in Jetty 5->6 port.
    ssl.setHost(address);
    ssl.setPort(port);
    ssl.setWantClientAuth(false); // Don't care about client authentication.
    ssl.setPassword(KeyStoreProvider.DEFAULT_KEYSTORE_PASSWORD);
    ssl.setKeyPassword(KeyStoreProvider.DEFAULT_KEYSTORE_PASSWORD);
    ssl.setKeystoreType(KeyStore.getDefaultType());
    ssl.setKeystore(KeyStoreProvider.getKeyStoreLocation());
    ssl.setName("SSL Listener-" + ++listeners);

    return ssl;
}
项目:h2o-3    文件:AbstractHTTPD.java   
/**
 * This implementation is based on http://blog.denevell.org/jetty-9-ssl-https.html
 *
 * @throws Exception
 */
private void startHttps() throws Exception {
  _server = new Server();

  SslContextFactory sslContextFactory = new SslContextFactory(_args.jks);
  sslContextFactory.setKeyStorePassword(_args.jks_pass);

  SslSocketConnector httpsConnector = new SslSocketConnector(sslContextFactory);

  if (getIp() != null) {
    httpsConnector.setHost(getIp());
  }
  httpsConnector.setPort(getPort());

  createServer(httpsConnector);
}
项目:freedomotic    文件:ApplicationServer.java   
/**
 * Enables SSL
 * 
 */
private void enableSSL() {
    String keyStorePath = this.getFile().getParent() + "/data/" + keystoreFile;
    try (FileInputStream keyStoreInputStream = new FileInputStream(keyStorePath)) {
        KeyStore keyStore = KeyStore.getInstance(keystoreType);
        keyStore.load(keyStoreInputStream, keystorePassword.toCharArray());
        SslContextFactory sslContextFactory = new SslContextFactory();
        sslContextFactory.setKeyStore(keyStore);
        sslContextFactory.setKeyStorePassword(keystorePassword);
        sslContextFactory.setKeyStoreType(keystoreType);
        SslSocketConnector sslConnector = new SslSocketConnector(sslContextFactory);
        sslConnector.setPort(sslPort);
        sslConnector.setMaxIdleTime(30000);
        LOG.info("Webserver now listens on SSL port {}", sslPort);
        server.addConnector(sslConnector);
    } catch (Exception ex) {
        LOG.error("Cannot load java keystore for reason: ", Freedomotic.getStackTraceInfo(ex));
    }
}
项目:little_mitm    文件:TestUtils.java   
/**
 * Finds the port the specified server is listening for HTTP connections on.
 *
 * @param webServer started web server
 * @return HTTP port, or -1 if no HTTP port was found
 */
public static int findLocalHttpPort(Server webServer) {
    for (Connector connector : webServer.getConnectors()) {
        if (!(connector instanceof SslSocketConnector)) {
            return connector.getLocalPort();
        }
    }

    return -1;
}
项目:little_mitm    文件:TestUtils.java   
/**
 * Finds the port the specified server is listening for HTTPS connections on.
 *
 * @param webServer started web server
 * @return HTTP port, or -1 if no HTTPS port was found
 */
public static int findLocalHttpsPort(Server webServer) {
    for (Connector connector : webServer.getConnectors()) {
        if (connector instanceof SslSocketConnector) {
            return connector.getLocalPort();
        }
    }

    return -1;
}
项目:opennmszh    文件:JettyServer.java   
public long getHttpsConnectionsTotal() {
    long retval = 0;
    for (Connector conn : m_server.getConnectors()) {
        if (conn instanceof SslSocketConnector) {
            retval += conn.getConnections();
        }
    }
    return retval;
}
项目:opennmszh    文件:JettyServer.java   
public long getHttpsConnectionsOpen() {
    long retval = 0;
    for (Connector conn : m_server.getConnectors()) {
        if (conn instanceof SslSocketConnector) {
            retval += conn.getConnectionsOpen();
        }
    }
    return retval;
}
项目:opennmszh    文件:JettyServer.java   
public long getHttpsConnectionsOpenMax() {
    long retval = 0;
    for (Connector conn : m_server.getConnectors()) {
        if (conn instanceof SslSocketConnector) {
            retval += conn.getConnectionsOpenMax();
        }
    }
    return retval;
}
项目:pentaho-kettle    文件:WebServer.java   
private SocketConnector getConnector() {
  if ( sslConfig != null ) {
    log.logBasic( BaseMessages.getString( PKG, "WebServer.Log.SslModeUsing" ) );
    SslSocketConnector connector = new SslSocketConnector();
    connector.setKeystore( sslConfig.getKeyStore() );
    connector.setPassword( sslConfig.getKeyStorePassword() );
    connector.setKeyPassword( sslConfig.getKeyPassword() );
    connector.setKeystoreType( sslConfig.getKeyStoreType() );
    return connector;
  } else {
    return new SocketConnector();
  }

}
项目:ansible-docker-talk    文件:Start.java   
public static void main(String[] args) throws Exception {
    int timeout = (int) Duration.ONE_HOUR.getMilliseconds();

    Server server = new Server();
    SocketConnector connector = new SocketConnector();

    // Set some timeout options to make debugging easier.
    connector.setMaxIdleTime(timeout);
    connector.setSoLingerTime(-1);
    connector.setPort(8080);
    server.addConnector(connector);

    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.

        connector.setConfidentialPort(8443);

        SslContextFactory factory = new SslContextFactory();
        factory.setKeyStoreResource(keystore);
        factory.setKeyStorePassword("wicket");
        factory.setTrustStoreResource(keystore);
        factory.setKeyManagerPassword("wicket");
        SslSocketConnector sslConnector = new SslSocketConnector(factory);
        sslConnector.setMaxIdleTime(timeout);
        sslConnector.setPort(8443);
        sslConnector.setAcceptors(4);
        server.addConnector(sslConnector);

        System.out.println("SSL access to the quickstart 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");

    // START JMX SERVER
    // MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
    // MBeanContainer mBeanContainer = new MBeanContainer(mBeanServer);
    // server.getContainer().addEventListener(mBeanContainer);
    // mBeanContainer.start();

    server.setHandler(bb);

    try {
        System.out.println(">>> STARTING EMBEDDED JETTY SERVER, PRESS ANY KEY TO STOP");
        server.start();
        System.in.read();
        System.out.println(">>> STOPPING EMBEDDED JETTY SERVER");
        server.stop();
        server.join();
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(1);
    }
}
项目:vlo-curation    文件:Start.java   
public static void main(String[] args) throws Exception {
    int timeout = (int) Duration.ONE_HOUR.getMilliseconds();

    Server server = new Server();
    SocketConnector connector = new SocketConnector();

    // Set some timeout options to make debugging easier.
    connector.setMaxIdleTime(timeout);
    connector.setSoLingerTime(-1);
    connector.setPort(8090);
    server.addConnector(connector);

    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.

        connector.setConfidentialPort(8443);

        SslContextFactory factory = new SslContextFactory();
        factory.setKeyStoreResource(keystore);
        factory.setKeyStorePassword("wicket");
        factory.setTrustStoreResource(keystore);
        factory.setKeyManagerPassword("wicket");
        SslSocketConnector sslConnector = new SslSocketConnector(factory);
        sslConnector.setMaxIdleTime(timeout);
        sslConnector.setPort(8443);
        sslConnector.setAcceptors(4);
        server.addConnector(sslConnector);

        System.out.println("SSL access to the quickstart 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");

    // START JMX SERVER
    // MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
    // MBeanContainer mBeanContainer = new MBeanContainer(mBeanServer);
    // server.getContainer().addEventListener(mBeanContainer);
    // mBeanContainer.start();

    server.setHandler(bb);

    try {
        System.out.println(">>> STARTING EMBEDDED JETTY SERVER, PRESS ANY KEY TO STOP");
        server.start();
        System.in.read();
        System.out.println(">>> STOPPING EMBEDDED JETTY SERVER");
        server.stop();
        server.join();
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(1);
    }
}
项目:little_mitm    文件:TestUtils.java   
/**
 * Creates and starts an embedded web server on JVM-assigned HTTP and HTTPS ports.
 * Each response has a body that indicates how many bytes were received with a message like
 * "Received x bytes\n".
 *
 * @param enableHttps if true, an HTTPS connector will be added to the web server
 * @return Instance of Server
 */
public static Server startWebServer(boolean enableHttps) {
    final Server httpServer = new Server(0);

    httpServer.setHandler(new AbstractHandler() {
        public void handle(String target, Request baseRequest,
                HttpServletRequest request, HttpServletResponse response)
                throws IOException, ServletException {
            if (request.getRequestURI().contains("hang")) {
                System.out.println("Hanging as requested");
                try {
                    Thread.sleep(90000);
                } catch (InterruptedException ie) {
                    System.out.println("Stopped hanging due to interruption");
                }
            }

            long numberOfBytesRead = 0;
            InputStream in = new BufferedInputStream(request
                    .getInputStream());
            while (in.read() != -1) {
                numberOfBytesRead += 1;
            }
            System.out.println("Done reading # of bytes: "
                    + numberOfBytesRead);
            response.setStatus(HttpServletResponse.SC_OK);
            baseRequest.setHandled(true);
            byte[] content = ("Received " + numberOfBytesRead + " bytes\n").getBytes();
            response.addHeader("Content-Length", Integer.toString(content.length));
            response.getOutputStream().write(content);
        }
    });
    if (enableHttps) {
        // Add SSL connector
        org.eclipse.jetty.util.ssl.SslContextFactory sslContextFactory = new org.eclipse.jetty.util.ssl.SslContextFactory();

        SelfSignedSslEngineSource contextSource = new SelfSignedSslEngineSource();
        SSLContext sslContext = contextSource.getSslContext();

        sslContextFactory.setSslContext(sslContext);
        SslSocketConnector connector = new SslSocketConnector(
                sslContextFactory);
        connector.setPort(0);
        /*
         * <p>Ox: For some reason, on OS X, a non-zero timeout can causes
         * sporadic issues. <a href="http://stackoverflow.com/questions
         * /16191236/tomcat-startup-fails
         * -due-to-java-net-socketexception-invalid-argument-on-mac-o">This
         * StackOverflow thread</a> has some insights into it, but I don't
         * quite get it.</p>
         * 
         * <p>This can cause problems with Jetty's SSL handshaking, so I
         * have to set the handshake timeout and the maxIdleTime to 0 so
         * that the SSLSocket has an infinite timeout.</p>
         */
        connector.setHandshakeTimeout(0);
        connector.setMaxIdleTime(0);
        httpServer.addConnector(connector);
    }

    try {
        httpServer.start();
    } catch (Exception e) {
        throw new RuntimeException("Error starting Jetty web server", e);
    }

    return httpServer;
}
项目:little_mitm    文件:TestUtils.java   
/**
 * Creates and starts an embedded web server on JVM-assigned HTTP and HTTPS ports.
 * Each response has a body that contains the specified contents.
 *
 * @param enableHttps if true, an HTTPS connector will be added to the web server
 * @param content The response the server will return
 * @return Instance of Server
 */
public static Server startWebServerWithResponse(boolean enableHttps, final byte[] content) {
    final Server httpServer = new Server(0);
    httpServer.setHandler(new AbstractHandler() {
        public void handle(String target, Request baseRequest,
                           HttpServletRequest request, HttpServletResponse response)
                throws IOException, ServletException {
            if (request.getRequestURI().contains("hang")) {
                System.out.println("Hanging as requested");
                try {
                    Thread.sleep(90000);
                } catch (InterruptedException ie) {
                    System.out.println("Stopped hanging due to interruption");
                }
            }

            long numberOfBytesRead = 0;
            InputStream in = new BufferedInputStream(request
                    .getInputStream());
            while (in.read() != -1) {
                numberOfBytesRead += 1;
            }
            System.out.println("Done reading # of bytes: "
                    + numberOfBytesRead);
            response.setStatus(HttpServletResponse.SC_OK);
            baseRequest.setHandled(true);

            response.addHeader("Content-Length", Integer.toString(content.length));
            response.getOutputStream().write(content);
        }
    });
    if (enableHttps) {
        // Add SSL connector
        org.eclipse.jetty.util.ssl.SslContextFactory sslContextFactory = new org.eclipse.jetty.util.ssl.SslContextFactory();

        SelfSignedSslEngineSource contextSource = new SelfSignedSslEngineSource();
        SSLContext sslContext = contextSource.getSslContext();

        sslContextFactory.setSslContext(sslContext);
        SslSocketConnector connector = new SslSocketConnector(
                sslContextFactory);
        connector.setPort(0);
        /*
         * <p>Ox: For some reason, on OS X, a non-zero timeout can causes
         * sporadic issues. <a href="http://stackoverflow.com/questions
         * /16191236/tomcat-startup-fails
         * -due-to-java-net-socketexception-invalid-argument-on-mac-o">This
         * StackOverflow thread</a> has some insights into it, but I don't
         * quite get it.</p>
         *
         * <p>This can cause problems with Jetty's SSL handshaking, so I
         * have to set the handshake timeout and the maxIdleTime to 0 so
         * that the SSLSocket has an infinite timeout.</p>
         */
        connector.setHandshakeTimeout(0);
        connector.setMaxIdleTime(0);
        httpServer.addConnector(connector);
    }

    try {
        httpServer.start();
    } catch (Exception e) {
        throw new RuntimeException("Error starting Jetty web server", e);
    }

    return httpServer;
}
项目:i2p.plugins.i2pcontrol    文件:I2PControlController.java   
/**
 * Builds a new server. Used for changing ports during operation and such.
 * @return Server - A new server built from current configuration.
 * @throws UnknownHostException
 */
public static Connector buildDefaultListenter() throws UnknownHostException {
    SslSocketConnector ssl = buildSslListener(_conf.getConf("i2pcontrol.listen.address", "127.0.0.1"),
                             _conf.getConf("i2pcontrol.listen.port", 7650));
    return ssl;
}
项目:Intercloud    文件:Start.java   
public static void main(String[] args) throws Exception {
    int timeout = (int) Duration.ONE_HOUR.getMilliseconds();

    Server server = new Server();
    SocketConnector connector = new SocketConnector();

    // Set some timeout options to make debugging easier.
    connector.setMaxIdleTime(timeout);
    connector.setSoLingerTime(-1);
    connector.setPort(8080);
    server.addConnector(connector);

    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.

        connector.setConfidentialPort(8443);

        SslContextFactory factory = new SslContextFactory();
        factory.setKeyStoreResource(keystore);
        factory.setKeyStorePassword("wicket");
        factory.setTrustStoreResource(keystore);
        factory.setKeyManagerPassword("wicket");
        SslSocketConnector sslConnector = new SslSocketConnector(factory);
        sslConnector.setMaxIdleTime(timeout);
        sslConnector.setPort(8443);
        sslConnector.setAcceptors(4);
        server.addConnector(sslConnector);

        System.out.println("SSL access to the quickstart 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");

    // START JMX SERVER
    // MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
    // MBeanContainer mBeanContainer = new MBeanContainer(mBeanServer);
    // server.getContainer().addEventListener(mBeanContainer);
    // mBeanContainer.start();

    server.setHandler(bb);

    try {
        System.out.println(">>> STARTING EMBEDDED JETTY SERVER, PRESS ANY KEY TO STOP");
        server.start();
        System.in.read();
        System.out.println(">>> STOPPING EMBEDDED JETTY SERVER");
        server.stop();
        server.join();
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(1);
    }
}
项目:LittleProxy    文件:TestUtils.java   
/**
 * Creates and starts embedded web server that is running on given port,
 * including an SSL connector on the other given port. Each response has a
 * body that indicates how many bytes were received with a message like
 * "Received x bytes\n".
 * 
 * @param port
 *            The port
 * @param sslPort
 *            (optional) The ssl port
 * @return Instance of Server
 * @throws Exception
 *             if failed to start
 */
public static Server startWebServer(final int port, final Integer sslPort)
        throws Exception {
    final Server httpServer = new Server(port);
    httpServer.setHandler(new AbstractHandler() {
        public void handle(String target, Request baseRequest,
                HttpServletRequest request, HttpServletResponse response)
                throws IOException, ServletException {
            if (request.getRequestURI().contains("hang")) {
                System.out.println("Hanging as requested");
                try {
                    Thread.sleep(90000);
                } catch (InterruptedException ie) {
                    System.out.println("Stopped hanging due to interruption");
                }
            }

            long numberOfBytesRead = 0;
            InputStream in = new BufferedInputStream(request
                    .getInputStream());
            while (in.read() != -1) {
                numberOfBytesRead += 1;
            }
            System.out.println("Done reading # of bytes: "
                    + numberOfBytesRead);
            response.setStatus(HttpServletResponse.SC_OK);
            baseRequest.setHandled(true);
            byte[] content = ("Received " + numberOfBytesRead + " bytes\n").getBytes();
            response.addHeader("Content-Length", Integer.toString(content.length));
            response.getOutputStream().write(content);
        }
    });
    if (sslPort != null) {
        // Add SSL connector
        org.eclipse.jetty.util.ssl.SslContextFactory sslContextFactory = new org.eclipse.jetty.util.ssl.SslContextFactory();

        SelfSignedSslEngineSource contextSource = new SelfSignedSslEngineSource();
        SSLContext sslContext = contextSource.getSslContext();

        sslContextFactory.setSslContext(sslContext);
        SslSocketConnector connector = new SslSocketConnector(
                sslContextFactory);
        connector.setPort(sslPort);
        /*
         * <p>Ox: For some reason, on OS X, a non-zero timeout can causes
         * sporadic issues. <a href="http://stackoverflow.com/questions
         * /16191236/tomcat-startup-fails
         * -due-to-java-net-socketexception-invalid-argument-on-mac-o">This
         * StackOverflow thread</a> has some insights into it, but I don't
         * quite get it.</p>
         * 
         * <p>This can cause problems with Jetty's SSL handshaking, so I
         * have to set the handshake timeout and the maxIdleTime to 0 so
         * that the SSLSocket has an infinite timeout.</p>
         */
        connector.setHandshakeTimeout(0);
        connector.setMaxIdleTime(0);
        httpServer.addConnector(connector);
    }
    httpServer.start();
    return httpServer;
}
项目:LittleProxy    文件:TestUtils.java   
/**
 * Creates and starts embedded web server that is running on given port,
 * including an SSL connector on the other given port. Each response has a
 * body that contains the specified contents.
 *
 * @param port
 *            The port
 * @param sslPort
 *            (optional) The ssl port
 * @param content
 *            The response the server will return
 * @return Instance of Server
 * @throws Exception
 *             if failed to start
 */
public static Server startWebServerWithResponse(final int port, final Integer sslPort, final byte[] content)
        throws Exception {
    final Server httpServer = new Server(port);
    httpServer.setHandler(new AbstractHandler() {
        public void handle(String target, Request baseRequest,
                           HttpServletRequest request, HttpServletResponse response)
                throws IOException, ServletException {
            if (request.getRequestURI().contains("hang")) {
                System.out.println("Hanging as requested");
                try {
                    Thread.sleep(90000);
                } catch (InterruptedException ie) {
                    System.out.println("Stopped hanging due to interruption");
                }
            }

            long numberOfBytesRead = 0;
            InputStream in = new BufferedInputStream(request
                    .getInputStream());
            while (in.read() != -1) {
                numberOfBytesRead += 1;
            }
            System.out.println("Done reading # of bytes: "
                    + numberOfBytesRead);
            response.setStatus(HttpServletResponse.SC_OK);
            baseRequest.setHandled(true);

            response.addHeader("Content-Length", Integer.toString(content.length));
            response.getOutputStream().write(content);
        }
    });
    if (sslPort != null) {
        // Add SSL connector
        org.eclipse.jetty.util.ssl.SslContextFactory sslContextFactory = new org.eclipse.jetty.util.ssl.SslContextFactory();

        SelfSignedSslEngineSource contextSource = new SelfSignedSslEngineSource();
        SSLContext sslContext = contextSource.getSslContext();

        sslContextFactory.setSslContext(sslContext);
        SslSocketConnector connector = new SslSocketConnector(
                sslContextFactory);
        connector.setPort(sslPort);
        /*
         * <p>Ox: For some reason, on OS X, a non-zero timeout can causes
         * sporadic issues. <a href="http://stackoverflow.com/questions
         * /16191236/tomcat-startup-fails
         * -due-to-java-net-socketexception-invalid-argument-on-mac-o">This
         * StackOverflow thread</a> has some insights into it, but I don't
         * quite get it.</p>
         *
         * <p>This can cause problems with Jetty's SSL handshaking, so I
         * have to set the handshake timeout and the maxIdleTime to 0 so
         * that the SSLSocket has an infinite timeout.</p>
         */
        connector.setHandshakeTimeout(0);
        connector.setMaxIdleTime(0);
        httpServer.addConnector(connector);
    }
    httpServer.start();
    return httpServer;
}
项目:message-server    文件:MMXAdminAPIServer.java   
/**
 * Start the server
 */
public void start() {

  MMXConfiguration configuration = MMXConfiguration.getConfiguration();

  final int callBackHandlerPort = configuration.getInt(MMXConfigKeys.ADMIN_API_PORT,
      MMXServerConstants.ADMIN_API_PORT);

  int linger = JiveGlobals.getIntProperty("http.socket.linger", -1);

  SslSocketConnector sslConnector = getSSLConnector();

  if(sslConnector != null && linger > -1) {
    LOGGER.trace("start : setting https socket linger={}", linger);
    sslConnector.setSoLingerTime(linger);
  }


  /**
   * Regular HTTP Connector.
   */
  SelectChannelConnector httpConnector = new SelectChannelConnector();
  httpConnector.setPort(callBackHandlerPort);

  if(linger > -1) {
    LOGGER.trace("start : setting http socket linger={}", linger);
    httpConnector.setSoLingerTime(linger);
  }

  privateApiServer = new Server(callBackHandlerPort);
  if (sslConnector != null) {
    privateApiServer.setConnectors(new Connector[]{sslConnector, httpConnector});
  } else {
    privateApiServer.setConnectors(new Connector[]{httpConnector});
  }
  ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
  context.setContextPath(MMXServerConstants.ADMIN_API_CONTEXT);
  privateApiServer.setHandler(context);

  context.addServlet(new ServletHolder(new MessageServlet()), "/messages");
  context.addServlet(new ServletHolder(new UserServlet()), "/users");
  context.addServlet(new ServletHolder(new PushServlet()), "/push");
  context.addServlet(new ServletHolder(new DeviceServlet()), "/devices/*");
  context.addServlet(new ServletHolder(new PushMessageServlet()), "/pushmessages");
  context.addServlet(new ServletHolder(new ConfigServlet()), "/config");

  /**
   * add the rest easy end point handling the admin rest API.
   */
  String[] resourceClasses = AdminRESTResourceListing.getResources();
  String resources = StringUtils.join(resourceClasses, ",");

  String[] providerClasses = AdminRESTResourceListing.getProviders();
  String providers = StringUtils.join(providerClasses, ",");

  if (LOGGER.isDebugEnabled()) {
    LOGGER.debug("Resource classes:{}", resources);
  }
  ServletHolder holder = new ServletHolder(new MMXRestEasyServletWrapper());
  holder.setInitParameter(MMXServerConstants.RESTEASY_SERVLET_MAPPING_PREFIX_KEY,
      MMXServerConstants.ADMIN_API_SERVLET_V1_MAPPING_PREFIX);

  holder.setInitParameter(MMXServerConstants.RESTEASY_RESOURCES_KEY, resources);
  holder.setInitParameter(MMXServerConstants.RESTEASY_PROVIDERS_KEY, providers);


  context.addServlet(holder, MMXServerConstants.ADMIN_API_V1_REST_MAPPING);
  try {
    LOGGER.info("Admin API server starting at port:" + callBackHandlerPort) ;
    privateApiServer.start();
    LOGGER.info("Admin API server started at port:" + callBackHandlerPort) ;
  } catch (Exception e) {
    LOGGER.error("Exception in starting the jetty Admin API server", e);
  }
}
项目:message-server    文件:MMXPublicAPIServer.java   
public void start() {
  MMXConfiguration configuration = MMXConfiguration.getConfiguration();
  final int port = configuration.getInt(MMXConfigKeys.REST_HTTP_PORT,
      MMXServerConstants.DEFAULT_REST_HTTP_PORT);

  int linger = JiveGlobals.getIntProperty("http.socket.linger", -1);

  SslSocketConnector sslConnector = getSSLConnector();

  if(sslConnector != null && linger > -1) {
    LOGGER.trace("start : setting https socket linger={}", linger);
    sslConnector.setSoLingerTime(linger);
  }
  /**
   * Regular HTTP Connector.
   */
  SelectChannelConnector httpConnector = new SelectChannelConnector();
  httpConnector.setPort(port);

  if(linger > -1) {
    LOGGER.trace("start : setting http socket linger={}", linger);
    httpConnector.setSoLingerTime(linger);
  }

  server = new Server(port);
  if (sslConnector != null) {
    server.setConnectors(new Connector[]{sslConnector, httpConnector});
  } else {
    server.setConnectors(new Connector[]{httpConnector});
  }
  ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
  context.setContextPath(MMXServerConstants.PUSH_CALLBACK_CONTEXT);
  server.setHandler(context);

  context.addServlet(new ServletHolder(new PushReplyServlet()), MMXServerConstants.PUSH_CALLBACK_ENDPOINT);
  /**
   * add the rest easy endpoint handling the public rest API.
   */
  String[] v1resourceClasses = RESTResourceListing.getV1Resources();
  String[] providerList = RESTResourceListing.getProviders();
  String v1resources = StringUtils.join(v1resourceClasses, ",");
  String providers = StringUtils.join(providerList, ",");
  if (LOGGER.isDebugEnabled()) {
    LOGGER.debug("V1 Resource classes:{}", v1resources);
  }
  ServletHolder v1holder = new ServletHolder(new org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher());
  v1holder.setInitParameter(MMXServerConstants.RESTEASY_SERVLET_MAPPING_PREFIX_KEY, MMXServerConstants.PUBLIC_API_SERVLET_V1_MAPPING_PREFIX);
  v1holder.setInitParameter(MMXServerConstants.RESTEASY_RESOURCES_KEY, v1resources);
  v1holder.setInitParameter(MMXServerConstants.RESTEASY_PROVIDERS_KEY, providers);
  context.addServlet(v1holder, MMXServerConstants.PUBLIC_REST_API_V1_MAPPING);

  String[] v2resourceClasses = RESTResourceListing.getV2Resources();
  String v2resources = StringUtils.join(v2resourceClasses, ",");
  if (LOGGER.isDebugEnabled()) {
    LOGGER.debug("V2 Resource classes:{}", v2resources);
  }
  ServletHolder v2holder = new ServletHolder(new org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher());
  v2holder.setInitParameter(MMXServerConstants.RESTEASY_SERVLET_MAPPING_PREFIX_KEY, MMXServerConstants.PUBLIC_API_SERVLET_V2_MAPPING_PREFIX);
  v2holder.setInitParameter(MMXServerConstants.RESTEASY_RESOURCES_KEY, v2resources);
  v2holder.setInitParameter(MMXServerConstants.RESTEASY_PROVIDERS_KEY, providers);
  context.addServlet(v2holder, MMXServerConstants.PUBLIC_REST_API_V2_MAPPING);

  try {
    LOGGER.info("Public REST API server starting at port:" + port);
    server.start();
    LOGGER.info("Public REST API server started at port:" + port);
  } catch (Exception e) {
    LOGGER.error("Exception in starting the Public REST API server", e);
  }
}
项目:message-server    文件:BaseJAXRSTest.java   
@Override
protected SslSocketConnector getSSLConnector() {
  return null;
}
项目:message-server    文件:BaseJAXRSTest.java   
@Override
protected SslSocketConnector getSSLConnector() {
  return null;
}
项目:FutureSonic-Server    文件:SubsonicDeployer.java   
private void deployWebApp() {
    try {
        Server server = new Server();
        SelectChannelConnector connector = new SelectChannelConnector();
        connector.setMaxIdleTime(MAX_IDLE_TIME_MILLIS);
        connector.setRequestHeaderSize(HEADER_BUFFER_SIZE);
        connector.setResponseHeaderSize(HEADER_BUFFER_SIZE);
        connector.setHost(getHost());
        connector.setPort(getPort());
        if (isHttpsEnabled()) {
            connector.setConfidentialPort(getHttpsPort());
        }
        server.addConnector(connector);

        if (isHttpsEnabled()) {
            SslSocketConnector sslConnector = new SslSocketConnector();
            sslConnector.setMaxIdleTime(MAX_IDLE_TIME_MILLIS);
            sslConnector.setRequestHeaderSize(HEADER_BUFFER_SIZE);
            sslConnector.setResponseHeaderSize(HEADER_BUFFER_SIZE);
            sslConnector.setHost(getHost());
            sslConnector.setPort(getHttpsPort());
            sslConnector.setKeystore(System.getProperty("subsonic.ssl.keystore", getClass().getResource("/subsonic.keystore").toExternalForm()));
            sslConnector.setPassword(System.getProperty("subsonic.ssl.password", "subsonic"));
            server.addConnector(sslConnector);
        }

        WebAppContext context = new WebAppContext();
        context.setTempDirectory(getJettyDirectory());
        context.setContextPath(getContextPath());
        context.setWar(getWar());

        if (isHttpsEnabled()) {
            ConstraintMapping constraintMapping = new ConstraintMapping();
            Constraint constraint = new Constraint();
            constraint.setDataConstraint(Constraint.DC_CONFIDENTIAL);
            constraintMapping.setPathSpec("/");
            constraintMapping.setConstraint(constraint);
            ConstraintSecurityHandler csh = (ConstraintSecurityHandler) context.getSecurityHandler();
            csh.setConstraintMappings(new ConstraintMapping[]{constraintMapping});
        } 

        server.setHandler(context);
        server.start();

        System.err.println("FutureSonic running on: " + getUrl());
        if (isHttpsEnabled()) {
            System.err.println("                and: " + getHttpsUrl());
        }

    } catch (Throwable x) {
        x.printStackTrace();
        exception = x;
    }
}
项目:madsonic-server-5.1    文件:MadsonicDeployer.java   
@SuppressWarnings("deprecation")
private void deployWebApp() {
       try {
           Server server = new Server();
           SelectChannelConnector connector = new SelectChannelConnector();
           connector.setMaxIdleTime(MAX_IDLE_TIME_MILLIS);
           connector.setRequestHeaderSize(HEADER_BUFFER_SIZE);
           connector.setResponseHeaderSize(HEADER_BUFFER_SIZE);
           connector.setHost(getHost());
           connector.setPort(getPort());
           if (isHttpsEnabled()) {
               connector.setConfidentialPort(getHttpsPort());
           }
           server.addConnector(connector);

           if (isHttpsEnabled()) {
               SslSocketConnector sslConnector = new SslSocketConnector();
               SslContextFactory sslContextFactory = sslConnector.getSslContextFactory();
               sslContextFactory = sslConnector.getSslContextFactory();
               sslContextFactory.setExcludeCipherSuites(
                       new String[] {
                           "SSL_RSA_WITH_DES_CBC_SHA",
                           "SSL_DHE_RSA_WITH_DES_CBC_SHA",
                           "SSL_DHE_DSS_WITH_DES_CBC_SHA",
                           "SSL_RSA_EXPORT_WITH_RC4_40_MD5",
                           "SSL_RSA_EXPORT_WITH_DES40_CBC_SHA",
                           "SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA",
                           "SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA"
                       });
               sslContextFactory.addExcludeProtocols(new String[]{"SSLv3","SSLv2Hello"});
               sslConnector.setMaxIdleTime(MAX_IDLE_TIME_MILLIS);
               sslConnector.setRequestHeaderSize(HEADER_BUFFER_SIZE);
               sslConnector.setResponseHeaderSize(HEADER_BUFFER_SIZE);
               sslConnector.setHost(getHost());
               sslConnector.setPort(getHttpsPort());
               sslConnector.setKeystore(System.getProperty("subsonic.ssl.keystore", getClass().getResource("/subsonic.keystore").toExternalForm()));
               sslConnector.setPassword(System.getProperty("subsonic.ssl.password", "subsonic"));
               server.addConnector(sslConnector);
           }

           WebAppContext context = new WebAppContext();
           context.setTempDirectory(getJettyDirectory());
           context.setContextPath(getContextPath());
           context.setWar(getWar());
           context.setOverrideDescriptor("/web-jetty.xml");

           if (isHttpsEnabled()) {

               // Allow non-https for streaming and cover art (for Chromecast, UPnP etc)
               ((ConstraintSecurityHandler) context.getSecurityHandler()).setConstraintMappings(new ConstraintMapping[]{
                       createConstraintMapping("/stream", Constraint.DC_NONE),
                       createConstraintMapping("/coverArt.view", Constraint.DC_NONE),
                       createConstraintMapping("/", Constraint.DC_CONFIDENTIAL)
               });
           } 

           server.setHandler(context);
           server.start();

           System.err.println("Madsonic running on: " + getUrl());
           if (isHttpsEnabled()) {
           System.err.println("                and: " + getHttpsUrl());
           }

       } catch (Throwable x) {
           x.printStackTrace();
           exception = x;
       }
   }
项目:madsonic-server-5.0    文件:SubsonicDeployer.java   
private void deployWebApp() {
    try {
        Server server = new Server();
        SelectChannelConnector connector = new SelectChannelConnector();
        connector.setMaxIdleTime(MAX_IDLE_TIME_MILLIS);
        connector.setRequestHeaderSize(HEADER_BUFFER_SIZE);
        connector.setResponseHeaderSize(HEADER_BUFFER_SIZE);
        connector.setHost(getHost());
        connector.setPort(getPort());
        if (isHttpsEnabled()) {
            connector.setConfidentialPort(getHttpsPort());
        }
        server.addConnector(connector);

        if (isHttpsEnabled()) {
            SslSocketConnector sslConnector = new SslSocketConnector();
            sslConnector.setMaxIdleTime(MAX_IDLE_TIME_MILLIS);
            sslConnector.setRequestHeaderSize(HEADER_BUFFER_SIZE);
            sslConnector.setResponseHeaderSize(HEADER_BUFFER_SIZE);
            sslConnector.setHost(getHost());
            sslConnector.setPort(getHttpsPort());
            sslConnector.setKeystore(System.getProperty("subsonic.ssl.keystore", getClass().getResource("/subsonic.keystore").toExternalForm()));
            sslConnector.setPassword(System.getProperty("subsonic.ssl.password", "subsonic"));
            server.addConnector(sslConnector);
        }

        WebAppContext context = new WebAppContext();
        context.setTempDirectory(getJettyDirectory());
        context.setContextPath(getContextPath());
        context.setWar(getWar());

        if (isHttpsEnabled()) {
            ConstraintMapping constraintMapping = new ConstraintMapping();
            Constraint constraint = new Constraint();
            constraint.setDataConstraint(Constraint.DC_CONFIDENTIAL);
            constraintMapping.setPathSpec("/");
            constraintMapping.setConstraint(constraint);
            ConstraintSecurityHandler csh = (ConstraintSecurityHandler) context.getSecurityHandler();
            csh.setConstraintMappings(new ConstraintMapping[]{constraintMapping});
        } 

        server.setHandler(context);
        server.start();

        System.err.println("Madsonic running on: " + getUrl());
        if (isHttpsEnabled()) {
            System.err.println("                and: " + getHttpsUrl());
        }

    } catch (Throwable x) {
        x.printStackTrace();
        exception = x;
    }
}
项目:practicalwicket    文件:Start.java   
public static void main(String[] args) throws Exception {
    int timeout = (int) Duration.ONE_HOUR.getMilliseconds();

    Server server = new Server();
    SocketConnector connector = new SocketConnector();

    // Set some timeout options to make debugging easier.
    connector.setMaxIdleTime(timeout);
    connector.setSoLingerTime(-1);
    connector.setPort(8080);
    server.addConnector(connector);

    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.

        connector.setConfidentialPort(8443);

        SslContextFactory factory = new SslContextFactory();
        factory.setKeyStoreResource(keystore);
        factory.setKeyStorePassword("wicket");
        factory.setTrustStoreResource(keystore);
        factory.setKeyManagerPassword("wicket");
        SslSocketConnector sslConnector = new SslSocketConnector(factory);
        sslConnector.setMaxIdleTime(timeout);
        sslConnector.setPort(8443);
        sslConnector.setAcceptors(4);
        server.addConnector(sslConnector);

        System.out.println("SSL access to the quickstart 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");

    // START JMX SERVER
    // MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
    // MBeanContainer mBeanContainer = new MBeanContainer(mBeanServer);
    // server.getContainer().addEventListener(mBeanContainer);
    // mBeanContainer.start();

    server.setHandler(bb);

    try {
        System.out.println(">>> STARTING EMBEDDED JETTY SERVER, PRESS ANY KEY TO STOP");
        server.start();
        System.in.read();
        System.out.println(">>> STOPPING EMBEDDED JETTY SERVER");
        server.stop();
        server.join();
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(1);
    }
}
项目:Invoice-Keeper    文件:Start.java   
public static void main(String[] args) throws Exception {
    int timeout = (int) Duration.ONE_HOUR.getMilliseconds();

    Server server = new Server();
    SocketConnector connector = new SocketConnector();

    // Set some timeout options to make debugging easier.
    connector.setMaxIdleTime(timeout);
    connector.setSoLingerTime(-1);
    connector.setPort(8080);
    server.addConnector(connector);

    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.

        connector.setConfidentialPort(8443);

        SslContextFactory factory = new SslContextFactory();
        factory.setKeyStoreResource(keystore);
        factory.setKeyStorePassword("wicket");
        factory.setTrustStoreResource(keystore);
        factory.setKeyManagerPassword("wicket");
        SslSocketConnector sslConnector = new SslSocketConnector(factory);
        sslConnector.setMaxIdleTime(timeout);
        sslConnector.setPort(8443);
        sslConnector.setAcceptors(4);
        server.addConnector(sslConnector);

        System.out.println("SSL access to the quickstart 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");

    // START JMX SERVER
    // MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
    // MBeanContainer mBeanContainer = new MBeanContainer(mBeanServer);
    // server.getContainer().addEventListener(mBeanContainer);
    // mBeanContainer.start();

    server.setHandler(bb);

    try {
        System.out.println(">>> STARTING EMBEDDED JETTY SERVER, PRESS ANY KEY TO STOP");
        server.start();
        System.in.read();
        System.out.println(">>> STOPPING EMBEDDED JETTY SERVER");
        server.stop();
        server.join();
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(1);
    }
}
项目:wicket-bootstrap-example    文件:Start.java   
public static void main(String[] args) throws Exception {
    int timeout = (int) Duration.ONE_HOUR.getMilliseconds();

    Server server = new Server();
    SocketConnector connector = new SocketConnector();

    // Set some timeout options to make debugging easier.
    connector.setMaxIdleTime(timeout);
    connector.setSoLingerTime(-1);
    connector.setPort(8080);
    server.addConnector(connector);

    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.

        connector.setConfidentialPort(8443);

        SslContextFactory factory = new SslContextFactory();
        factory.setKeyStoreResource(keystore);
        factory.setKeyStorePassword("wicket");
        factory.setTrustStoreResource(keystore);
        factory.setKeyManagerPassword("wicket");
        SslSocketConnector sslConnector = new SslSocketConnector(factory);
        sslConnector.setMaxIdleTime(timeout);
        sslConnector.setPort(8443);
        sslConnector.setAcceptors(4);
        server.addConnector(sslConnector);

        System.out.println("SSL access to the quickstart 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");

    // START JMX SERVER
    // MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
    // MBeanContainer mBeanContainer = new MBeanContainer(mBeanServer);
    // server.getContainer().addEventListener(mBeanContainer);
    // mBeanContainer.start();

    server.setHandler(bb);

    try {
        System.out.println(">>> STARTING EMBEDDED JETTY SERVER, PRESS ANY KEY TO STOP");
        server.start();
        System.in.read();
        System.out.println(">>> STOPPING EMBEDDED JETTY SERVER");
        server.stop();
        server.join();
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(1);
    }
}
项目:madsonic-server-5.0    文件:SubsonicDeployer.java   
private void deployWebApp() {
    try {
        Server server = new Server();
        SelectChannelConnector connector = new SelectChannelConnector();
        connector.setMaxIdleTime(MAX_IDLE_TIME_MILLIS);
        connector.setRequestHeaderSize(HEADER_BUFFER_SIZE);
        connector.setResponseHeaderSize(HEADER_BUFFER_SIZE);
        connector.setHost(getHost());
        connector.setPort(getPort());
        if (isHttpsEnabled()) {
            connector.setConfidentialPort(getHttpsPort());
        }
        server.addConnector(connector);

        if (isHttpsEnabled()) {
            SslSocketConnector sslConnector = new SslSocketConnector();
            sslConnector.setMaxIdleTime(MAX_IDLE_TIME_MILLIS);
            sslConnector.setRequestHeaderSize(HEADER_BUFFER_SIZE);
            sslConnector.setResponseHeaderSize(HEADER_BUFFER_SIZE);
            sslConnector.setHost(getHost());
            sslConnector.setPort(getHttpsPort());
            sslConnector.setKeystore(System.getProperty("subsonic.ssl.keystore", getClass().getResource("/subsonic.keystore").toExternalForm()));
            sslConnector.setPassword(System.getProperty("subsonic.ssl.password", "subsonic"));
            server.addConnector(sslConnector);
        }

        WebAppContext context = new WebAppContext();
        context.setTempDirectory(getJettyDirectory());
        context.setContextPath(getContextPath());
        context.setWar(getWar());

        if (isHttpsEnabled()) {
            ConstraintMapping constraintMapping = new ConstraintMapping();
            Constraint constraint = new Constraint();
            constraint.setDataConstraint(Constraint.DC_CONFIDENTIAL);
            constraintMapping.setPathSpec("/");
            constraintMapping.setConstraint(constraint);
            ConstraintSecurityHandler csh = (ConstraintSecurityHandler) context.getSecurityHandler();
            csh.setConstraintMappings(new ConstraintMapping[]{constraintMapping});
        } 

        server.setHandler(context);
        server.start();

        System.err.println("Madsonic running on: " + getUrl());
        if (isHttpsEnabled()) {
            System.err.println("                and: " + getHttpsUrl());
        }

    } catch (Throwable x) {
        x.printStackTrace();
        exception = x;
    }
}
项目:wicket-memcached-data-store    文件:Start.java   
public static void main(String[] args) throws Exception {
    int timeout = (int) Duration.ONE_HOUR.getMilliseconds();

    Server server = new Server();
    SocketConnector connector = new SocketConnector();

    // Set some timeout options to make debugging easier.
    connector.setMaxIdleTime(timeout);
    connector.setSoLingerTime(-1);
    connector.setPort(8080);
    server.addConnector(connector);

    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.

        connector.setConfidentialPort(8443);

        SslContextFactory factory = new SslContextFactory();
        factory.setKeyStoreResource(keystore);
        factory.setKeyStorePassword("wicket");
        factory.setTrustStoreResource(keystore);
        factory.setKeyManagerPassword("wicket");
        SslSocketConnector sslConnector = new SslSocketConnector(factory);
        sslConnector.setMaxIdleTime(timeout);
        sslConnector.setPort(8443);
        sslConnector.setAcceptors(4);
        server.addConnector(sslConnector);

        System.out.println("SSL access to the quickstart 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/test/webapp");

    // START JMX SERVER
    // MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
    // MBeanContainer mBeanContainer = new MBeanContainer(mBeanServer);
    // server.getContainer().addEventListener(mBeanContainer);
    // mBeanContainer.start();

    server.setHandler(bb);

    try {
        System.out.println(">>> STARTING EMBEDDED JETTY SERVER, PRESS ANY KEY TO STOP");
        server.start();
        System.in.read();
        System.out.println(">>> STOPPING EMBEDDED JETTY SERVER");
        server.stop();
        server.join();
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(1);
    }
}
项目:serverside-todomvc    文件:Start.java   
public static void main(String[] args) throws Exception {
  int timeout = (int) Duration.ONE_HOUR.getMilliseconds();

  Server server = new Server();
  SocketConnector connector = new SocketConnector();

  // Set some timeout options to make debugging easier.
  connector.setMaxIdleTime(timeout);
  connector.setSoLingerTime(-1);
  connector.setPort(8080);
  server.addConnector(connector);

  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.

    connector.setConfidentialPort(8443);

    SslContextFactory factory = new SslContextFactory();
    factory.setKeyStoreResource(keystore);
    factory.setKeyStorePassword("wicket");
    factory.setTrustStoreResource(keystore);
    factory.setKeyManagerPassword("wicket");
    SslSocketConnector sslConnector = new SslSocketConnector(factory);
    sslConnector.setMaxIdleTime(timeout);
    sslConnector.setPort(8443);
    sslConnector.setAcceptors(4);
    server.addConnector(sslConnector);

    System.out.println("SSL access to the quickstart 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("/examples-java-wicket");
  bb.setWar("src/main/webapp");

  // START JMX SERVER
  // MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
  // MBeanContainer mBeanContainer = new MBeanContainer(mBeanServer);
  // server.getContainer().addEventListener(mBeanContainer);
  // mBeanContainer.start();

  server.setHandler(bb);

  try {
    System.out.println(">>> STARTING EMBEDDED JETTY SERVER, PRESS ANY KEY TO STOP");
    server.start();
    System.in.read();
    System.out.println(">>> STOPPING EMBEDDED JETTY SERVER");
    server.stop();
    server.join();
  }
  catch (Exception e) {
    e.printStackTrace();
    System.exit(1);
  }
}
项目:Wicket-rest-annotations    文件:Start.java   
public static void main(String[] args) throws Exception {
    int timeout = (int) Duration.ONE_HOUR.getMilliseconds();

    Server server = new Server();
    SocketConnector connector = new SocketConnector();

    // Set some timeout options to make debugging easier.
    connector.setMaxIdleTime(timeout);
    connector.setSoLingerTime(-1);
    connector.setPort(8080);
    server.addConnector(connector);

    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.

        connector.setConfidentialPort(8443);

        SslContextFactory factory = new SslContextFactory();
        factory.setKeyStoreResource(keystore);
        factory.setKeyStorePassword("wicket");
        factory.setTrustStoreResource(keystore);
        factory.setKeyManagerPassword("wicket");
        SslSocketConnector sslConnector = new SslSocketConnector(factory);
        sslConnector.setMaxIdleTime(timeout);
        sslConnector.setPort(8443);
        sslConnector.setAcceptors(4);
        server.addConnector(sslConnector);

        System.out.println("SSL access to the quickstart 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");

    // START JMX SERVER
    // MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
    // MBeanContainer mBeanContainer = new MBeanContainer(mBeanServer);
    // server.getContainer().addEventListener(mBeanContainer);
    // mBeanContainer.start();

    server.setHandler(bb);

    try {
        System.out.println(">>> STARTING EMBEDDED JETTY SERVER, PRESS ANY KEY TO STOP");
        server.start();
        System.in.read();
        System.out.println(">>> STOPPING EMBEDDED JETTY SERVER");
        server.stop();
        server.join();
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(1);
    }
}
项目:Wicket-rest-annotations    文件:Start.java   
public static void main(String[] args) throws Exception {
    int timeout = (int) Duration.ONE_HOUR.getMilliseconds();

    Server server = new Server();
    SocketConnector connector = new SocketConnector();

    // Set some timeout options to make debugging easier.
    connector.setMaxIdleTime(timeout);
    connector.setSoLingerTime(-1);
    connector.setPort(8080);
    server.addConnector(connector);

    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.

        connector.setConfidentialPort(8443);

        SslContextFactory factory = new SslContextFactory();
        factory.setKeyStoreResource(keystore);
        factory.setKeyStorePassword("wicket");
        factory.setTrustStoreResource(keystore);
        factory.setKeyManagerPassword("wicket");
        SslSocketConnector sslConnector = new SslSocketConnector(factory);
        sslConnector.setMaxIdleTime(timeout);
        sslConnector.setPort(8443);
        sslConnector.setAcceptors(4);
        server.addConnector(sslConnector);

        System.out.println("SSL access to the quickstart 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");

    // START JMX SERVER
    // MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
    // MBeanContainer mBeanContainer = new MBeanContainer(mBeanServer);
    // server.getContainer().addEventListener(mBeanContainer);
    // mBeanContainer.start();

    server.setHandler(bb);

    try {
        System.out.println(">>> STARTING EMBEDDED JETTY SERVER, PRESS ANY KEY TO STOP");
        server.start();
        System.in.read();
        System.out.println(">>> STOPPING EMBEDDED JETTY SERVER");
        server.stop();
        server.join();
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(1);
    }
}
项目:wicket-hot-reload    文件:Start.java   
public static void main(String[] args) throws Exception {
    int timeout = (int) Duration.ONE_HOUR.getMilliseconds();

    Server server = new Server();
    SocketConnector connector = new SocketConnector();

    // Set some timeout options to make debugging easier.
    connector.setMaxIdleTime(timeout);
    connector.setSoLingerTime(-1);
    connector.setPort(8081);
    server.addConnector(connector);

    // check if a keystore for a SSL certificate is available, and
    // if so, 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.

    Resource keystore = Resource.newClassPathResource("/keystore");
    if (keystore != null && keystore.exists()) {
        connector.setConfidentialPort(8443);

        SslContextFactory factory = new SslContextFactory();
        factory.setKeyStoreResource(keystore);
        factory.setKeyStorePassword("wicket");
        factory.setTrustStoreResource(keystore);
        factory.setKeyManagerPassword("wicket");
        SslSocketConnector sslConnector = new SslSocketConnector(factory);
        sslConnector.setMaxIdleTime(timeout);
        sslConnector.setPort(8443);
        sslConnector.setAcceptors(4);
        server.addConnector(sslConnector);

        System.out.println("SSL access to the quickstart 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/test/webapp");

    // START JMX SERVER
    // MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
    // MBeanContainer mBeanContainer = new MBeanContainer(mBeanServer);
    // server.getContainer().addEventListener(mBeanContainer);
    // mBeanContainer.start();

    server.setHandler(bb);

    //TOGGLE between these two method to experiment different reloading strategies
    // Autoreload builds and reload the classes automatically
    setAutoReloadProperties();
    // WatchClasses watch the target dir for reloading (build with your IDE or maven)
    //setWatchClassesProperties();
    try {
        System.out.println(">>> STARTING EMBEDDED JETTY SERVER, PRESS ANY KEY TO STOP");
        server.start();
        System.in.read();
        System.out.println(">>> STOPPING EMBEDDED JETTY SERVER");
        server.stop();
        server.join();
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(1);
    }
}
项目:sensormix    文件:JettyStart.java   
public static void main(String[] args) throws Exception {

    Server server = new Server();
    SocketConnector connector = new SocketConnector();

    // Set some timeout options to make debugging easier.
    connector.setMaxIdleTime(3600000);
    connector.setSoLingerTime(-1);
    connector.setPort(8080);
    server.addConnector(connector);

    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.

      connector.setConfidentialPort(8443);

      SslContextFactory factory = new SslContextFactory();
      factory.setKeyStoreResource(keystore);
      factory.setKeyStorePassword("jettyjetty");
      factory.setTrustStoreResource(keystore);
      factory.setKeyManagerPassword("jettyjetty");
      SslSocketConnector sslConnector = new SslSocketConnector(factory);
      sslConnector.setMaxIdleTime(3600000);
      sslConnector.setPort(8443);
      sslConnector.setAcceptors(4);
      server.addConnector(sslConnector);

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

    String includeJarPattern =
        ".*/.*jsp-api-[^/]*\\.jar$|.*/.*jsp-[^/]*\\.jar$|.*/.*taglibs[^/]*\\.jar$";
    // includeJarPattern =
    // ".*/org\\.apache\\.taglibs\\.standard\\.glassfish-1\\.2\\.0\\.v201112081803\\.jar";

    ResourceCollection resources = new ResourceCollection(new String[]{
        "src/main/webapp", "target/webapp",
    });

    WebAppContext webCtx = new WebAppContext();
    webCtx.setServer(server);
    webCtx.setContextPath("/");

    webCtx.setDescriptor("src/test/resources/web/test-web.xml");
    webCtx.setBaseResource(resources);

    webCtx.setAttribute("org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern",
        includeJarPattern);

    server.setHandler(webCtx);


    // BrowserListener gwtBrowserListener = new BrowserListener(null, "0.0.0.0", 9997, null);


    try {
      System.out.println(">>> STARTING EMBEDDED JETTY SERVER, PRESS ANY KEY TO STOP");
      server.start();
      System.in.read();
      System.out.println(">>> STOPPING EMBEDDED JETTY SERVER");
      server.stop();
      server.join();
    } catch (Exception e) {
      e.printStackTrace();
      System.exit(1);
    }
  }