当前位置: 首页>>代码示例>>Java>>正文


Java HttpsParameters类代码示例

本文整理汇总了Java中com.sun.net.httpserver.HttpsParameters的典型用法代码示例。如果您正苦于以下问题:Java HttpsParameters类的具体用法?Java HttpsParameters怎么用?Java HttpsParameters使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


HttpsParameters类属于com.sun.net.httpserver包,在下文中一共展示了HttpsParameters类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createHttpServerInstance

import com.sun.net.httpserver.HttpsParameters; //导入依赖的package包/类
@Override
public HttpServer createHttpServerInstance(final int port) throws IOException {
    try {
        final HttpsServer server = HttpsServer.create(new InetSocketAddress(port), 5);
        server.setHttpsConfigurator(new HttpsConfigurator(sslContext) {
            @Override
            public void configure(final HttpsParameters params) {
                final SSLContext c = getSSLContext();

                // get the default parameters
                final SSLParameters sslparams = c.getDefaultSSLParameters();

                params.setSSLParameters(sslparams);
                // statement above could throw IAE if any params invalid.
                // eg. if app has a UI and parameters supplied by a user.
            }
        });

        s_logger.info("create HTTPS server instance on port: " + port);
        return server;
    } catch (final Exception ioe) {
        s_logger.error(ioe.toString(), ioe);
    }
    return null;
}
 
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:26,代码来源:ConsoleProxySecureServerFactoryImpl.java

示例2: startHttpsServer

import com.sun.net.httpserver.HttpsParameters; //导入依赖的package包/类
protected void startHttpsServer() throws Exception {
  final InetSocketAddress addr = new InetSocketAddress(httpsServerPort);
  httpsServer = HttpsServer.create(addr, 0);
  httpsServer.setExecutor(Executors.newCachedThreadPool());
  attachHttpHandlers(httpsServer);

  final char[] passphrase = KEYSTORE_PASSWORD.toCharArray();
  final KeyStore ks = KeyStore.getInstance("JKS");
  ks.load(getKeyStore(), passphrase);

  final KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
  kmf.init(ks, passphrase);

  final TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
  tmf.init(ks);

  final SSLContext ssl = SSLContext.getInstance("TLS");
  ssl.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);

  httpsServer.setHttpsConfigurator(new HttpsConfigurator(ssl) {
    @Override
    public void configure(final HttpsParameters params) {
      final SSLContext c = getSSLContext();
      final SSLParameters sslparams = c.getDefaultSSLParameters();
      params.setSSLParameters(sslparams);
    }
  });

  httpsServer.start();
}
 
开发者ID:antlibs,项目名称:ant-http,代码行数:31,代码来源:AbstractHttpServerTest.java

示例3: createHttpServerInstance

import com.sun.net.httpserver.HttpsParameters; //导入依赖的package包/类
@Override
public HttpServer createHttpServerInstance(int port) throws IOException {
    try {
        HttpsServer server = HttpsServer.create(new InetSocketAddress(port), 5);
        server.setHttpsConfigurator(new HttpsConfigurator(sslContext) {
            @Override
            public void configure(HttpsParameters params) {

                // get the remote address if needed
                InetSocketAddress remote = params.getClientAddress();
                SSLContext c = getSSLContext();

                // get the default parameters
                SSLParameters sslparams = c.getDefaultSSLParameters();

                params.setSSLParameters(sslparams);
                params.setProtocols(SSLUtils.getRecommendedProtocols());
                params.setCipherSuites(SSLUtils.getRecommendedCiphers());
                // statement above could throw IAE if any params invalid.
                // eg. if app has a UI and parameters supplied by a user.
            }
        });

        s_logger.info("create HTTPS server instance on port: " + port);
        return server;
    } catch (Exception ioe) {
        s_logger.error(ioe.toString(), ioe);
    }
    return null;
}
 
开发者ID:apache,项目名称:cloudstack,代码行数:31,代码来源:ConsoleProxySecureServerFactoryImpl.java

示例4: shouldSetHttpsParametersOnEveryRequest

import com.sun.net.httpserver.HttpsParameters; //导入依赖的package包/类
@Test
public void shouldSetHttpsParametersOnEveryRequest() throws Exception {
    // setup
    final SSLParameters defaultSslParameters = mock(SSLParameters.class);
    final String[] cipherSuites = new String[0];
    final String[] protocols = new String[0];
    SSLEngine sslEngine = mock(SSLEngine.class);
    when(sslEngine.getEnabledCipherSuites()).thenReturn(cipherSuites);
    when(sslEngine.getEnabledProtocols()).thenReturn(protocols);

    when(sslContext.getDefaultSSLParameters()).thenReturn(defaultSslParameters);
    when(sslContext.createSSLEngine()).thenReturn(sslEngine);

    doAnswer(new Answer<Object>() {
        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {

            HttpsParameters httpsParameters = mock(HttpsParameters.class);

            HttpsConfigurator httpsConfigurator = (HttpsConfigurator) invocation.getArguments()[0];
            httpsConfigurator.configure(httpsParameters);

            verify(httpsParameters).setSSLParameters(defaultSslParameters);
            verify(httpsParameters).setNeedClientAuth(false);
            verify(httpsParameters).setWantClientAuth(false);
            verify(httpsParameters).setCipherSuites(cipherSuites);
            verify(httpsParameters).setProtocols(protocols);

            return null;
        }
    }).when(httpsServer).setHttpsConfigurator(isA(HttpsConfigurator.class));

    // act
    HttpServer result = simpleHttpsServerFactoryBean.getInitializedServer(inetSocketAddress);

    // assert
    verify(httpsServer).setHttpsConfigurator(isA(HttpsConfigurator.class));
    assertEquals(httpsServer, result);
}
 
开发者ID:barnyard,项目名称:pi,代码行数:40,代码来源:SimpleHttpsServerFactoryBeanTest.java

示例5: getConfigurator

import com.sun.net.httpserver.HttpsParameters; //导入依赖的package包/类
private HttpsConfigurator getConfigurator(SSLContext sslContext) {
  return new HttpsConfigurator(sslContext) {
        @Override
        public void configure (HttpsParameters params) {
          SSLContext context = getSSLContext();
          SSLParameters sslParams = context.getDefaultSSLParameters();
          params.setNeedClientAuth(false);
          params.setSSLParameters(sslParams);
        }
      };
}
 
开发者ID:languagetool-org,项目名称:languagetool,代码行数:12,代码来源:HTTPSServer.java

示例6: configure

import com.sun.net.httpserver.HttpsParameters; //导入依赖的package包/类
public void configure(HttpsParameters params) {
    params.setSSLParameters(getSSLContext().getSupportedSSLParameters());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:4,代码来源:ManyRequests.java

示例7: configure

import com.sun.net.httpserver.HttpsParameters; //导入依赖的package包/类
@Override
public void configure (HttpsParameters params) {
    params.setSSLParameters (getSSLContext().getSupportedSSLParameters());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:5,代码来源:ProxyTest.java

示例8: configure

import com.sun.net.httpserver.HttpsParameters; //导入依赖的package包/类
public void configure (HttpsParameters params) {
    params.setSSLParameters (getSSLContext().getSupportedSSLParameters());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:4,代码来源:SmokeTest.java

示例9: setUpHttps

import com.sun.net.httpserver.HttpsParameters; //导入依赖的package包/类
private static HttpServer setUpHttps(JSONObject config) throws Exception {
    HttpServer server = HttpsServer.create(new InetSocketAddress(config.getInt("httpsPort")), 0);
    SSLContext sslContext = SSLContext.getInstance("TLS");

    // initialise the keystore
    char[] password = "84267139".toCharArray();
    KeyStore ks = KeyStore.getInstance("JKS");
    FileInputStream fis = new FileInputStream("www_turtledev_org.jks");
    ks.load(fis, password);
    // setup the key manager factory
    KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
    kmf.init(ks, password);

    // setup the trust manager factory
    TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");
    tmf.init(ks);

    // setup the HTTPS context and parameters
    sslContext.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
    ((HttpsServer) server).setHttpsConfigurator(new HttpsConfigurator(sslContext) {
        @Override
        public void configure(HttpsParameters params) {
            try {
                // initialise the SSL context
                SSLContext c = SSLContext.getDefault();
                SSLEngine engine = c.createSSLEngine();
                params.setNeedClientAuth(false);
                params.setCipherSuites(engine.getEnabledCipherSuites());
                params.setProtocols(engine.getEnabledProtocols());

                // get the default parameters
                SSLParameters defaultSSLParameters = c.getDefaultSSLParameters();
                params.setSSLParameters(defaultSSLParameters);

            } catch (NoSuchAlgorithmException ex) {
                System.out.println("Failed to create HTTPS port");
            }
        }
    });
    return server;
}
 
开发者ID:sherisaac,项目名称:TurteTracker_APIServer,代码行数:42,代码来源:Server.java

示例10: initHttpsServer

import com.sun.net.httpserver.HttpsParameters; //导入依赖的package包/类
public void initHttpsServer(int port, String sslPassword)
{
  try
  {
    this.server = HttpsServer.create(new InetSocketAddress(port), 0);
    SSLContext sslContext = SSLContext.getInstance("TLS");
    char[] password = sslPassword.toCharArray();
    KeyStore ks = KeyStore.getInstance("JKS");
    FileInputStream fis = new FileInputStream("https_key.jks");
    ks.load(fis, password);
    KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
    kmf.init(ks, password);
    TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");
    tmf.init(ks);
    sslContext.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
    this.server.setHttpsConfigurator(new HttpsConfigurator(sslContext)
    {
      @Override
      public void configure(HttpsParameters params)
      {
        try
        {
          SSLContext c = SSLContext.getDefault();
          SSLEngine engine = c.createSSLEngine();
          params.setNeedClientAuth(false);
          params.setCipherSuites(engine.getEnabledCipherSuites());
          params.setProtocols(engine.getEnabledProtocols());
          SSLParameters defaultSSLParameters = c.getDefaultSSLParameters();
          params.setSSLParameters(defaultSSLParameters);
        }
        catch (Exception ex)
        {
          System.out.println("Failed to create HTTPS port");
        }
      }
    });
    this.server.setExecutor(null); // creates a default executor
  }
  catch (Exception e)
  {
    System.out.println("Exception while starting RequestListener.");
    e.printStackTrace();
  }
}
 
开发者ID:Malow,项目名称:GladiatorManager,代码行数:45,代码来源:HttpsApiServer.java

示例11: Start

import com.sun.net.httpserver.HttpsParameters; //导入依赖的package包/类
public void Start(int port) {
  try {
    // load certificate
    String keystoreFilename =  Constants.KEY_STORE_FILE;
    char[] storepass = Constants.KEY_STORE_PASSWORD.toCharArray();
    char[] keypass = Constants.KEY_STORE_PASSWORD.toCharArray();
    FileInputStream fIn = new FileInputStream(Constants.SERVER_PATH + keystoreFilename);
    KeyStore keystore = KeyStore.getInstance(KEY_STORE);
    keystore.load(fIn, storepass);

    // setup the key manager factory
    KeyManagerFactory kmf = KeyManagerFactory.getInstance(KEY_MANAGER_FACTORY);
    kmf.init(keystore, keypass);

    // setup the trust manager factory
    TrustManagerFactory tmf = TrustManagerFactory.getInstance(KEY_MANAGER_FACTORY);
    tmf.init(keystore);

    // create https server
    server = HttpsServer.create(new InetSocketAddress(port), 0);
    // create ssl context
    SSLContext sslContext = SSLContext.getInstance(protocol);
    // setup the HTTPS context and parameters
    sslContext.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
    server.setHttpsConfigurator(new HttpsConfigurator(sslContext) {
      public void configure(HttpsParameters params) {
        try {

          // initialise the SSL context
          SSLContext c = SSLContext.getDefault();
          SSLEngine engine = c.createSSLEngine();
          params.setNeedClientAuth(false);
          params.setCipherSuites(engine.getEnabledCipherSuites());
          params.setProtocols(engine.getEnabledProtocols());

          // get the default parameters
          SSLParameters defaultSSLParameters = c.getDefaultSSLParameters();
          params.setSSLParameters(defaultSSLParameters);



        } catch (Exception ex) {
          System.err.println(Errors.START_HTTPS_SERVER);
        }
      }
    });
    System.out.println(SERVER_STARTED + port);
    server.createContext(ROOT_ENDPOINT, new OAuthHandler.RootHandler());
    server.createContext(OAUTH_ENDPOINT, new OAuthHandler.AuthorizationHandler());
    server.createContext(REDIRECT_ENDPOINT, new OAuthHandler.RedirectUriHandler());
    server.setExecutor(null);
    server.start();
  } catch (Exception e) {
    System.err.println(e);
  }
}
 
开发者ID:adobe-sign,项目名称:AdobeSignJavaSdk,代码行数:57,代码来源:LocalHttpsServer.java

示例12: start

import com.sun.net.httpserver.HttpsParameters; //导入依赖的package包/类
public Boolean start() {
    try {
        final Integer maxQueue = 256;
        final Executor executor = Executors.newFixedThreadPool(maxQueue);

        if (_useEncryption) {
            final HttpsServer httpsServer = HttpsServer.create(new InetSocketAddress(_tlsPort), maxQueue);
            final TlsCertificate tlsCertificate = TlsFactory.loadTlsCertificate(StringUtil.bytesToString(IoUtil.getFileContents(_certificateFile)), IoUtil.getFileContents(_certificateKeyFile));
            final SSLContext sslContext = TlsFactory.createContext(tlsCertificate);

            httpsServer.setHttpsConfigurator(new HttpsConfigurator(sslContext) {
                @Override
                public void configure(final HttpsParameters params) {
                    params.setProtocols(new String[]{ "TLSv1.1", "TLSv1.2", "TLSv1.3" });
                    params.setNeedClientAuth(false);
                }
            });

            _applyEndpoints(httpsServer);
            httpsServer.setExecutor(executor);

            _tlsServer = httpsServer;
            _tlsServer.start();
        }

        if (! _disableHttp) {
            _server = com.sun.net.httpserver.HttpServer.create(new InetSocketAddress(_port), maxQueue);

            if (_redirectToTls) {
                _server.createContext("/", new HttpHandler(_encryptionRedirectEndpoint, false));
            }
            else {
                _applyEndpoints(_server);
            }

            _server.setExecutor(executor);
            _server.start();
        }

        return true;
    }
    catch (final Exception e) {
        e.printStackTrace();
        return false;
    }
}
 
开发者ID:SoftwareVerde,项目名称:http-servlet,代码行数:47,代码来源:HttpServer.java

示例13: init

import com.sun.net.httpserver.HttpsParameters; //导入依赖的package包/类
/**
 * Initialize HttpServer instance
 * @throws Exception
 */
public void init() throws Exception {
    InetAddress host = null;
    if (ProcessEditorServerHelper.getHost() != null) {
        host = InetAddress.getByName(ProcessEditorServerHelper.getHost());
    }

    if (host != null) {
        // Bind to specific interface
        address = new InetSocketAddress(host, port);
    } else {
        // Bind to all interfaces
        System.out.println("BINDING TO ALL INTERFACES");
        address = new InetSocketAddress(port);
    }
    //secure = true;
    if (ProcessEditorServerHelper.isSecure()) {
        KeyStore ks = KeyStore.getInstance("JKS");
        char[] pwd = "inubit".toCharArray();
        ks.load(ProcessEditorServer.class.getResourceAsStream(KEY_STORE), pwd);

        KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
        kmf.init(ks, pwd);

        TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");
        tmf.init(ks);

        SSLContext ssl = SSLContext.getInstance("TLS");
        ssl.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
        this.server = HttpsServer.create(address, 255);

        ((HttpsServer) this.server).setHttpsConfigurator(new HttpsConfigurator(ssl) {

            public void configure(HttpsParameters params) {
                // get the remote address if needed
                InetSocketAddress remote = params.getClientAddress();

                SSLContext c = getSSLContext();

                // get the default parameters
                SSLParameters sslparams = c.getDefaultSSLParameters();

                params.setSSLParameters(sslparams);
                // statement above could throw IAE if any params invalid.
                // eg. if app has a UI and parameters supplied by a user.

            }
        });
    } else {
        this.server = HttpServer.create(address, 255);
    }

    System.out.println("[Server] Setting up server at " + address.getAddress().getHostAddress() + ":" + address.getPort());
    logger.info("[Server] Setting up server at " + address.getAddress().getHostAddress() + ":" + address.getPort());

    for (AbstractHandler h : handlers) {
        server.createContext(h.getContextUri(), h);
    }

    BlockingQueue queue = new ProcessEditorBlockingQueue(1000);
    ThreadPoolExecutor exec = new ProcessEditorThreadPoolExecutor(10, 20, 5000, TimeUnit.MILLISECONDS, queue);

    TemporaryKeyManager.initialize();

    server.setExecutor(exec); // creates executor

    this.setup = true;
}
 
开发者ID:frapu78,项目名称:processeditor,代码行数:72,代码来源:ProcessEditorServer.java

示例14: before

import com.sun.net.httpserver.HttpsParameters; //导入依赖的package包/类
public void before(final Description description) throws Exception {
    this.service = Executors.newFixedThreadPool(
            threadCount, 
            new ThreadFactoryBuilder().setDaemon(true).setNameFormat("TestHttpServer-%d").build());
    
    InetSocketAddress inetSocketAddress = new InetSocketAddress("localhost", 0);
    if (hasSsl) {
        byte[] sampleTruststore1 = Base64.decode(TEST_TS1);
        byte[] sampleKeystore1 = Base64.decode(TEST_KS1);

        keystore = File.createTempFile("SecureAcceptAllGetTest", ".keystore");
        truststore = File.createTempFile("SecureAcceptAllGetTest", ".truststore");

        FileOutputStream keystoreFileOut = new FileOutputStream(keystore);
        try {
            keystoreFileOut.write(sampleKeystore1);
        } finally {
            keystoreFileOut.close();
        }

        FileOutputStream truststoreFileOut = new FileOutputStream(truststore);
        try {
            truststoreFileOut.write(sampleTruststore1);
        } finally {
            truststoreFileOut.close();
        }


        KeyStore ks = KeyStore.getInstance("JKS");
        ks.load(new FileInputStream(keystore), PASSWORD.toCharArray());
        KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
        kmf.init(ks, PASSWORD.toCharArray());

        KeyStore ts = KeyStore.getInstance("JKS");
        ts.load(new FileInputStream(truststore), PASSWORD.toCharArray());
        TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
        tmf.init(ts);

        SSLContext sc = SSLContext.getInstance("TLS");
        sc.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
        
        HttpsServer secureServer = HttpsServer.create(inetSocketAddress, 0);
        secureServer.setHttpsConfigurator(new HttpsConfigurator(sc) {
            public void configure (HttpsParameters params) {
                SSLContext c = getSSLContext();
                SSLParameters sslparams = c.getDefaultSSLParameters();
                params.setSSLParameters(sslparams);
            }
        });
        server = secureServer;
    }
    else {
        server = HttpServer.create(inetSocketAddress, 0);
    }
    
    server.setExecutor(service);
    
    for (Entry<String, HttpHandler> handler : handlers.entrySet()) {
        server.createContext(handler.getKey(), handler.getValue());
    }
    
    server.start();
    localHttpServerPort = server.getAddress().getPort();
    
    System.out.println(description.getClassName() + " TestServer is started: " + getServerUrl());
}
 
开发者ID:Netflix,项目名称:ribbon,代码行数:67,代码来源:MockHttpServer.java


注:本文中的com.sun.net.httpserver.HttpsParameters类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。