本文整理了Java中javax.net.ssl.HttpsURLConnection.getDefaultSSLSocketFactory()
方法的一些代码示例,展示了HttpsURLConnection.getDefaultSSLSocketFactory()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpsURLConnection.getDefaultSSLSocketFactory()
方法的具体详情如下:
包路径:javax.net.ssl.HttpsURLConnection
类名称:HttpsURLConnection
方法名:getDefaultSSLSocketFactory
[英]Returns the default SSL socket factory for new instances.
[中]返回新实例的默认SSL套接字工厂。
代码示例来源:origin: robovm/robovm
/**
* Creates the default SSL socket factory.
* This constructor is used exclusively to instantiate the factory for
* {@link #getSocketFactory getSocketFactory}.
*/
private SSLSocketFactory() {
super();
this.sslcontext = null;
this.socketfactory = HttpsURLConnection.getDefaultSSLSocketFactory();
this.nameResolver = null;
}
代码示例来源:origin: stackoverflow.com
public class CustomSSLSocketFactory extends org.apache.http.conn.ssl.SSLSocketFactory
{
private SSLSocketFactory FACTORY = HttpsURLConnection.getDefaultSSLSocketFactory ();
public CustomSSLSocketFactory ()
{
super(null);
try
{
SSLContext context = SSLContext.getInstance ("TLS");
TrustManager[] tm = new TrustManager[] { new FullX509TrustManager () };
context.init (null, tm, new SecureRandom ());
FACTORY = context.getSocketFactory ();
}
catch (Exception e)
{
e.printStackTrace();
}
}
public Socket createSocket() throws IOException
{
return FACTORY.createSocket();
}
// TODO: add other methods like createSocket() and getDefaultCipherSuites().
// Hint: they all just make a call to member FACTORY
}
代码示例来源:origin: neo4j/neo4j
@Before
public void setUp()
{
originalSslSocketFactory = HttpsURLConnection.getDefaultSSLSocketFactory();
}
代码示例来源:origin: jersey/jersey
/**
* Secure connection if necessary.
* <p/>
* Provided implementation sets {@link HostnameVerifier} and {@link SSLSocketFactory} to give connection, if that
* is an instance of {@link HttpsURLConnection}.
*
* @param client client associated with this client runtime.
* @param uc http connection to be secured.
*/
protected void secureConnection(final JerseyClient client, final HttpURLConnection uc) {
if (uc instanceof HttpsURLConnection) {
HttpsURLConnection suc = (HttpsURLConnection) uc;
final HostnameVerifier verifier = client.getHostnameVerifier();
if (verifier != null) {
suc.setHostnameVerifier(verifier);
}
if (HttpsURLConnection.getDefaultSSLSocketFactory() == suc.getSSLSocketFactory()) {
// indicates that the custom socket factory was not set
suc.setSSLSocketFactory(sslSocketFactory.get());
}
}
}
代码示例来源:origin: jersey/jersey
/**
* Secure connection if necessary.
* <p/>
* Provided implementation sets {@link HostnameVerifier} and {@link SSLSocketFactory} to give connection, if that
* is an instance of {@link HttpsURLConnection}.
*
* @param client client associated with this client runtime.
* @param uc http connection to be secured.
*/
protected void secureConnection(final JerseyClient client, final HttpURLConnection uc) {
if (uc instanceof HttpsURLConnection) {
HttpsURLConnection suc = (HttpsURLConnection) uc;
final HostnameVerifier verifier = client.getHostnameVerifier();
if (verifier != null) {
suc.setHostnameVerifier(verifier);
}
if (HttpsURLConnection.getDefaultSSLSocketFactory() == suc.getSSLSocketFactory()) {
// indicates that the custom socket factory was not set
suc.setSSLSocketFactory(sslSocketFactory.get());
}
}
}
代码示例来源:origin: org.glassfish.jersey.core/jersey-client
/**
* Secure connection if necessary.
* <p/>
* Provided implementation sets {@link HostnameVerifier} and {@link SSLSocketFactory} to give connection, if that
* is an instance of {@link HttpsURLConnection}.
*
* @param client client associated with this client runtime.
* @param uc http connection to be secured.
*/
protected void secureConnection(final JerseyClient client, final HttpURLConnection uc) {
if (uc instanceof HttpsURLConnection) {
HttpsURLConnection suc = (HttpsURLConnection) uc;
final HostnameVerifier verifier = client.getHostnameVerifier();
if (verifier != null) {
suc.setHostnameVerifier(verifier);
}
if (HttpsURLConnection.getDefaultSSLSocketFactory() == suc.getSSLSocketFactory()) {
// indicates that the custom socket factory was not set
suc.setSSLSocketFactory(sslSocketFactory.get());
}
}
}
代码示例来源:origin: OryxProject/oryx
@Test
public void testHTTPS() throws Exception {
Config config = buildHTTPSConfig();
startServer(config);
// Turn off actual checking of the dummy SSL cert
SSLContext sslContext = SSLContext.getInstance("SSL");
sslContext.init(null, new TrustManager[] { ACCEPT_ALL_TM }, null);
SSLSocketFactory originalFactory = HttpsURLConnection.getDefaultSSLSocketFactory();
HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory());
try {
String response = Resources.toString(
new URL("https://localhost:" + getHTTPSPort() + "/helloWorld"),
StandardCharsets.UTF_8);
assertEquals("Hello, World", response);
} finally {
// Restore original SSL factory
HttpsURLConnection.setDefaultSSLSocketFactory(originalFactory);
Files.delete(Paths.get(config.getString("oryx.serving.api.keystore-file")));
}
}
代码示例来源:origin: stackoverflow.com
this.delegate = HttpsURLConnection.getDefaultSSLSocketFactory();
代码示例来源:origin: stackoverflow.com
this.delegate = HttpsURLConnection.getDefaultSSLSocketFactory();
代码示例来源:origin: stackoverflow.com
this.delegate = HttpsURLConnection.getDefaultSSLSocketFactory();
代码示例来源:origin: org.apache.cxf/cxf-rt-transports-http
socketFactory = HttpsURLConnection.getDefaultSSLSocketFactory();
代码示例来源:origin: MobiVM/robovm
/**
* Creates the default SSL socket factory.
* This constructor is used exclusively to instantiate the factory for
* {@link #getSocketFactory getSocketFactory}.
*/
private SSLSocketFactory() {
super();
this.sslcontext = null;
this.socketfactory = HttpsURLConnection.getDefaultSSLSocketFactory();
this.nameResolver = null;
}
代码示例来源:origin: dremio/dremio-oss
/**
* Trigger method to create the default HTTPS SSL socket factory. Currently we have an issue due to
* {@link HttpsURLConnection#defaultSSLSocketFactory} being static but not volatile which means we could end up
* initializing the static variable multiple times in multi-threaded scenario and it could cause issues such as
* <a href="DX-11543">https://dremio.atlassian.net/browse/DX-11543</a>
*/
private void setupDefaultHttpsSSLSocketFactory() {
HttpsURLConnection.getDefaultSSLSocketFactory();
}
代码示例来源:origin: helun/Ektorp
/**
* Creates the default SSL socket factory.
* This constructor is used exclusively to instantiate the factory for
* {@link #getSocketFactory getSocketFactory}.
*/
private AndroidSSLSocketFactory() {
super();
this.sslcontext = null;
this.socketfactory = HttpsURLConnection.getDefaultSSLSocketFactory();
this.nameResolver = null;
}
代码示例来源:origin: com.mobidevelop.robovm/robovm-rt
/**
* Creates the default SSL socket factory.
* This constructor is used exclusively to instantiate the factory for
* {@link #getSocketFactory getSocketFactory}.
*/
private SSLSocketFactory() {
super();
this.sslcontext = null;
this.socketfactory = HttpsURLConnection.getDefaultSSLSocketFactory();
this.nameResolver = null;
}
代码示例来源:origin: com.gluonhq/robovm-rt
/**
* Creates the default SSL socket factory.
* This constructor is used exclusively to instantiate the factory for
* {@link #getSocketFactory getSocketFactory}.
*/
private SSLSocketFactory() {
super();
this.sslcontext = null;
this.socketfactory = HttpsURLConnection.getDefaultSSLSocketFactory();
this.nameResolver = null;
}
代码示例来源:origin: org.ektorp/org.ektorp.android
/**
* Creates the default SSL socket factory.
* This constructor is used exclusively to instantiate the factory for
* {@link #getSocketFactory getSocketFactory}.
*/
private AndroidSSLSocketFactory() {
super();
this.sslcontext = null;
this.socketfactory = HttpsURLConnection.getDefaultSSLSocketFactory();
this.nameResolver = null;
}
代码示例来源:origin: stackoverflow.com
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;
import java.security.cert.Certificate;
...
String hostname = "your.host";
SSLSocketFactory factory = HttpsURLConnection.getDefaultSSLSocketFactory();
SSLSocket socket = (SSLSocket) factory.createSocket(hostname, 443);
socket.startHandshake();
Certificate[] certs = socket.getSession().getPeerCertificates();
Certificate cert = certs[0];
PublicKey key = cert.getPublicKey();
代码示例来源:origin: org.geoserver.security/sec-cas
protected void checkSSLServer() throws Exception {
SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, new TrustManager[] { trustManager} , null);
SSLSocketFactory fac = HttpsURLConnection.getDefaultSSLSocketFactory();
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
URL testSSLURL = new URL(getProxyCallbackURLPrefix().getProtocol(),
getProxyCallbackURLPrefix().getHost(),getProxyCallbackURLPrefix().getPort(),"/test");
HttpURLConnection con = (HttpURLConnection) testSSLURL.openConnection();
con.getInputStream().close();
HttpsURLConnection.setDefaultSSLSocketFactory(fac);
}
代码示例来源:origin: apache/attic-polygene-java
@BeforeClass
public static void beforeSecureClass()
throws IOException, GeneralSecurityException
{
defaultHostnameVerifier = HttpsURLConnection.getDefaultHostnameVerifier();
defaultSSLSocketFactory = HttpsURLConnection.getDefaultSSLSocketFactory();
HttpsURLConnection.setDefaultHostnameVerifier( ( string, ssls ) -> true );
HttpsURLConnection.setDefaultSSLSocketFactory( buildTrustSSLContext().getSocketFactory() );
}
内容来源于网络,如有侵权,请联系作者删除!