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


Java SSLContext.getDefault方法代码示例

本文整理汇总了Java中javax.net.ssl.SSLContext.getDefault方法的典型用法代码示例。如果您正苦于以下问题:Java SSLContext.getDefault方法的具体用法?Java SSLContext.getDefault怎么用?Java SSLContext.getDefault使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.net.ssl.SSLContext的用法示例。


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

示例1: emmit

import javax.net.ssl.SSLContext; //导入方法依赖的package包/类
private void emmit(FlowableEmitter<Message> emitter, String roomId) throws Exception {
    SSLContext sslCtx = SSLContext.getDefault();
    SSLEngine sslEngine = sslCtx.createSSLEngine("stream.gitter.im", 443);
    sslEngine.setUseClientMode(true);

    HttpClient
            .newClient("stream.gitter.im", 443)
            .secure(sslEngine)
            .createGet("/v1/rooms/" + roomId + "/chatMessages")
            .addHeader("Authorization", "Bearer 3cd4820adf59b6a7116f99d92f68a1b786895ce7")
            .flatMap(HttpClientResponse::getContent)
            .filter(bb -> bb.capacity() > 2)
            .map(MessageEncoder::mapToMessage)
            .doOnNext(m -> System.out.println("Log Emit: " + m))
            .subscribe(emitter::onNext, emitter::onError, emitter::onComplete);
}
 
开发者ID:OlegDokuka,项目名称:reactive-playing,代码行数:17,代码来源:RxGitterClient.java

示例2: VertxClientEngine

import javax.net.ssl.SSLContext; //导入方法依赖的package包/类
public VertxClientEngine(final HttpClient httpClient) {

        try {
            this.httpClient = httpClient;
            sslContext = SSLContext.getDefault();
            hostnameVerifier = HttpsURLConnection.getDefaultHostnameVerifier();
        } catch (final NoSuchAlgorithmException e) {
            throw new ExceptionInInitializerError(e);
        }
    }
 
开发者ID:trajano,项目名称:app-ms,代码行数:11,代码来源:VertxClientEngine.java

示例3: test

import javax.net.ssl.SSLContext; //导入方法依赖的package包/类
/**
 * The parameter passed is the user enforced protocol. Does not catch
 * NoSuchAlgorithmException, WrongProperty test will use it.
 */
public void test(String expectedContextProto,
        String[] expectedDefaultProtos) throws NoSuchAlgorithmException {

    SSLContext context = null;
    try {
        if (expectedContextProto != null) {
            context = SSLContext.getInstance(expectedContextProto);
            context.init(null, null, null);
        } else {
            context = SSLContext.getDefault();
        }
        printContextDetails(context);
    } catch (KeyManagementException ex) {
        error(null, ex);
    }

    validateContext(expectedContextProto, expectedDefaultProtos, context);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:23,代码来源:TLSClientPropertyTest.java

示例4: preparedSocket_NullProtocols

import javax.net.ssl.SSLContext; //导入方法依赖的package包/类
/**
 * Test when the edge case when the both supported and enabled protocols are null.
 */
@Test
public void preparedSocket_NullProtocols() throws NoSuchAlgorithmException {
    SdkTlsSocketFactory f = new SdkTlsSocketFactory(SSLContext.getDefault(), null);
    f.prepareSocket(new TestSSLSocket() {
        @Override
        public String[] getSupportedProtocols() {
            return null;
        }

        @Override
        public String[] getEnabledProtocols() {
            return null;
        }

        @Override
        public void setEnabledProtocols(String[] protocols) {
            fail();
        }
    });
}
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:24,代码来源:SdkTlsSocketFactoryTest.java

示例5: typical

import javax.net.ssl.SSLContext; //导入方法依赖的package包/类
@Test
public void typical() throws NoSuchAlgorithmException {
    SdkTlsSocketFactory f = new SdkTlsSocketFactory(SSLContext.getDefault(), null);
    f.prepareSocket(new TestSSLSocket() {
        @Override
        public String[] getSupportedProtocols() {
            return shuffle(new String[]{"SSLv2Hello", "SSLv3", "TLSv1", "TLSv1.1", "TLSv1.2"});
        }

        @Override
        public String[] getEnabledProtocols() {
            return shuffle(new String[]{"SSLv3", "TLSv1"});
        }

        @Override
        public void setEnabledProtocols(String[] protocols) {
            assertTrue(Arrays.equals(protocols, new String[]{"TLSv1.2", "TLSv1.1", "TLSv1", "SSLv3"}));
        }
    });
}
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:21,代码来源:SdkTlsSocketFactoryTest.java

示例6: usingNetty

import javax.net.ssl.SSLContext; //导入方法依赖的package包/类
static ClientHttpRequestFactory usingNetty(ClientOptions options)
		throws IOException, GeneralSecurityException {

	SslContext sslContext = new JdkSslContext(SSLContext.getDefault(), true, ClientAuth.REQUIRE);

	final Netty4ClientHttpRequestFactory requestFactory = new Netty4ClientHttpRequestFactory();
	requestFactory.setSslContext(sslContext);

	if (options.getConnectionTimeout() != null) {
		requestFactory.setConnectTimeout(options.getConnectionTimeout());
	}
	if (options.getReadTimeout() != null) {
		requestFactory.setReadTimeout(options.getReadTimeout());
	}

	return requestFactory;
}
 
开发者ID:spring-projects,项目名称:spring-credhub,代码行数:18,代码来源:ClientHttpRequestFactoryFactory.java

示例7: typical

import javax.net.ssl.SSLContext; //导入方法依赖的package包/类
@Test
public void typical() throws NoSuchAlgorithmException {
    SdkTLSSocketFactory f = new SdkTLSSocketFactory(SSLContext.getDefault(), null);
    f.prepareSocket(new TestSSLSocket() {
        @Override
        public String[] getSupportedProtocols() {
            return shuffle(new String[]{"SSLv2Hello", "SSLv3", "TLSv1", "TLSv1.1", "TLSv1.2"});
        }
        @Override
        public String[] getEnabledProtocols() {
            return shuffle(new String[]{"SSLv3", "TLSv1"});
        }
        @Override
        public void setEnabledProtocols(String[] protocols) {
            assertTrue(Arrays.equals(protocols, new String[] {"TLSv1.2", "TLSv1.1", "TLSv1", "SSLv3" }));
        }
    });
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:19,代码来源:SdkTLSSocketFactoryTest.java

示例8: getSupportedSslProtocols

import javax.net.ssl.SSLContext; //导入方法依赖的package包/类
/**
 * @return the list of supported ssl protocols by the default
 *         {@link SSLContext}
 */
private String[] getSupportedSslProtocols() {
    try {
        SSLContext sslContext = SSLContext.getDefault();
        return sslContext.getSupportedSSLParameters().getProtocols();
    } catch (NoSuchAlgorithmException e) {
        throw new RuntimeException(sm.getString("jndiRealm.exception"), e);
    }
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:13,代码来源:JNDIRealm.java

示例9: testNewInstanceLoader

import javax.net.ssl.SSLContext; //导入方法依赖的package包/类
@Test
public void testNewInstanceLoader() throws Exception {
    final SslContextReloader reloader = new SslContextReloader(() -> {
        return new JdkSslContext(SSLContext.getDefault(), true, ClientAuth.REQUIRE);
    });

    assertTrue(reloader.load());
    assertEquals(ReloadState.RELOADED, reloader.getReloadState());
    assertNull(reloader.getDataVersion());
}
 
开发者ID:indeedeng-alpha,项目名称:indeed-grpc-java,代码行数:11,代码来源:SslContextReloaderTest.java

示例10: testStaticInstanceLoader

import javax.net.ssl.SSLContext; //导入方法依赖的package包/类
@Test
public void testStaticInstanceLoader() throws Exception {
    final JdkSslContext context = new JdkSslContext(SSLContext.getDefault(), true, ClientAuth.REQUIRE);
    final SslContextReloader reloader = new SslContextReloader(() -> context);

    // don't invoke load here because the constructor forces load the first time
    assertEquals(ReloadState.RELOADED, reloader.getReloadState());
    assertNull(reloader.getDataVersion());

    assertFalse(reloader.load());
    assertEquals(ReloadState.NO_CHANGE, reloader.getReloadState());
    assertNull(reloader.getDataVersion());
}
 
开发者ID:indeedeng-alpha,项目名称:indeed-grpc-java,代码行数:14,代码来源:SslContextReloaderTest.java

示例11: main

import javax.net.ssl.SSLContext; //导入方法依赖的package包/类
public static void main (String[] args) throws Exception {
    SSLContext context = SSLContext.getDefault();

    // set the property before initialization SSLEngine.
    System.setProperty("jsse.SSLEngine.acceptLargeFragments", "true");

    SSLEngine cliEngine = context.createSSLEngine();
    cliEngine.setUseClientMode(true);

    SSLEngine srvEngine = context.createSSLEngine();
    srvEngine.setUseClientMode(false);

    SSLSession cliSession = cliEngine.getSession();
    SSLSession srvSession = srvEngine.getSession();

    // check packet buffer sizes.
    if (cliSession.getPacketBufferSize() < 33049 ||
        srvSession.getPacketBufferSize() < 33049) {
            throw new Exception("Don't accept large SSL/TLS fragments");
    }

    // check application data buffer sizes.
    if (cliSession.getApplicationBufferSize() < 32768 ||
        srvSession.getApplicationBufferSize() < 32768) {
            throw new Exception(
                    "Don't accept large SSL/TLS application data ");
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:29,代码来源:AcceptLargeFragments.java

示例12: createHttpsServer

import javax.net.ssl.SSLContext; //导入方法依赖的package包/类
static Http2TestServer createHttpsServer(ExecutorService exec) throws Exception {
    Http2TestServer server = new Http2TestServer(true, 0, exec, SSLContext.getDefault());
    server.addHandler(new Http2Handler() {
        @Override
        public void handle(Http2TestExchange he) throws IOException {
            he.getResponseHeaders().addHeader("encoding", "UTF-8");
            he.sendResponseHeaders(200, RESPONSE.length());
            he.getResponseBody().write(RESPONSE.getBytes(StandardCharsets.UTF_8));
            he.close();
        }
    }, PATH);

    return server;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:ProxyTest2.java

示例13: getSupportedSslProtocols

import javax.net.ssl.SSLContext; //导入方法依赖的package包/类
/**
 * @return the list of supported ssl protocols by the default
 *         {@link SSLContext}
 */
private String[] getSupportedSslProtocols() {
	try {
		SSLContext sslContext = SSLContext.getDefault();
		return sslContext.getSupportedSSLParameters().getProtocols();
	} catch (NoSuchAlgorithmException e) {
		throw new RuntimeException(sm.getString("jndiRealm.exception"), e);
	}
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:13,代码来源:JNDIRealm.java

示例14: init

import javax.net.ssl.SSLContext; //导入方法依赖的package包/类
static SSLEchoServer init(String cipherSuiteFilter,
        String sniPattern) throws NoSuchAlgorithmException, IOException {
    SSLContext context = SSLContext.getDefault();
    SSLServerSocketFactory ssf =
            (SSLServerSocketFactory) context.getServerSocketFactory();
    SSLServerSocket ssocket =
            (SSLServerSocket) ssf.createServerSocket(0);

    // specify enabled cipher suites
    if (cipherSuiteFilter != null) {
        String[] ciphersuites = UnboundSSLUtils.filterStringArray(
                ssf.getSupportedCipherSuites(), cipherSuiteFilter);
        System.out.println("Server: enabled cipher suites: "
                + Arrays.toString(ciphersuites));
        ssocket.setEnabledCipherSuites(ciphersuites);
    }

    // specify SNI matcher pattern
    if (sniPattern != null) {
        System.out.println("Server: set SNI matcher: " + sniPattern);
        SNIMatcher matcher = SNIHostName.createSNIMatcher(sniPattern);
        List<SNIMatcher> matchers = new ArrayList<>();
        matchers.add(matcher);
        SSLParameters params = ssocket.getSSLParameters();
        params.setSNIMatchers(matchers);
        ssocket.setSSLParameters(params);
    }

    return new SSLEchoServer(ssocket);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:31,代码来源:UnboundSSLUtils.java

示例15: buildAsyncClient

import javax.net.ssl.SSLContext; //导入方法依赖的package包/类
protected ExecCallbackAsyncREST<HttpResponse> buildAsyncClient(RESTPool pool) throws IOException {
    SSLContext sslContext;
    try {
        sslContext = SSLContext.getDefault();
    } catch (NoSuchAlgorithmException e) {
        throw new IOException(e);
    }

    Registry<SchemeIOSessionStrategy> socketRegistry = RegistryBuilder.<SchemeIOSessionStrategy>create()
            .register("http", NoopIOSessionStrategy.INSTANCE)
            .register("https", new SSLIOSessionStrategy(sslContext, NoopHostnameVerifier.INSTANCE))
            .build();

    IOReactorConfig socketConfig = IOReactorConfig.custom()
            .setIoThreadCount(pool.getReactorThreadCount())
            .setSoTimeout(new Long(pool.getSocketTimeout()).intValue())
            .setTcpNoDelay(true)
            .setSoKeepAlive(true)
            .setSelectInterval(REACTOR_SELECT_INTERVAL)
            .build();

    ConnectionConfig connectionConfig = ConnectionConfig.custom()
            .setCharset(StandardCharsets.UTF_8)
            .setMalformedInputAction(CodingErrorAction.IGNORE)
            .setUnmappableInputAction(CodingErrorAction.IGNORE)
            .build();

    RequestConfig requestConfig = RequestConfig.custom()
            .setConnectionRequestTimeout(new Long(pool.getMaxPoolWait()).intValue())
            .setConnectTimeout(new Long(pool.getConnectionTimeout()).intValue())
            .setExpectContinueEnabled(pool.expectContinue())
            .setRedirectsEnabled(false)
            .setStaleConnectionCheckEnabled(pool.getValidationOnInactivity() >= 0)
            .build();

    NHttpConnectionFactory<ManagedNHttpClientConnection> connFactory = new ManagedNHttpClientConnectionFactory(
            new org.apache.http.impl.nio.codecs.DefaultHttpRequestWriterFactory(),
            new org.apache.http.impl.nio.codecs.DefaultHttpResponseParserFactory(),
            HeapByteBufferAllocator.INSTANCE
    );

    //TODO set validateAfterInactivity when supported
    PoolingNHttpClientConnectionManager ccm = new PoolingNHttpClientConnectionManager(
            new DefaultConnectingIOReactor(socketConfig),
            connFactory,
            socketRegistry,
            new SystemDefaultDnsResolver()
    );

    ccm.setMaxTotal(pool.getMaxTotal());
    ccm.setDefaultMaxPerRoute(pool.getMaxPerRoute());
    ccm.setDefaultConnectionConfig(connectionConfig);

    HttpAsyncClientBuilder builder = HttpAsyncClients.custom()
            .setConnectionManager(ccm)
            .setDefaultRequestConfig(requestConfig)
            .setKeepAliveStrategy(DefaultConnectionKeepAliveStrategy.INSTANCE)
            .disableCookieManagement();

    IdleAsyncConnectionEvictor evictor = new IdleAsyncConnectionEvictor(ccm, pool.getEvictorSleep(), TimeUnit.MILLISECONDS, pool.getMaxIdleTime(), TimeUnit.MILLISECONDS);

    addProxy(pool, builder);

    handleRedirects(pool, builder);

    CloseableHttpAsyncClient servClient = builder.build();

    servClient.start();

    HTTPCClientMonitor monitor = pool.hasConnectionMetrics() ? new HTTPCAsyncClientMonitor(pool.getName(), ccm) : null;

    return new HTTPCAsyncClient(servClient, evictor, monitor);
}
 
开发者ID:mercadolibre,项目名称:java-restclient,代码行数:74,代码来源:HTTPCBuilder.java


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