Java 类org.eclipse.jetty.server.HttpConnectionFactory 实例源码

项目:buabook-api-interface    文件:BuaBookApiInterface.java   
private void startJetty() throws Exception {
    QueuedThreadPool jettyThreadPool = new QueuedThreadPool(jettyServerThreads);
    Server server = new Server(jettyThreadPool);

    ServerConnector http = new ServerConnector(server, new HttpConnectionFactory());
    http.setPort(jettyListenPort);

    server.addConnector(http);

    ContextHandler contextHandler = new ContextHandler();
    contextHandler.setHandler(botSocketHandler);
    server.setHandler(contextHandler);

    server.start();
    server.join();
}
项目:minijax    文件:Minijax.java   
/**
 * Creates a server connector.
 *
 * If an HTTPS key store is configured, returns a SSL connector for HTTPS.
 *
 * Otherwise, returns a normal HTTP connector by default.
 *
 * @param server The server.
 * @return The server connector.
 */
@SuppressWarnings("squid:S2095")
private ServerConnector createConnector(final Server server) {
    final String keyStorePath = (String) configuration.get(MinijaxProperties.SSL_KEY_STORE_PATH);

    if (keyStorePath == null || keyStorePath.isEmpty()) {
        // Normal HTTP
        return new ServerConnector(server);
    }

    final String keyStorePassword = (String) configuration.get(MinijaxProperties.SSL_KEY_STORE_PASSWORD);
    final String keyManagerPassword = (String) configuration.get(MinijaxProperties.SSL_KEY_MANAGER_PASSWORD);

    final HttpConfiguration https = new HttpConfiguration();
    https.addCustomizer(new SecureRequestCustomizer());

    final SslContextFactory sslContextFactory = new SslContextFactory();
    sslContextFactory.setKeyStorePath(Minijax.class.getClassLoader().getResource(keyStorePath).toExternalForm());
    sslContextFactory.setKeyStorePassword(keyStorePassword);
    sslContextFactory.setKeyManagerPassword(keyManagerPassword);

    return new ServerConnector(server,
            new SslConnectionFactory(sslContextFactory, "http/1.1"),
            new HttpConnectionFactory(https));
}
项目:robotoy    文件:WebServer.java   
private void setupSSL(Server server,HttpConfiguration http_config) {
    SslContextFactory sslContextFactory = new SslContextFactory();

    if (sslKeyStoreFile!=null)
        sslContextFactory.setKeyStorePath(sslKeyStoreFile);
    else if (sslKeyStore!=null)
        sslContextFactory.setKeyStore(sslKeyStore);
    else {
        log.log(Level.SEVERE,"Error while configuring SSL connection. Missing KeyStore!");
        return;
    }
    sslContextFactory.setKeyStorePassword(new String(sslKeyStorePassword));
    sslContextFactory.setExcludeCipherSuites("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");
    HttpConfiguration https_config = new HttpConfiguration(http_config);
    https_config.addCustomizer(new SecureRequestCustomizer());
    ServerConnector sslConnector = new ServerConnector(server,
        new SslConnectionFactory(sslContextFactory,HttpVersion.HTTP_1_1.asString()),
        new HttpConnectionFactory(https_config));
    sslConnector.setPort(daemonPortSecure);
    server.addConnector(sslConnector);
}
项目:endpoints-management-java    文件:IntegrationTestServer.java   
public void start() throws Exception {
  URL keystoreUrl = IntegrationTestServer.class.getClassLoader().getResource("keystore.jks");
  SslContextFactory sslContextFactory = new SslContextFactory();
  sslContextFactory.setKeyStorePath(keystoreUrl.getPath());
  sslContextFactory.setKeyStorePassword("keystore");

  SecureRequestCustomizer src = new SecureRequestCustomizer();
  HttpConfiguration httpsConfiguration = new HttpConfiguration();
  httpsConfiguration.setSecureScheme("https");
  httpsConfiguration.addCustomizer(src);

  ServerConnector https = new ServerConnector(server,
      new SslConnectionFactory(sslContextFactory,HttpVersion.HTTP_1_1.asString()),
          new HttpConnectionFactory(httpsConfiguration));
  https.setPort(this.httpsPort);

  this.server.setConnectors(new Connector[] { https });

  ResourceConfig resourceConfig = new ResourceConfig(this.resourceClass);
  ServletContainer servletContainer = new ServletContainer(resourceConfig);
  ServletHolder servletHolder = new ServletHolder(servletContainer);
  ServletContextHandler servletContextHandler = new ServletContextHandler(server, "/*");
  servletContextHandler.addServlet(servletHolder, "/*");

  this.server.start();
}
项目:megaphone    文件:TestUtils.java   
public static void addHttpsConnector(Server server, int port) throws IOException, URISyntaxException {

        String keyStoreFile = resourceAsFile("ssltest-keystore.jks").getAbsolutePath();
        SslContextFactory sslContextFactory = new SslContextFactory(keyStoreFile);
        sslContextFactory.setKeyStorePassword("changeit");

        String trustStoreFile = resourceAsFile("ssltest-cacerts.jks").getAbsolutePath();
        sslContextFactory.setTrustStorePath(trustStoreFile);
        sslContextFactory.setTrustStorePassword("changeit");

        HttpConfiguration httpsConfig = new HttpConfiguration();
        httpsConfig.setSecureScheme("https");
        httpsConfig.setSecurePort(port);
        httpsConfig.addCustomizer(new SecureRequestCustomizer());

        ServerConnector connector = new ServerConnector(server, new SslConnectionFactory(sslContextFactory, "http/1.1"), new HttpConnectionFactory(httpsConfig));
        connector.setPort(port);

        server.addConnector(connector);
    }
项目:rdf-delta    文件:PatchLogServer.java   
/** Build a Jetty server */
private static Server jettyServer(int port, boolean loopback) {
    Server server = new Server() ;
    HttpConnectionFactory f1 = new HttpConnectionFactory() ;
    // Some people do try very large operations ... really, should use POST.
    f1.getHttpConfiguration().setRequestHeaderSize(512 * 1024);
    f1.getHttpConfiguration().setOutputBufferSize(5 * 1024 * 1024) ;
    // Do not add "Server: Jetty(....) when not a development system.
    if ( true )
        f1.getHttpConfiguration().setSendServerVersion(false) ;
    ServerConnector connector = new ServerConnector(server, f1) ;
    connector.setPort(port) ;
    server.addConnector(connector);
    if ( loopback )
        connector.setHost("localhost");
    return server ;
}
项目:git-lfs-azureblob    文件:LfsServer.java   
/**
 * Ctor.
 * @param path Server path.
 * @param storage Storage container.
 * @param port Server port
 */
LfsServer(final String path, final ContentManager storage,
    final int port) {
    this.server = new Server();
    this.http =
        new ServerConnector(this.server, new HttpConnectionFactory());
    this.http.setPort(port);
    // @checkstyle MagicNumber (1 line)
    this.http.setIdleTimeout(30000);
    this.server.addConnector(this.http);
    final ServletHandler handler = new ServletHandler();
    this.server.setHandler(handler);
    handler.addServletWithMapping(
        new ServletHolder(
            new PointerServlet(
                storage, String.format("%s/info/lfs/storage/", path)
            )
        ),
        String.format("%s/info/lfs/objects/*", path)
    );
    handler.addServletWithMapping(
        new ServletHolder(new ContentServlet(storage)),
        String.format("%s/info/lfs/storage/*", path)
    );
}
项目:citizenship-appointment-server    文件:AppConfig.java   
@Bean
public EmbeddedServletContainerCustomizer disableServerHeader() {
    return container -> {
        if (container instanceof JettyEmbeddedServletContainerFactory) {
            ((JettyEmbeddedServletContainerFactory) container).addServerCustomizers(new JettyServerCustomizer() {
                @Override
                public void customize(Server server) {
                    for (Connector connector : server.getConnectors()) {
                        if (connector instanceof ServerConnector) {
                            HttpConnectionFactory connectionFactory = connector.getConnectionFactory(HttpConnectionFactory.class);
                            connectionFactory.getHttpConfiguration().setSendServerVersion(false);
                        }
                    }
                }
            });
        }
    };
}
项目:http-digest-auth    文件:RunJetty.java   
private static void defaultServerConfig(int port, boolean loopback) {
    server = new Server() ;
    HttpConnectionFactory f1 = new HttpConnectionFactory() ;
    // Some people do try very large operations ... really, should use POST.
    f1.getHttpConfiguration().setRequestHeaderSize(512 * 1024);
    f1.getHttpConfiguration().setOutputBufferSize(5 * 1024 * 1024) ;

    //SslConnectionFactory f2 = new SslConnectionFactory() ;

    ServerConnector connector = new ServerConnector(server, f1) ; //, f2) ;
    connector.setPort(port) ;
    server.addConnector(connector);
    if ( loopback )
        connector.setHost("localhost");
    serverConnector = connector ;
}
项目:scheduling    文件:ErrorCases.java   
@BeforeClass
public static void startHttpsServer() throws Exception {
    skipIfHeadlessEnvironment();
    server = new Server();

    SslContextFactory sslContextFactory = new SslContextFactory();
    sslContextFactory.setKeyStorePath(ErrorCases.class.getResource("keystore").getPath());
    sslContextFactory.setKeyStorePassword("activeeon");

    HttpConfiguration httpConfig = new HttpConfiguration();
    HttpConfiguration httpsConfig = new HttpConfiguration(httpConfig);
    httpsConfig.addCustomizer(new SecureRequestCustomizer());

    ServerConnector sslConnector = new ServerConnector(server,
                                                       new ConnectionFactory[] { new SslConnectionFactory(sslContextFactory,
                                                                                                          HttpVersion.HTTP_1_1.asString()),
                                                                                 new HttpConnectionFactory(httpsConfig) });

    server.addConnector(sslConnector);
    server.start();
    serverUrl = "https://localhost:" + sslConnector.getLocalPort() + "/rest";
}
项目:scheduling    文件:JettyStarterTest.java   
@Test
public void testCreateHttpServerUsingHttpsAndRedirection() {
    createHttpsContextProperties();

    server = jettyStarter.createHttpServer(8080, 8443, true, true);

    Connector[] connectors = server.getConnectors();

    assertThat(connectors).hasLength(2);
    assertThat(connectors[0].getName()).isEqualTo(JettyStarter.HTTP_CONNECTOR_NAME);
    assertThat(connectors[0].getConnectionFactory(HttpConnectionFactory.class)).isNotNull();
    assertThat(connectors[1].getName()).isEqualTo(JettyStarter.HTTPS_CONNECTOR_NAME.toLowerCase());
    assertThat(connectors[1].getConnectionFactory(HttpConnectionFactory.class)).isNotNull();
    assertThat(connectors[1].getConnectionFactory(SslConnectionFactory.class)).isNotNull();

    unsetHttpsContextProperties();
}
项目:fw    文件:Application.java   
public void listener(int port) {
    initJettyConfig();

    this.port = port;
    HttpConfiguration httpConfiguration = initHttpConfiguration();
    HttpConnectionFactory httpConnectionFactory = new HttpConnectionFactory(httpConfiguration);

    QueuedThreadPool threadPool = this.initThreadPool();
    this.server = new Server(threadPool);
    int cores = Runtime.getRuntime().availableProcessors();
    ServerConnector connector = new ServerConnector(server, null, null, null, 1 + cores / 2, -1,
            httpConnectionFactory);
    initConnector(connector);
    connector.setPort(this.port);
    server.setConnectors(new Connector[] { connector });
    logger.info("Application listen on " + port);
}
项目:CrococryptFile    文件:JettyStart.java   
public static boolean startup(int port) {
    Server server = new Server(port);

       ServletHandler handler = new ServletHandler();
       handler.addServletWithMapping(CrocoWebDecryptor.class, "/*");

    for(Connector y : server.getConnectors()) {
        for(ConnectionFactory x  : y.getConnectionFactories()) {
            if(x instanceof HttpConnectionFactory) {
                ((HttpConnectionFactory)x).getHttpConfiguration().setSendServerVersion(false);
            }
        }
    }

    server.setHandler(handler);
    try {
        server.start();
        return true;
    } catch (Exception e) {
        try {
            server.stop();
        } catch (Exception e2) {}
    }

    return false;
}
项目:mysql_perf_analyzer    文件:App.java   
/**
 * Create ssl connector if https is used
 * @return
 */
private ServerConnector sslConnector() {
    HttpConfiguration http_config = new HttpConfiguration();
    http_config.setSecureScheme("https");
    http_config.setSecurePort(this.getPort());

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

    SslContextFactory sslContextFactory = new SslContextFactory(this.getCertKeyStorePath());
    sslContextFactory.setKeyStorePassword(this.getCertKeyStorePassword());
    //exclude weak ciphers
    sslContextFactory.setExcludeCipherSuites("^.*_(MD5|SHA|SHA1)$");
    //only support tlsv1.2
    sslContextFactory.addExcludeProtocols("SSL", "SSLv2", "SSLv2Hello", "SSLv3", "TLSv1", "TLSv1.1");

    ServerConnector connector = new ServerConnector(jettyServer, 
            new SslConnectionFactory(sslContextFactory, "http/1.1"),
            new HttpConnectionFactory(https_config));
    connector.setPort(this.getPort());
    connector.setIdleTimeout(50000);
    return connector;
}
项目:ProcessPool    文件:PoolWatcher.java   
/**
 * Start the Jetty Server on the specified port
 * @throws Exception
 */
private static void startServer() throws Exception {
    HttpConfiguration http_config = new HttpConfiguration();
    http_config.setSecureScheme("https");
    http_config.setSecurePort(8443);
    http_config.setOutputBufferSize(32768);
    Server server = new Server();
    ServerConnector http = new ServerConnector(server,
            new HttpConnectionFactory(http_config));
    http.setPort(_port);
    http.setIdleTimeout(30000);
    server.setConnectors(new Connector[] { http });

    // Set a handler
    server.setHandler(new PoolWatcher());

    // Start the server
    server.start();
}
项目:armeria    文件:ThriftOverHttpClientTServletIntegrationTest.java   
private static Server startHttp2() throws Exception {
    Server server = new Server();
    // Common HTTP configuration.
    HttpConfiguration config = new HttpConfiguration();

    // HTTP/1.1 support.
    HttpConnectionFactory http1 = new HttpConnectionFactory(config);

    // HTTP/2 cleartext support.
    HTTP2CServerConnectionFactory http2c = new HTTP2CServerConnectionFactory(config);

    // Add the connector.
    ServerConnector connector = new ServerConnector(server, http1, http2c);
    connector.setPort(0);
    server.addConnector(connector);

    // Add the servlet.
    ServletHandler handler = new ServletHandler();
    handler.addServletWithMapping(newServletHolder(thriftServlet), TSERVLET_PATH);
    server.setHandler(handler);

    // Start the server.
    server.start();
    return server;
}
项目:ManagedProperties    文件:EmbeddableJetty.java   
public EmbeddableJetty() {
    System.setProperty("wicket.configuration", "development");

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

    server.addConnector(http);

    ServletContextHandler sch = new ServletContextHandler(ServletContextHandler.SESSIONS);
    FilterHolder fh2 = new FilterHolder(WicketFilter.class);
    fh2.setInitParameter(ContextParamWebApplicationFactory.APP_CLASS_PARAM, WicketTestApplication.class.getName());
    fh2.setInitParameter(WicketFilter.FILTER_MAPPING_PARAM, "/*");
    sch.addFilter(fh2, "/*", EnumSet.of(DispatcherType.REQUEST, DispatcherType.ERROR));

    server.setHandler(sch);

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

}
项目:chaos-http-proxy    文件:ChaosHttpProxy.java   
public ChaosHttpProxy(URI endpoint, ChaosConfig config)
        throws Exception {
    setChaosConfig(config);

    Supplier<Failure> supplier = new RandomFailureSupplier(
            config.getFailures());

    requireNonNull(endpoint);

    client = new HttpClient();

    server = new Server();
    HttpConnectionFactory httpConnectionFactory =
            new HttpConnectionFactory();
    // TODO: SSL
    ServerConnector connector = new ServerConnector(server,
            httpConnectionFactory);
    connector.setHost(endpoint.getHost());
    connector.setPort(endpoint.getPort());
    server.addConnector(connector);
    this.handler = new ChaosHttpProxyHandler(client, supplier);
    HandlerList handlers = new HandlerList();
    handlers.addHandler(new ChaosApiHandler(this, handler));
    handlers.addHandler(handler);
    server.setHandler(handlers);
}
项目:CrococryptQuerl    文件:JettyLaunch.java   
public static boolean startup(int port) {
    Server server = new Server(port);

       ServletHandler handler = new ServletHandler();
       handler.addServletWithMapping(Querler.class, "/*");

    for(Connector y : server.getConnectors()) {
        for(ConnectionFactory x  : y.getConnectionFactories()) {
            if(x instanceof HttpConnectionFactory) {
                ((HttpConnectionFactory)x).getHttpConfiguration().setSendServerVersion(false);
            }
        }
    }

    server.setHandler(handler);
    try {
        server.start();
        return true;
    } catch (Exception e) {
        try {
            server.stop();
        } catch (Exception e2) {}
    }

    return false;
}
项目:datacollector    文件:TestWebServicesFetcher.java   
protected Server createServer(int port, boolean serverSsl, boolean clientSsl) {
  Server server = new Server();
  if (!serverSsl) {
    InetSocketAddress addr = new InetSocketAddress("localhost", port);
    ServerConnector connector = new ServerConnector(server);
    connector.setHost(addr.getHostName());
    connector.setPort(addr.getPort());
    server.setConnectors(new Connector[]{connector});
  } else {
    SslContextFactory sslContextFactory = createSslContextFactory(clientSsl);
    ServerConnector httpsConnector = new ServerConnector(server,
        new SslConnectionFactory(sslContextFactory, "http/1.1"),
        new HttpConnectionFactory()
    );
    httpsConnector.setPort(port);
    httpsConnector.setHost("localhost");
    server.setConnectors(new Connector[]{httpsConnector});
  }
  return server;
}
项目:scale.commons    文件:TestBaseServerBuilder.java   
@Test
public void http() throws Exception {
    Server server = BaseServerBuilder.create().httpPort(8080).build();

    List<Connector> connectors = Arrays.asList(server.getConnectors());
    assertThat(server.getConnectors().length, is(1));
    // should have a server connector on port 8080
    ServerConnector connector = (ServerConnector) connectors.get(0);
    assertThat(connector.getPort(), is(8080));

    // should have a http connection factory
    HttpConnectionFactory httpConnectionFactory = connector.getConnectionFactory(HttpConnectionFactory.class);
    assertThat(httpConnectionFactory, is(notNullValue()));

    // no https redirect port should be set
    assertThat(httpConnectionFactory.getHttpConfiguration().getSecurePort(), is(0));
}
项目:scale.commons    文件:TestBaseServerBuilder.java   
@Test
public void httpAndHttps() {
    Server server = BaseServerBuilder.create().httpPort(8080).httpsPort(8443)
            .sslKeyStoreType(SslKeyStoreType.PKCS12).sslKeyStorePath(ETC_SECURITY + "/server_keystore.p12")
            .sslKeyStorePassword("pkcs12password").sslTrustStoreType(SslKeyStoreType.JKS).sslRequireClientCert(true)
            .sslTrustStorePath(ETC_SECURITY + "/server_truststore.jks").sslTrustStorePassword("truststorepassword")
            .sslRequireClientCert(true).build();

    List<Connector> connectors = Arrays.asList(server.getConnectors());
    assertThat(server.getConnectors().length, is(2));
    // should have a server connector on port 8080
    ServerConnector httpConnector = (ServerConnector) connectors.get(0);
    assertThat(httpConnector.getPort(), is(8080));
    // should have a server connector on port 8443
    ServerConnector httpsConnector = (ServerConnector) connectors.get(1);
    assertThat(httpsConnector.getPort(), is(8443));

    // should redirect secure connections to https port
    HttpConnectionFactory httpFactory = httpConnector.getConnectionFactory(HttpConnectionFactory.class);
    assertThat(httpFactory, is(notNullValue()));
    assertThat(httpFactory.getHttpConfiguration().getSecurePort(), is(8443));
    assertThat(httpFactory.getHttpConfiguration().getSecureScheme(), is("https"));
}
项目:helix    文件:HelixRestServer.java   
public void setupSslServer(int port, SslContextFactory sslContextFactory) {
  if (_server != null && port > 0) {
    try {
      HttpConfiguration https = new HttpConfiguration();
      https.addCustomizer(new SecureRequestCustomizer());
      ServerConnector sslConnector = new ServerConnector(
          _server,
          new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()),
          new HttpConnectionFactory(https));
      sslConnector.setPort(port);

      _server.addConnector(sslConnector);

      LOG.info("Helix SSL rest server is ready to start.");
    } catch (Exception ex) {
      LOG.error("Failed to setup Helix SSL rest server, " + ex);
    }
  }
}
项目:yuicompressor-server    文件:YuiCompressorServer.java   
/**
 * Set up the server with all its dependencies
 * 
 * @param configuration
 */
public YuiCompressorServer(Configuration configuration) {
    hasher = new Md5Hasher();

    server = new Server(getThreadPool());
    HttpConfiguration http_config = getHttpConfiguration();

    ServerConnector http = new ServerConnector(server,
            new HttpConnectionFactory(http_config));
    http.setPort(configuration.getPort());
    http.setIdleTimeout(CONECTION_IDLE_TIMEOUT);
    server.addConnector(http);
    server.setAttribute(MAX_FORM_SIZE_PROPERTY,
            configuration.getMaxFormSize());
    server.setHandler(new YuiCompressorHandler(
            getCompressor(configuration), hasher));
}
项目:android-gps-emulator    文件:Main.java   
/**
 * @param args
 */
public static void main(String[] args) throws Exception
{
    Server server = new Server();

    HttpConfiguration config = new HttpConfiguration();
    ServerConnector http = new ServerConnector(server, new HttpConnectionFactory(config));

    int port = 8080;
    if (args.length > 0) {
        port = Integer.parseInt(args[0]);
    }

    http.setPort(port);
    server.addConnector(http);

    ProtectionDomain domain = Main.class.getProtectionDomain();
    URL location = domain.getCodeSource().getLocation();
    WebAppContext webapp = new WebAppContext();
    webapp.setContextPath("/");
    webapp.setWar(location.toExternalForm());
    server.setHandler(webapp);

    server.start();
    server.join();
}
项目:sequenceiq-samples    文件:JettyWebSocketServer.java   
@Override
public void startSSL(String keyStoreLocation, String keyStorePassword) throws Exception {
    Server server = new Server();

    HttpConfiguration httpsConfig = new HttpConfiguration();
    httpsConfig.addCustomizer(new SecureRequestCustomizer());
    SslContextFactory sslContextFactory = new SslContextFactory();
    sslContextFactory.setKeyStorePath(keyStoreLocation);
    sslContextFactory.setKeyStorePassword(keyStorePassword);
    ServerConnector https = new ServerConnector(server,
            new SslConnectionFactory(sslContextFactory, "http/1.1"),
            new HttpConnectionFactory(httpsConfig));
    https.setHost(host);
    https.setPort(port);
    server.setConnectors(new Connector[]{https});

    configureContextHandler(server);
    startServer(server);
}
项目:codeexamples-eclipse    文件:StartJettyHandler.java   
@Execute
public void execute()  throws Exception{
    Runnable runnable = new Runnable() {
        @Override
        public void run() {
            Server server = new Server(8080);
            try {
                server.getConnectors()[0].getConnectionFactory(HttpConnectionFactory.class);
                server.setHandler(new HelloHttpRequestHandler());

                server.start();
                server.join();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    };
    new Thread(runnable).start();


}
项目:wandora    文件:WandoraJettyServer.java   
public void start(){
    try{
        jettyServer=new Server(port);

        HttpConfiguration httpConfiguration = new HttpConfiguration();
        ConnectionFactory c = new HttpConnectionFactory(httpConfiguration);

        ServerConnector serverConnector = new ServerConnector(jettyServer, c);
        serverConnector.setPort(port);

        jettyServer.setConnectors(new Connector[] { serverConnector });

        jettyServer.setHandler(requestHandler);
        jettyServer.start();

        if(statusButton!=null){
            updateStatusIcon();
            iconThread=new IconThread();
            iconThread.start();
        }
    }
    catch(Exception e){
        wandora.handleError(e);
    }
}
项目:Doradus    文件:JettyWebServer.java   
private ServerConnector createSSLConnector() {
    SslContextFactory sslContextFactory = new SslContextFactory();
    sslContextFactory.setKeyStorePath(m_keystore);
    sslContextFactory.setKeyStorePassword(m_keystorepassword);
    sslContextFactory.setTrustStorePath(m_truststore);
    sslContextFactory.setTrustStorePassword(m_truststorepassword);
    sslContextFactory.setNeedClientAuth(m_clientauthentication);
    sslContextFactory.setIncludeCipherSuites(m_tls_cipher_suites);

    HttpConfiguration http_config = new HttpConfiguration();
    http_config.setSecureScheme("https");
    HttpConfiguration https_config = new HttpConfiguration(http_config);
    https_config.addCustomizer(new SecureRequestCustomizer());
    SslConnectionFactory sslConnFactory = new SslConnectionFactory(sslContextFactory, "http/1.1");
    HttpConnectionFactory httpConnFactory = new HttpConnectionFactory(https_config);
    ServerConnector sslConnector = new ServerConnector(m_jettyServer, sslConnFactory, httpConnFactory);
    return sslConnector;
}
项目:cloudstore    文件:CloudStoreServer.java   
private ServerConnector createServerConnectorForHTTPS(final Server server, final HttpConfiguration httpConfigurationForHTTPS) {
        final SslContextFactory sslContextFactory = new SslContextFactory();
        sslContextFactory.setKeyStorePath(getKeyStoreFile().getPath());
        sslContextFactory.setKeyStorePassword(KEY_STORE_PASSWORD_STRING);
        sslContextFactory.setKeyManagerPassword(KEY_PASSWORD_STRING);
        sslContextFactory.setTrustStorePath(getKeyStoreFile().getPath());
        sslContextFactory.setTrustStorePassword(KEY_STORE_PASSWORD_STRING);

        sslContextFactory.setExcludeCipherSuites( // TODO make this configurable!
//              "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",
// Using wildcards instead. This should be much safer:
                ".*RC4.*",
                ".*DES.*");
        //        sslContextFactory.setCertAlias(CERTIFICATE_ALIAS); // Jetty uses our certificate. We put only one single cert into the key store. Hence, we don't need this.

        final ServerConnector sslConnector = new ServerConnector(server, new SslConnectionFactory(sslContextFactory, "http/1.1"), new HttpConnectionFactory(httpConfigurationForHTTPS));
        sslConnector.setPort(getSecurePort());
//      sslConnector.setIdleTimeout(300*1000);
//      sslConnector.setStopTimeout(30*1000);
//      sslConnector.setSoLingerTime(10);
        return sslConnector;
    }
项目:feathercon    文件:FeatherCon.java   
private Integer getPort(Scheme scheme) {
    for (Connector connector : server.getConnectors()) {
        if (connector instanceof ServerConnector) {
            ServerConnector serverConnector = (ServerConnector) connector;
            Collection<ConnectionFactory> connectionFactories = serverConnector.getConnectionFactories();
            for (ConnectionFactory connectionFactory : connectionFactories) {
                Class<? extends AbstractConnectionFactory> connectorClass;
                switch (scheme) {
                    case HTTP:
                        connectorClass = HttpConnectionFactory.class;
                        break;
                    case HTTPS:
                        connectorClass = SslConnectionFactory.class;
                        break;
                    default:
                        throw new UnsupportedOperationException("No such scheme.");
                }
                if (connectorClass.isAssignableFrom(connectionFactory.getClass())) {
                    return serverConnector.getLocalPort();
                }
            }
        }
    }
    return null;
}
项目:jlubricant    文件:HttpConnectivity.java   
public Connector doInstall(Server server){

    // shared http config
    HttpConfiguration http_config = new HttpConfiguration();
    http_config.setSecureScheme("https");
    http_config.setSecurePort(8443);
    http_config.setOutputBufferSize(32768);

    // HTTP connector #1
    ServerConnector http = new ServerConnector(server, new HttpConnectionFactory(http_config));
    http.setPort(httpPort);
    http.setIdleTimeout(idleTimeout == null ? 30000 : idleTimeout);
    if(host != null){
        http.setHost(host);         
    }

    return http;

}
项目:buck    文件:HttpdForTests.java   
public HttpdForTests() throws SocketException {
  // Configure the logging for jetty. Which uses a singleton. Ho hum.
  Log.setLog(new JavaUtilLog());
  server = new Server();

  ServerConnector connector = new ServerConnector(server);
  connector.addConnectionFactory(new HttpConnectionFactory());
  // Choose a port randomly upon listening for socket connections.
  connector.setPort(0);
  server.addConnector(connector);

  handlerList = new HandlerList();
  localhost = getLocalhostAddress().getHostAddress();
}
项目:joynr    文件:ServersUtil.java   
private static Server startServer(ContextHandlerCollection contexts, int port) throws Exception {
    System.setProperty(MessagingPropertyKeys.PROPERTY_SERVLET_HOST_PATH, "http://localhost:" + port);
    setBounceProxyUrl();
    setDirectoriesUrl();
    logger.info("HOST PATH: {}", System.getProperty(MessagingPropertyKeys.PROPERTY_SERVLET_HOST_PATH));

    final Server jettyServer = new Server();
    ServerConnector connector = new ServerConnector(jettyServer, new HttpConnectionFactory(new HttpConfiguration()));
    connector.setPort(port);
    connector.setAcceptQueueSize(1);
    jettyServer.setConnectors(new Connector[]{ connector });

    jettyServer.setHandler(contexts);
    jettyServer.start();

    logger.trace("Started jetty server:\n{}", jettyServer.dump());

    return jettyServer;
}
项目:ngWebDriver    文件:AngularAndWebDriverTest.java   
@BeforeSuite
public void before_suite() throws Exception {

    // Launch Protractor's own test app on http://localhost:8080
    ((StdErrLog) Log.getRootLogger()).setLevel(StdErrLog.LEVEL_OFF);
    webServer = new Server(new QueuedThreadPool(6));
    ServerConnector connector = new ServerConnector(webServer, new HttpConnectionFactory());
    connector.setPort(8080);
    webServer.addConnector(connector);
    ResourceHandler resource_handler = new ResourceHandler();
    resource_handler.setDirectoriesListed(true);
    resource_handler.setWelcomeFiles(new String[]{"index.html"});
    resource_handler.setResourceBase("src/test/webapp");
    HandlerList handlers = new HandlerList();
    MovedContextHandler effective_symlink = new MovedContextHandler(webServer, "/lib/angular", "/lib/angular_v1.2.9");
    handlers.setHandlers(new Handler[] { effective_symlink, resource_handler, new DefaultHandler() });
    webServer.setHandler(handlers);
    webServer.start();

    driver = new ChromeDriver();
    driver.manage().timeouts().setScriptTimeout(30, TimeUnit.SECONDS);
    ngWebDriver = new NgWebDriver(driver);
}
项目:debug    文件:Profiling.java   
public static void startServer() throws ServletException {
    QueuedThreadPool threadPool = new QueuedThreadPool(10);
    threadPool.setDaemon(true);
    threadPool.setMaxThreads(10);
    Server server = new Server(threadPool);
    server.addBean(new ScheduledExecutorScheduler("JettyScheduler", true), true);
    ServerConnector http = new ServerConnector(server, new HttpConnectionFactory());
    http.setPort(2992);
    server.addConnector(http);

    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
    context.setContextPath("/");
    context.setBaseResource(Resource.newClassPathResource("/org/lwjglx/debug/static"));
    context.setWelcomeFiles(new String[] { "index.html" });
    server.setHandler(context);

    WebSocketUpgradeFilter wsfilter = WebSocketUpgradeFilter.configureContext(context);
    // wsfilter.getFactory().getPolicy().setIdleTimeout(5000);
    wsfilter.addMapping(new ServletPathSpec("/ws"), new ProfilingConnectionCreator());

    ServletHolder holderDefault = new ServletHolder("default", DefaultServlet.class);
    holderDefault.setInitParameter("dirAllowed", "true");
    context.addServlet(holderDefault, "/");

    try {
        server.start();
    } catch (Exception e) {
        throw new AssertionError("Could not start profiling server", e);
    }
}
项目:QDrill    文件:WebServer.java   
/**
 * Create HTTP connector.
 * @return Initialized {@link ServerConnector} instance for HTTP connections.
 * @throws Exception
 */
private ServerConnector createHttpConnector() throws Exception {
  logger.info("Setting up HTTP connector for web server");
  final HttpConfiguration httpConfig = new HttpConfiguration();
  final ServerConnector httpConnector = new ServerConnector(embeddedJetty, new HttpConnectionFactory(httpConfig));
  httpConnector.setPort(config.getInt(ExecConstants.HTTP_PORT));

  return httpConnector;
}
项目:Cognizant-Intelligent-Test-Scripter    文件:EventServer.java   
private ServerConnector getServerConnector() {
    SslConnectionFactory sslConnectionFactory = getSSLConnectionFactory();
    HttpConnectionFactory httpConnectionFactory = new HttpConnectionFactory(new HttpConfiguration());
    ServerConnector connector = new ServerConnector(server, sslConnectionFactory, httpConnectionFactory);
    connector.setPort(port);
    return connector;
}
项目:webserver    文件:HTTPSConnectorFactory.java   
@Override
public ServerConnector get(Server server) {
  HttpConfiguration configuration = new HttpConfiguration(defaultConfig);
  configuration.setSecurePort(configurator.getPort());
  configuration.setSecureScheme(HttpScheme.HTTPS.asString());

  final ServerConnector connector = new ServerConnector(server, new HttpConnectionFactory(configuration));
  connector.setPort(configurator.getPort());
  connector.setHost(configurator.getHost());

  return connector;
}
项目:webserver    文件:HTTPConnectorFactory.java   
public ServerConnector get(Server server) {
  HttpConfiguration configuration = new HttpConfiguration(defaultConfig);

  final ServerConnector connector = new ServerConnector(server, new HttpConnectionFactory(configuration));
  connector.setPort(configurator.getPort());
  connector.setHost(configurator.getHost());

  return connector;
}