本文整理汇总了Java中org.apache.http.conn.ssl.SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER属性的典型用法代码示例。如果您正苦于以下问题:Java SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER属性的具体用法?Java SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER怎么用?Java SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.apache.http.conn.ssl.SSLConnectionSocketFactory
的用法示例。
在下文中一共展示了SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER属性的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ceateSSLClient
public static CloseableHttpClient ceateSSLClient(File keyFile, String protocol, String password){
CloseableHttpClient httpclient = null;
try{
KeyStore keyStore = KeyStore.getInstance("PKCS12");
FileInputStream instream = new FileInputStream(keyFile);
try {
keyStore.load(instream, password.toCharArray());
} finally {
instream.close();
}
// Trust own CA and all self-signed certs
SSLContext sslcontext = SSLContexts.custom().loadKeyMaterial(keyStore, password.toCharArray()).build();
// Allow TLSv1 protocol only
String[] protocols = new String[] {protocol};
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslcontext,protocols,null,SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
httpclient = HttpClients.custom().setSSLSocketFactory(sslsf).build();
}catch(Exception e){
e.printStackTrace();
}
return httpclient;
}
示例2: getSSLConnectionSocketFactory
/**
*
*@name 获取ssl链接
*@Description
*@CreateDate 2015年12月31日下午2:34:40
*/
public static SSLConnectionSocketFactory getSSLConnectionSocketFactory(String keyStoreType,String certFilePath,String certPassword) throws Exception{
KeyStore keyStore = KeyStore.getInstance(keyStoreType);
// FileInputStream instream = new FileInputStream(new File(certFilePath));
InputStream instream = null;
try {
instream = new ClassPathResource(certFilePath).getInputStream();
keyStore.load(instream, certPassword.toCharArray());
}
finally {
instream.close();
}
SSLContext sslContext = SSLContexts.custom()
.loadKeyMaterial(keyStore, certPassword.toCharArray())
.build();
return new SSLConnectionSocketFactory(sslContext,new String[] { "TLSv1" },null,
SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
}
示例3: getHostNameVerifier
@ReviewBeforeRelease("Need to have a way to communicate with HTTP impl supports disabling of strict" +
"hostname verification. If it doesn't we either need to fail in S3 or switch to path style" +
"addressing.")
private HostnameVerifier getHostNameVerifier(AttributeMap standardOptions) {
// TODO Need to find a better way to handle these deprecations.
return standardOptions.get(SdkHttpConfigurationOption.USE_STRICT_HOSTNAME_VERIFICATION)
? SSLConnectionSocketFactory.STRICT_HOSTNAME_VERIFIER
: SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER;
}
示例4:
private HostnameVerifier getHostNameVerifier
(HttpClientSettings options) {
// TODO Need to find a better way to handle these deprecations.
return options.useBrowserCompatibleHostNameVerifier()
? SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER
: SSLConnectionSocketFactory.STRICT_HOSTNAME_VERIFIER;
}
示例5: init
private void init() throws IOException, KeyStoreException, UnrecoverableKeyException, NoSuchAlgorithmException, KeyManagementException {
KeyStore keyStore = KeyStore.getInstance("PKCS12");
FileInputStream instream = new FileInputStream(new File(config.getCertLocalPath()));//加载本地的证书进行https加密传输
try {
keyStore.load(instream,config.getCertPassword().toCharArray());//设置证书密码
} catch (Exception e) {
e.printStackTrace();
} finally {
instream.close();
}
// Trust own CA and all self-signed certs
SSLContext sslcontext = SSLContexts.custom()
.loadKeyMaterial(keyStore, config.getCertPassword().toCharArray())
.build();
// Allow TLSv1 protocol only
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(
sslcontext,
new String[]{"TLSv1"},
null,
SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
httpClient = HttpClients.custom()
.setSSLSocketFactory(sslsf)
.build();
//根据默认超时限制初始化requestConfig
requestConfig = RequestConfig.custom().setSocketTimeout(socketTimeout).setConnectTimeout(connectTimeout).build();
hasInit = true;
}
示例6: main
public final static void main(String[] args) throws Exception {
KeyStore keyStore = KeyStore.getInstance("PKCS12");
FileInputStream instream = new FileInputStream(new File("D:/10016225.p12"));
try {
keyStore.load(instream, "10016225".toCharArray());
} finally {
instream.close();
}
// Trust own CA and all self-signed certs
SSLContext sslcontext = SSLContexts.custom()
.loadKeyMaterial(keyStore, "10016225".toCharArray())
.build();
// Allow TLSv1 protocol only
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(
sslcontext,
new String[] { "TLSv1" },
null,
SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
CloseableHttpClient httpclient = HttpClients.custom()
.setSSLSocketFactory(sslsf)
.build();
try {
HttpGet httpget = new HttpGet("https://api.mch.weixin.qq.com/secapi/pay/refund");
System.out.println("executing request" + httpget.getRequestLine());
CloseableHttpResponse response = httpclient.execute(httpget);
try {
HttpEntity entity = response.getEntity();
System.out.println("----------------------------------------");
System.out.println(response.getStatusLine());
if (entity != null) {
System.out.println("Response content length: " + entity.getContentLength());
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(entity.getContent()));
String text;
while ((text = bufferedReader.readLine()) != null) {
System.out.println(text);
}
}
EntityUtils.consume(entity);
} finally {
response.close();
}
} finally {
httpclient.close();
}
}