本文整理汇总了Java中org.apache.http.conn.ssl.SSLConnectionSocketFactory.getDefaultHostnameVerifier方法的典型用法代码示例。如果您正苦于以下问题:Java SSLConnectionSocketFactory.getDefaultHostnameVerifier方法的具体用法?Java SSLConnectionSocketFactory.getDefaultHostnameVerifier怎么用?Java SSLConnectionSocketFactory.getDefaultHostnameVerifier使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.http.conn.ssl.SSLConnectionSocketFactory
的用法示例。
在下文中一共展示了SSLConnectionSocketFactory.getDefaultHostnameVerifier方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getHostnameVerifier
import org.apache.http.conn.ssl.SSLConnectionSocketFactory; //导入方法依赖的package包/类
/**
* Creates the {@code HostnameVerifier} given the provided {@code verification}.
*
* @param verification The intended hostname verification action.
* @return A verifier for the request verification.
* @throws IllegalArgumentException if the provided verification cannot be handled.
*/
HostnameVerifier getHostnameVerifier(HostnameVerification verification) {
// Normally, the configuration logic would give us a default of STRICT if it was not
// provided by the user. It's easy for us to do a double-check.
if (verification == null) {
verification = HostnameVerification.STRICT;
}
switch (verification) {
case STRICT:
return SSLConnectionSocketFactory.getDefaultHostnameVerifier();
case NONE:
return NoopHostnameVerifier.INSTANCE;
default:
throw new IllegalArgumentException("Unhandled HostnameVerification: "
+ hostnameVerification);
}
}
示例2: httpClient
import org.apache.http.conn.ssl.SSLConnectionSocketFactory; //导入方法依赖的package包/类
private HttpClient httpClient(JiraConnectionProperties jiraConnectionProperties) {
try {
SSLContext sslContext = SSLContexts.custom()
.loadTrustMaterial(
jiraConnectionProperties.getSslTrustStore().getFile(),
jiraConnectionProperties.getSslTrustStorePassword())
.build();
HostnameVerifier hostnameVerifier = SSLConnectionSocketFactory.getDefaultHostnameVerifier();
SSLSocketFactory socketFactory = sslContext.getSocketFactory();
LayeredConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(socketFactory, hostnameVerifier);
if (jiraConnectionProperties.getSshJumpHost() != null) {
sshProxy = new SshProxy();
sslSocketFactory = new SshTunnelSslSocketFactory(sshProxy, sslSocketFactory, jiraConnectionProperties.getSshJumpHost());
}
return HttpClientBuilder.create()
.setSSLSocketFactory(sslSocketFactory)
.build();
} catch (GeneralSecurityException | IOException e) {
throw new JiraSyncException("Failed to build custom http client", e);
}
}
示例3: NestSession
import org.apache.http.conn.ssl.SSLConnectionSocketFactory; //导入方法依赖的package包/类
public NestSession(String username, String password) throws LoginException {
super();
theLine = null;
theBody = null;
response = null;
theUsername = new String(username);
thePassword = new String(password);
log.info("Starting Nest login...");
retry = 0;
// Trust own CA and all self-signed certs
sslcontext = SSLContexts.createDefault();
// Allow TLSv1 protocol only
sslsf = new SSLConnectionSocketFactory(
sslcontext,
new String[] { "TLSv1" },
null,
SSLConnectionSocketFactory.getDefaultHostnameVerifier());
globalConfig = RequestConfig.custom()
.setCookieSpec(CookieSpecs.STANDARD)
.build();
_login();
}
示例4: buildSSLConnectionSocketFactory
import org.apache.http.conn.ssl.SSLConnectionSocketFactory; //导入方法依赖的package包/类
private SSLConnectionSocketFactory buildSSLConnectionSocketFactory() {
try {
SSLContext sslcontext = SSLContexts.custom()
//忽略掉对服务器端证书的校验
.loadTrustMaterial(new TrustStrategy() {
@Override
public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
return true;
}
}).build();
return new SSLConnectionSocketFactory(
sslcontext,
new String[]{"TLSv1"},
null,
SSLConnectionSocketFactory.getDefaultHostnameVerifier());
} catch (NoSuchAlgorithmException | KeyManagementException | KeyStoreException e) {
this.log.error(e.getMessage(), e);
}
return null;
}
示例5: init
import org.apache.http.conn.ssl.SSLConnectionSocketFactory; //导入方法依赖的package包/类
/**
* 创建httpclient连接池,并初始化httpclient
*/
public void init() {
try {
SSLContext sslcontext = SSLContexts.custom().loadTrustMaterial(null,
new TrustSelfSignedStrategy())
.build();
HostnameVerifier hostnameVerifier = SSLConnectionSocketFactory.getDefaultHostnameVerifier();
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(
sslcontext, hostnameVerifier);
Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create()
.register("http", PlainConnectionSocketFactory.getSocketFactory())
.register("https", sslsf)
.build();
httpClientConnectionManager = new PoolingHttpClientConnectionManager(socketFactoryRegistry);
// Increase max total connection to 200
httpClientConnectionManager.setMaxTotal(maxTotalPool);
// Increase default max connection per route to 20
httpClientConnectionManager.setDefaultMaxPerRoute(maxConPerRoute);
SocketConfig socketConfig = SocketConfig.custom().setSoTimeout(socketTimeout).build();
httpClientConnectionManager.setDefaultSocketConfig(socketConfig);
} catch (Exception e) {
}
}
示例6: getRegistry
import org.apache.http.conn.ssl.SSLConnectionSocketFactory; //导入方法依赖的package包/类
protected Registry<ConnectionSocketFactory> getRegistry() {
HostnameVerifier verifier = SSLConnectionSocketFactory.getDefaultHostnameVerifier();
SSLConnectionSocketFactory sslConnectionSocketFactory = new SSLConnectionSocketFactory(
this.options.getSslContext(),
new String[]{"TLSv1.2"}, null, verifier);
return RegistryBuilder.<ConnectionSocketFactory>create()
.register("http", PlainConnectionSocketFactory.getSocketFactory())
.register("https", sslConnectionSocketFactory)
.build();
}
示例7: getCloseableHttpClient
import org.apache.http.conn.ssl.SSLConnectionSocketFactory; //导入方法依赖的package包/类
private static CloseableHttpClient getCloseableHttpClient() {
SSLContext sslcontext = SSLContexts.createDefault();
SSLConnectionSocketFactory factory = new SSLConnectionSocketFactory(sslcontext,
new String[]{HttpConstant.TLS_VERSION}, null,
SSLConnectionSocketFactory.getDefaultHostnameVerifier());
return HttpClients.custom().setSSLSocketFactory(factory).build();
}
示例8: initSslContext
import org.apache.http.conn.ssl.SSLConnectionSocketFactory; //导入方法依赖的package包/类
private SSLConnectionSocketFactory initSslContext(String keyStoreType, String keyStorePath, String keyStorePassword, String keyPassword,
String trustStoreType, String trustStorePath, String trustStorePassword)
throws CertificateException, NoSuchAlgorithmException, KeyStoreException, IOException, UnrecoverableKeyException, KeyManagementException {
SSLContextBuilder sslContextBuilder = SSLContexts.custom();
if (StringUtils.isNoneBlank(keyStorePath)) {
KeyStore keyStore = SslUtils.getStore(keyStoreType, keyStorePath, keyStorePassword);
if (keyStore.size() == 0) {
throw new IllegalStateException("Key store has no keys");
}
sslContextBuilder.loadKeyMaterial(keyStore, keyPassword.toCharArray());
}
if (StringUtils.isNoneBlank(trustStorePath)) {
KeyStore trustStore = SslUtils.getStore(trustStoreType, trustStorePath, trustStorePassword);
if (trustStore.size() == 0) {
throw new IllegalStateException("Trust store has no keys");
}
sslContextBuilder.loadTrustMaterial(trustStore, new TrustSelfSignedStrategy());
}
return new SSLConnectionSocketFactory(
sslContextBuilder.build(),
SSLConnectionSocketFactory.getDefaultHostnameVerifier());
}
示例9: getSSLFactory
import org.apache.http.conn.ssl.SSLConnectionSocketFactory; //导入方法依赖的package包/类
public static SSLConnectionSocketFactory getSSLFactory()
throws CertificateException, NoSuchAlgorithmException, KeyStoreException, IOException,
KeyManagementException {
SSLContext sslcontext = SSLContexts.custom().loadTrustMaterial(
new File(ModellerClient.class.getResource("/modeller.jks").getFile()),
"changeme".toCharArray(), new TrustSelfSignedStrategy()).build();
SSLConnectionSocketFactory sslsf =
new SSLConnectionSocketFactory(sslcontext, new String[]{"TLSv1"}, null,
SSLConnectionSocketFactory.getDefaultHostnameVerifier());
return sslsf;
}
示例10: WxBot
import org.apache.http.conn.ssl.SSLConnectionSocketFactory; //导入方法依赖的package包/类
public WxBot() {
System.setProperty("jsse.enableSNIExtension", "false");
System.setProperty("https.protocols", "TLSv1");
try {
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(SSLContext.getDefault(),
new String[] { "TLSv1" }, null, SSLConnectionSocketFactory.getDefaultHostnameVerifier());
httpClient = HttpClients.custom().setSSLSocketFactory(sslsf).build();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
}
示例11: main
import org.apache.http.conn.ssl.SSLConnectionSocketFactory; //导入方法依赖的package包/类
public final static void main(String[] args) throws Exception {
// Trust own CA and all self-signed certs
SSLContext sslcontext = SSLContexts.custom()
.loadTrustMaterial(new File("my.keystore"), "nopassword".toCharArray(),
new TrustSelfSignedStrategy())
.build();
// Allow TLSv1 protocol only
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(
sslcontext,
new String[] { "TLSv1" },
null,
SSLConnectionSocketFactory.getDefaultHostnameVerifier());
CloseableHttpClient httpclient = HttpClients.custom()
.setSSLSocketFactory(sslsf)
.build();
try {
HttpGet httpget = new HttpGet("https://httpbin.org/");
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());
EntityUtils.consume(entity);
} finally {
response.close();
}
} finally {
httpclient.close();
}
}
示例12: httpClientFactory
import org.apache.http.conn.ssl.SSLConnectionSocketFactory; //导入方法依赖的package包/类
protected CloseableHttpClient httpClientFactory() throws CannotInitializeDataAdapterException {
try {
SSLConnectionSocketFactory csf = new SSLConnectionSocketFactory(
createSslCustomContext(),
null,
null,
SSLConnectionSocketFactory.getDefaultHostnameVerifier());
RegistryBuilder<AuthSchemeProvider> schemeProviderBuilder = RegistryBuilder.create();
schemeProviderBuilder.register(AuthSchemes.SPNEGO, new SPNegoSchemeFactory());
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(
new AuthScope(null, -1, null),
new Credentials() {
@Override
public Principal getUserPrincipal() {
return null;
}
@Override
public String getPassword() {
return null;
}
});
return HttpClients.custom()
.setDefaultAuthSchemeRegistry(schemeProviderBuilder.build())
.setDefaultCredentialsProvider(credsProvider)
.setSSLSocketFactory(csf)
.build();
} catch (IOException | UnrecoverableKeyException | CertificateException | NoSuchAlgorithmException | KeyStoreException | NoSuchProviderException | KeyManagementException e) {
throw new CannotInitializeDataAdapterException("Could not initialize adapter to source '" + this.getSourceName() + "': " + e.getMessage(), e);
}
}
示例13: postSSL
import org.apache.http.conn.ssl.SSLConnectionSocketFactory; //导入方法依赖的package包/类
public static String postSSL(String url, String data, String certPath, String certPass) {
try {
KeyStore clientStore = KeyStore.getInstance("PKCS12");
// 读取本机存放的PKCS12证书文件
FileInputStream instream = new FileInputStream(certPath);
try {
// 指定PKCS12的密码(商户ID)
clientStore.load(instream, certPass.toCharArray());
} finally {
instream.close();
}
SSLContext sslcontext = SSLContexts.custom().loadKeyMaterial(clientStore, certPass.toCharArray()).build();
// 指定TLS版本
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslcontext, new String[]{"TLSv1"}, null,
SSLConnectionSocketFactory.getDefaultHostnameVerifier());
// 设置httpclient的SSLSocketFactory
CloseableHttpClient httpclient = HttpClients.custom().setSSLSocketFactory(sslsf).build();
try {
HttpPost httpost = new HttpPost(url); // 设置响应头信息
httpost.addHeader("Connection", "keep-alive");
httpost.addHeader("Accept", "*/*");
httpost.addHeader("Content-Type", CONTENT_TYPE_FORM.toString());
httpost.addHeader("X-Requested-With", "XMLHttpRequest");
httpost.addHeader("Cache-Control", "max-age=0");
httpost.addHeader("User-Agent", DEFAULT_USER_AGENT);
httpost.setEntity(new StringEntity(data, "UTF-8"));
CloseableHttpResponse response = httpclient.execute(httpost);
try {
HttpEntity entity = response.getEntity();
String jsonStr = EntityUtils.toString(response.getEntity(), "UTF-8");
EntityUtils.consume(entity);
return jsonStr;
} finally {
response.close();
}
} finally {
httpclient.close();
}
} catch (Exception e) {
logger.error("", e);
throw new RuntimeException(e);
}
}
示例14: init
import org.apache.http.conn.ssl.SSLConnectionSocketFactory; //导入方法依赖的package包/类
/**
* Initialization method. This takes in the configuration and sets up the underlying
* http client appropriately.
* @param configuration The user defined configuration.
*/
@Override
public void init(final Configuration configuration) {
// Save reference to configuration
this.configuration = configuration;
// Create default SSLContext
final SSLContext sslcontext = SSLContexts.createDefault();
// Allow TLSv1 protocol only
final SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(
sslcontext,
new String[] { "TLSv1" },
null,
SSLConnectionSocketFactory.getDefaultHostnameVerifier()
);
// Setup client builder
final HttpClientBuilder clientBuilder = HttpClientBuilder.create();
clientBuilder
// Pardot disconnects requests after 120 seconds.
.setConnectionTimeToLive(130, TimeUnit.SECONDS)
.setSSLSocketFactory(sslsf);
// Define our RequestConfigBuilder
final RequestConfig.Builder requestConfigBuilder = RequestConfig.custom();
// If we have a configured proxy host
if (configuration.getProxyHost() != null) {
// Define proxy host
final HttpHost proxyHost = new HttpHost(
configuration.getProxyHost(),
configuration.getProxyPort(),
configuration.getProxyScheme()
);
// If we have proxy auth enabled
if (configuration.getProxyUsername() != null) {
// Create credential provider
final CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(
new AuthScope(configuration.getProxyHost(), configuration.getProxyPort()),
new UsernamePasswordCredentials(configuration.getProxyUsername(), configuration.getProxyPassword())
);
// Attach Credentials provider to client builder.
clientBuilder.setDefaultCredentialsProvider(credsProvider);
}
// Attach Proxy to request config builder
requestConfigBuilder.setProxy(proxyHost);
}
// Attach default request config
clientBuilder.setDefaultRequestConfig(requestConfigBuilder.build());
// build http client
httpClient = clientBuilder.build();
}
示例15: executePostWithForm
import org.apache.http.conn.ssl.SSLConnectionSocketFactory; //导入方法依赖的package包/类
public static InputStream executePostWithForm(String targetURL, List<Property> properties)
throws ClientProtocolException, IOException {
// Create SSL Client
SSLContext sslcontext = SSLContexts.createSystemDefault();
SSLConnectionSocketFactory sslConnectionSocketFactory =
new SSLConnectionSocketFactory(
sslcontext,
new String[] { "TLSv1", "SSLv3" },
null,
SSLConnectionSocketFactory.getDefaultHostnameVerifier());
Registry<ConnectionSocketFactory> socketFactoryRegistry =
RegistryBuilder.<ConnectionSocketFactory>create()
.register("http", PlainConnectionSocketFactory.INSTANCE)
.register("https", sslConnectionSocketFactory)
.build();
PoolingHttpClientConnectionManager cm =
new PoolingHttpClientConnectionManager(socketFactoryRegistry);
CloseableHttpClient httpClient = HttpClients.custom()
.setSSLSocketFactory(sslConnectionSocketFactory)
.setConnectionManager(cm)
.build();
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
for (Property p : properties)
builder.addTextBody(p.key, p.value, ContentType.TEXT_PLAIN);
HttpPost uploadFile = new HttpPost(targetURL);
uploadFile.setEntity(builder.build());
// Send POST
CloseableHttpResponse response = httpClient.execute(uploadFile);
int status = response.getStatusLine().getStatusCode();
if ((status == HttpURLConnection.HTTP_MOVED_TEMP
|| status == HttpURLConnection.HTTP_MOVED_PERM
|| status == HttpURLConnection.HTTP_SEE_OTHER)) {
System.out.println("Got status " + status);
// Get redirect url from "location" header field
String newURL = response.getFirstHeader("Location").getValue();
System.out.println("Redirect to URL: " + newURL);
// Send the new POST
uploadFile = new HttpPost(newURL);
uploadFile.setEntity(builder.build());
response = httpClient.execute(uploadFile);
}
// Get response
return response.getEntity().getContent();
}