當前位置: 首頁>>代碼示例>>Java>>正文


Java SslContextFactory.setSslContext方法代碼示例

本文整理匯總了Java中org.eclipse.jetty.util.ssl.SslContextFactory.setSslContext方法的典型用法代碼示例。如果您正苦於以下問題:Java SslContextFactory.setSslContext方法的具體用法?Java SslContextFactory.setSslContext怎麽用?Java SslContextFactory.setSslContext使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.eclipse.jetty.util.ssl.SslContextFactory的用法示例。


在下文中一共展示了SslContextFactory.setSslContext方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testRetry

import org.eclipse.jetty.util.ssl.SslContextFactory; //導入方法依賴的package包/類
@Test
public void testRetry() throws Exception {
    SalesforceComponent sf = context().getComponent("salesforce", SalesforceComponent.class);
    String accessToken = sf.getSession().getAccessToken();

    SslContextFactory sslContextFactory = new SslContextFactory();
    sslContextFactory.setSslContext(new SSLContextParameters().createSSLContext(context));
    HttpClient httpClient = new HttpClient(sslContextFactory);
    httpClient.setConnectTimeout(60000);
    httpClient.start();

    String uri = sf.getLoginConfig().getLoginUrl() + "/services/oauth2/revoke?token=" + accessToken;
    Request logoutGet = httpClient.newRequest(uri)
        .method(HttpMethod.GET)
        .timeout(1, TimeUnit.MINUTES);

    ContentResponse response = logoutGet.send();
    assertEquals(HttpStatus.OK_200, response.getStatus());

    JobInfo jobInfo = new JobInfo();
    jobInfo.setOperation(OperationEnum.INSERT);
    jobInfo.setContentType(ContentType.CSV);
    jobInfo.setObject(Merchandise__c.class.getSimpleName());
    createJob(jobInfo);
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:26,代碼來源:BulkApiIntegrationTest.java

示例2: getSslContextFactory

import org.eclipse.jetty.util.ssl.SslContextFactory; //導入方法依賴的package包/類
private static SslContextFactory getSslContextFactory(String password, InputStream key) {
    SslContextFactory sslContextFactory1 = new SslContextFactory(true);
    try {
        //init KeyStore
        final char[] pwdChars = password.toCharArray();
        final KeyStore keyStore = KeyStore.getInstance("PKCS12");
        keyStore.load(key, pwdChars);
        final KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance("SunX509");
        keyManagerFactory.init(keyStore, pwdChars);
        //init TrustManager
        final TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance("SunX509");
        trustManagerFactory.init((KeyStore) null);
        TrustManager[] trustManagers = trustManagerFactory.getTrustManagers();
        //init SSLContext
        final SSLContext sslContext = SSLContext.getInstance("TLSv1.2");
        sslContext.init(keyManagerFactory.getKeyManagers(), trustManagers, null);

        sslContextFactory1.setSslContext(sslContext);
        sslContextFactory1.start();
    } catch (Exception e) {
        log.error("create sslContextFactory error.", e);
    }
    return sslContextFactory1;
}
 
開發者ID:linmingchang,項目名稱:java-apns2,代碼行數:25,代碼來源:ApnsHttp2ClientPool.java

示例3: testRetry

import org.eclipse.jetty.util.ssl.SslContextFactory; //導入方法依賴的package包/類
@Test
public void testRetry() throws Exception {
    SalesforceComponent sf = context().getComponent("salesforce", SalesforceComponent.class);
    String accessToken = sf.getSession().getAccessToken();

    SslContextFactory sslContextFactory = new SslContextFactory();
    sslContextFactory.setSslContext(new SSLContextParameters().createSSLContext(context));
    HttpClient httpClient = new HttpClient(sslContextFactory);
    httpClient.setConnectTimeout(60000);
    httpClient.start();

    String uri = sf.getLoginConfig().getLoginUrl() + "/services/oauth2/revoke?token=" + accessToken;
    Request logoutGet = httpClient.newRequest(uri)
        .method(HttpMethod.GET)
        .timeout(1, TimeUnit.MINUTES);

    ContentResponse response = logoutGet.send();
    assertEquals(HttpStatus.OK_200, response.getStatus());

    doTestGetGlobalObjects("");
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:22,代碼來源:RestApiIntegrationTest.java

示例4: submit

import org.eclipse.jetty.util.ssl.SslContextFactory; //導入方法依賴的package包/類
@Override
public ResponseEntity<String> submit(JCurlRequestOptions requestOptions) throws Exception {

    final SslContextFactory sslContextFactory = new SslContextFactory();
    sslContextFactory.setSslContext(SSLContext.getDefault());
    HttpClient httpClient = new HttpClient(sslContextFactory);
    // Configure HttpClient here
    httpClient.start();

    ResponseEntity<String> responseEntity = null;

    for (int i=0;i< requestOptions.getCount();i++) {
        final Request request = httpClient
            .newRequest(requestOptions.getUrl());

        for(Map.Entry<String,String> e : requestOptions.getHeaderMap().entrySet()) {
            request.header(e.getKey(), e.getValue());
        }

        System.out.println("\nSending 'GET' request to URL : " + requestOptions.getUrl());
        final ContentResponse response = request.send();

        int responseCode = response.getStatus();
        System.out.println("Response Code : " + responseCode);

        String responseContent = IOUtils.toString(response.getContent(), "utf-8");

        //print result
        System.out.println(responseContent);

        responseEntity = new ResponseEntity<String>(responseContent, HttpStatus.valueOf(responseCode));
    }

    httpClient.stop();
    return responseEntity;
}
 
開發者ID:eeichinger,項目名稱:jcurl,代碼行數:37,代碼來源:JettyEngine.java

示例5: createSslContextFactory

import org.eclipse.jetty.util.ssl.SslContextFactory; //導入方法依賴的package包/類
private SslContextFactory createSslContextFactory(SSLContextParameters ssl) throws GeneralSecurityException, IOException {
    SslContextFactory answer = new SslContextFactory();
    if (ssl != null) {
        answer.setSslContext(ssl.createSSLContext());
    }
    return answer;
}
 
開發者ID:nkasvosve,項目名稱:beyondj,代碼行數:8,代碼來源:JettyHttpComponent.java

示例6: ServerManager

import org.eclipse.jetty.util.ssl.SslContextFactory; //導入方法依賴的package包/類
public ServerManager(ServiceConfig config) {
    this.webServiceExecutor = Executors.newFixedThreadPool(32, new DefaultThreadFactory("pulsar-external-web"));
    this.server = new Server(new ExecutorThreadPool(webServiceExecutor));
    this.externalServicePort = config.getWebServicePort();

    List<ServerConnector> connectors = Lists.newArrayList();

    ServerConnector connector = new ServerConnector(server, 1, 1);
    connector.setPort(externalServicePort);
    connectors.add(connector);

    if (config.isTlsEnabled()) {
        SslContextFactory sslCtxFactory = new SslContextFactory();
        try {
            SSLContext sslCtx = SecurityUtility.createSslContext(config.isTlsAllowInsecureConnection(), config.getTlsTrustCertsFilePath(), config.getTlsCertificateFilePath(),
                    config.getTlsKeyFilePath());
            sslCtxFactory.setSslContext(sslCtx);
        } catch (GeneralSecurityException e) {
            throw new RestException(e);
        }

        sslCtxFactory.setWantClientAuth(true);
        ServerConnector tlsConnector = new ServerConnector(server, 1, 1, sslCtxFactory);
        tlsConnector.setPort(config.getWebServicePortTls());
        connectors.add(tlsConnector);
    }

    // Limit number of concurrent HTTP connections to avoid getting out of file descriptors
    connectors.stream().forEach(c -> c.setAcceptQueueSize(1024 / connectors.size()));
    server.setConnectors(connectors.toArray(new ServerConnector[connectors.size()]));
}
 
開發者ID:apache,項目名稱:incubator-pulsar,代碼行數:32,代碼來源:ServerManager.java

示例7: ProxyServer

import org.eclipse.jetty.util.ssl.SslContextFactory; //導入方法依賴的package包/類
public ProxyServer(WebSocketProxyConfiguration config)
        throws PulsarClientException, MalformedURLException, PulsarServerException {
    this.conf = config;
    executorService = Executors.newFixedThreadPool(WebSocketProxyConfiguration.PROXY_SERVER_EXECUTOR_THREADS,
            new DefaultThreadFactory("pulsar-websocket-web"));
    this.server = new Server(new ExecutorThreadPool(executorService));
    List<ServerConnector> connectors = new ArrayList<>();

    ServerConnector connector = new ServerConnector(server);

    connector.setPort(config.getWebServicePort());
    connectors.add(connector);

    // TLS enabled connector
    if (config.isTlsEnabled()) {
        SslContextFactory sslCtxFactory = new SslContextFactory(true);
        try {
            SSLContext sslCtx = SecurityUtility.createSslContext(false, config.getTlsTrustCertsFilePath(), config.getTlsCertificateFilePath(),
                    config.getTlsKeyFilePath());
            sslCtxFactory.setSslContext(sslCtx);

        } catch (GeneralSecurityException e) {
            throw new PulsarServerException(e);
        }

        sslCtxFactory.setWantClientAuth(true);
        ServerConnector tlsConnector = new ServerConnector(server, -1, -1, sslCtxFactory);
        tlsConnector.setPort(config.getWebServicePortTls());
        connectors.add(tlsConnector);

    }

    // Limit number of concurrent HTTP connections to avoid getting out of
    // file descriptors
    connectors.stream().forEach(c -> c.setAcceptQueueSize(1024 / connectors.size()));
    server.setConnectors(connectors.toArray(new ServerConnector[connectors.size()]));
}
 
開發者ID:apache,項目名稱:incubator-pulsar,代碼行數:38,代碼來源:ProxyServer.java

示例8: WebService

import org.eclipse.jetty.util.ssl.SslContextFactory; //導入方法依賴的package包/類
public WebService(PulsarService pulsar) throws PulsarServerException {
    this.handlers = Lists.newArrayList();
    this.pulsar = pulsar;
    this.webServiceExecutor = Executors.newFixedThreadPool(WebService.NUM_ACCEPTORS, new DefaultThreadFactory("pulsar-web"));
    this.server = new Server(new ExecutorThreadPool(webServiceExecutor));
    List<ServerConnector> connectors = new ArrayList<>();

    ServerConnector connector = new PulsarServerConnector(server, 1, 1);
    connector.setPort(pulsar.getConfiguration().getWebServicePort());
    connector.setHost(pulsar.getBindAddress());
    connectors.add(connector);

    if (pulsar.getConfiguration().isTlsEnabled()) {
        SslContextFactory sslCtxFactory = new SslContextFactory();

        try {
            sslCtxFactory.setSslContext(
                    SecurityUtility.createSslContext(
                        pulsar.getConfiguration().isTlsAllowInsecureConnection(),
                        pulsar.getConfiguration().getTlsTrustCertsFilePath(),
                        pulsar.getConfiguration().getTlsCertificateFilePath(),
                        pulsar.getConfiguration().getTlsKeyFilePath()));
        } catch (GeneralSecurityException e) {
            throw new PulsarServerException(e);
        }

        sslCtxFactory.setWantClientAuth(true);
        ServerConnector tlsConnector = new PulsarServerConnector(server, 1, 1, sslCtxFactory);
        tlsConnector.setPort(pulsar.getConfiguration().getWebServicePortTls());
        tlsConnector.setHost(pulsar.getBindAddress());
        connectors.add(tlsConnector);
    }

    // Limit number of concurrent HTTP connections to avoid getting out of file descriptors
    connectors.forEach(c -> c.setAcceptQueueSize(WebService.MAX_CONCURRENT_REQUESTS / connectors.size()));
    server.setConnectors(connectors.toArray(new ServerConnector[connectors.size()]));
}
 
開發者ID:apache,項目名稱:incubator-pulsar,代碼行數:38,代碼來源:WebService.java

示例9: WebServer

import org.eclipse.jetty.util.ssl.SslContextFactory; //導入方法依賴的package包/類
public WebServer(ProxyConfiguration config) {
    this.webServiceExecutor = Executors.newFixedThreadPool(32, new DefaultThreadFactory("pulsar-external-web"));
    this.server = new Server(new ExecutorThreadPool(webServiceExecutor));
    this.externalServicePort = config.getWebServicePort();

    List<ServerConnector> connectors = Lists.newArrayList();

    ServerConnector connector = new ServerConnector(server, 1, 1);
    connector.setPort(externalServicePort);
    connectors.add(connector);

    if (config.isTlsEnabledInProxy()) {
        SslContextFactory sslCtxFactory = new SslContextFactory();
        try {
            SSLContext sslCtx = SecurityUtility.createSslContext(false, null, config.getTlsCertificateFilePath(),
                    config.getTlsKeyFilePath());
            sslCtxFactory.setSslContext(sslCtx);
        } catch (GeneralSecurityException e) {
            throw new RuntimeException(e);
        }

        sslCtxFactory.setWantClientAuth(false);
        ServerConnector tlsConnector = new ServerConnector(server, 1, 1, sslCtxFactory);
        tlsConnector.setPort(config.getWebServicePortTls());
        connectors.add(tlsConnector);
    }

    // Limit number of concurrent HTTP connections to avoid getting out of file descriptors
    connectors.stream().forEach(c -> c.setAcceptQueueSize(1024 / connectors.size()));
    server.setConnectors(connectors.toArray(new ServerConnector[connectors.size()]));
}
 
開發者ID:apache,項目名稱:incubator-pulsar,代碼行數:32,代碼來源:WebServer.java

示例10: createSslContextFactory

import org.eclipse.jetty.util.ssl.SslContextFactory; //導入方法依賴的package包/類
private SslContextFactory createSslContextFactory(SSLContextParameters ssl) throws GeneralSecurityException, IOException {
    SslContextFactory answer = new SslContextFactory();
    if (ssl != null) {
        answer.setSslContext(ssl.createSSLContext(getCamelContext()));
    }
    return answer;
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:8,代碼來源:JettyHttpComponent.java

示例11: getConnector

import org.eclipse.jetty.util.ssl.SslContextFactory; //導入方法依賴的package包/類
@Override
protected Connector getConnector() throws Exception {

    SslContextFactory sslContextFactory = new SslContextFactory();
    sslContextFactory.setSslContext(defineSSLContextServerParameters().createSSLContext(camelContext));

    ServerConnector https = new ServerConnector(server,
            new SslConnectionFactory(sslContextFactory, null));
    return https;
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:11,代碼來源:WssProducerTest.java

示例12: testRetryFailure

import org.eclipse.jetty.util.ssl.SslContextFactory; //導入方法依賴的package包/類
@Test
public void testRetryFailure() throws Exception {
    SalesforceComponent sf = context().getComponent("salesforce", SalesforceComponent.class);
    String accessToken = sf.getSession().getAccessToken();

    SslContextFactory sslContextFactory = new SslContextFactory();
    sslContextFactory.setSslContext(new SSLContextParameters().createSSLContext());
    HttpClient httpClient = new HttpClient(sslContextFactory);
    httpClient.setConnectTimeout(60000);
    httpClient.start();

    String uri = sf.getLoginConfig().getLoginUrl() + "/services/oauth2/revoke?token=" + accessToken;
    Request logoutGet = httpClient.newRequest(uri)
        .method(HttpMethod.GET)
        .timeout(1, TimeUnit.MINUTES);

    ContentResponse response = logoutGet.send();
    assertEquals(HttpStatus.OK_200, response.getStatus());

    // set component config to bad password to cause relogin attempts to fail
    final String password = sf.getLoginConfig().getPassword();
    sf.getLoginConfig().setPassword("bad_password");

    try {
        doTestGetGlobalObjects("");
        fail("Expected CamelExecutionException!");
    } catch (CamelExecutionException e) {
        if (e.getCause() instanceof SalesforceException) {
            SalesforceException cause = (SalesforceException) e.getCause();
            assertEquals("Expected 400 on authentication retry failure", HttpStatus.BAD_REQUEST_400, cause.getStatusCode());
        } else {
            fail("Expected SalesforceException!");
        }
    } finally {
        // reset password and retries to allow other tests to pass
        sf.getLoginConfig().setPassword(password);
    }
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:39,代碼來源:RestApiIntegrationTest.java

示例13: testLogin

import org.eclipse.jetty.util.ssl.SslContextFactory; //導入方法依賴的package包/類
@Test
public void testLogin() throws Exception {

    final SslContextFactory sslContextFactory = new SslContextFactory();
    sslContextFactory.setSslContext(new SSLContextParameters().createSSLContext());
    final SalesforceHttpClient httpClient = new SalesforceHttpClient(sslContextFactory);
    httpClient.setConnectTimeout(TIMEOUT);

    final SalesforceSession session = new SalesforceSession(
        httpClient, TIMEOUT, LoginConfigHelper.getLoginConfig());
    session.addListener(this);
    httpClient.setSession(session);

    httpClient.start();
    try {
        String loginToken = session.login(session.getAccessToken());
        LOG.info("First token " + loginToken);

        assertTrue("SalesforceSessionListener onLogin NOT called", onLoginTriggered);
        onLoginTriggered = false;

        // refresh token, also causes logout
        loginToken = session.login(loginToken);
        LOG.info("Refreshed token " + loginToken);

        assertTrue("SalesforceSessionListener onLogout NOT called", onLogoutTriggered);
        assertTrue("SalesforceSessionListener onLogin NOT called", onLoginTriggered);

    } finally {
        // logout finally
        session.logout();
    }
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:34,代碼來源:SessionIntegrationTest.java


注:本文中的org.eclipse.jetty.util.ssl.SslContextFactory.setSslContext方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。