本文整理汇总了Java中org.apache.http.conn.ssl.AllowAllHostnameVerifier类的典型用法代码示例。如果您正苦于以下问题:Java AllowAllHostnameVerifier类的具体用法?Java AllowAllHostnameVerifier怎么用?Java AllowAllHostnameVerifier使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AllowAllHostnameVerifier类属于org.apache.http.conn.ssl包,在下文中一共展示了AllowAllHostnameVerifier类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: executeGetRequest
import org.apache.http.conn.ssl.AllowAllHostnameVerifier; //导入依赖的package包/类
@Override
public ResponseObject executeGetRequest(String url, int timeoutInMs) throws IOException {
final HttpGet request = new HttpGet(url);
setHeaders(request);
setCookies(request);
try (CloseableHttpClient httpClient =
HttpClients.custom()
.setHostnameVerifier(new AllowAllHostnameVerifier())
.setSslcontext(trustAllSslContext())
.setDefaultRequestConfig(buildRequestConfig(timeoutInMs))
.build();
CloseableHttpResponse response = httpClient.execute(request)) {
Header[] headersArray = response.getAllHeaders();
Map<String, List<String>> tmpHeaders = new HashMap<>();
for (Header header : headersArray) {
tmpHeaders.put(header.getName(), Collections.singletonList(header.getValue()));
}
return new ResponseObject(tmpHeaders, IOUtils.toByteArray(response.getEntity().getContent()));
} catch (Exception e) {
throw new IOException(String.format("Failed to connect to %s - %s", url, e.getMessage()), e);
}
}
示例2: createRestTemplate
import org.apache.http.conn.ssl.AllowAllHostnameVerifier; //导入依赖的package包/类
private static RestTemplate createRestTemplate(String host, String username, String password, Set<ClientHttpRequestInterceptor> interceptors) throws GeneralSecurityException {
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(new AuthScope(host, 25555),
new UsernamePasswordCredentials(username, password));
SSLContext sslContext = SSLContexts.custom()
.loadTrustMaterial(null, new TrustSelfSignedStrategy())
.useTLS()
.build();
SSLConnectionSocketFactory connectionFactory = new SSLConnectionSocketFactory(sslContext, new AllowAllHostnameVerifier());
HttpClient httpClient = HttpClientBuilder.create()
.disableRedirectHandling()
.setDefaultCredentialsProvider(credentialsProvider)
.setSSLSocketFactory(connectionFactory)
.build();
RestTemplate restTemplate = new RestTemplate(new HttpComponentsClientHttpRequestFactory(httpClient));
restTemplate.getInterceptors().addAll(interceptors);
return restTemplate;
}
示例3: getApacheSslBypassClient
import org.apache.http.conn.ssl.AllowAllHostnameVerifier; //导入依赖的package包/类
private CloseableHttpClient getApacheSslBypassClient() throws NoSuchAlgorithmException,
KeyManagementException, KeyStoreException {
return HttpClients.custom().
setHostnameVerifier(new AllowAllHostnameVerifier()).
setSslcontext(new SSLContextBuilder()
.loadTrustMaterial(null, (arg0, arg1) -> true)
.build()).build();
}
示例4: getSchemeRegistry
import org.apache.http.conn.ssl.AllowAllHostnameVerifier; //导入依赖的package包/类
public static SchemeRegistry getSchemeRegistry() {
try {
KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
trustStore.load(null, null);
SSLSocketFactory.getSocketFactory().setHostnameVerifier(new AllowAllHostnameVerifier());
SSLSocketFactory sf = new SSLSocketFactory(trustStore);
sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
HttpParams params = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(params, 10000);
HttpConnectionParams.setSoTimeout(params, 10000);
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
SchemeRegistry registry = new SchemeRegistry();
registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
registry.register(new Scheme("https", sf, 443));
return registry;
} catch (Exception e) {
return null;
}
}
示例5: ignoreAuthenticateServer
import org.apache.http.conn.ssl.AllowAllHostnameVerifier; //导入依赖的package包/类
public AbstractRestTemplateClient ignoreAuthenticateServer() {
//backward compatible with android httpclient 4.3.x
if(restTemplate.getRequestFactory() instanceof HttpComponentsClientHttpRequestFactory) {
try {
SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, new TrustSelfSignedStrategy()).build();
X509HostnameVerifier verifier = ignoreSslWarning ? new AllowAllHostnameVerifier() : new BrowserCompatHostnameVerifier();
SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(sslContext, verifier);
HttpClient httpClient = HttpClients.custom().setSSLSocketFactory(socketFactory).build();
((HttpComponentsClientHttpRequestFactory)restTemplate.getRequestFactory()).setHttpClient(httpClient);
} catch (Exception e) {
e.printStackTrace();
}
} else {
Debug.error("the request factory " + restTemplate.getRequestFactory().getClass().getName() + " does not support ignoreAuthenticateServer");
}
return this;
}
开发者ID:Enterprise-Content-Management,项目名称:documentum-rest-client-java,代码行数:18,代码来源:AbstractRestTemplateClient.java
示例6: createRequestFactory
import org.apache.http.conn.ssl.AllowAllHostnameVerifier; //导入依赖的package包/类
private ClientHttpRequestFactory createRequestFactory(String host, String username,
String password) {
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(new AuthScope(host, 25555),
new UsernamePasswordCredentials(username, password));
SSLContext sslContext = null;
try {
sslContext = SSLContexts.custom()
.loadTrustMaterial(null, new TrustSelfSignedStrategy()).useTLS().build();
} catch (KeyManagementException | NoSuchAlgorithmException | KeyStoreException e) {
throw new DirectorException("Unable to configure ClientHttpRequestFactory", e);
}
SSLConnectionSocketFactory connectionFactory = new SSLConnectionSocketFactory(sslContext,
new AllowAllHostnameVerifier());
// disabling redirect handling is critical for the way BOSH uses 302's
HttpClient httpClient = HttpClientBuilder.create().disableRedirectHandling()
.setDefaultCredentialsProvider(credentialsProvider)
.setSSLSocketFactory(connectionFactory).build();
return new HttpComponentsClientHttpRequestFactory(httpClient);
}
示例7: testSSLSystemProperties
import org.apache.http.conn.ssl.AllowAllHostnameVerifier; //导入依赖的package包/类
@Test
@SuppressWarnings("deprecation")
public void testSSLSystemProperties() {
try {
SSLTestConfig.setSSLSystemProperties();
assertNotNull("HTTPS scheme could not be created using the javax.net.ssl.* system properties.",
HttpClientUtil.createClient(null).getConnectionManager().getSchemeRegistry().get("https"));
System.clearProperty(HttpClientUtil.SYS_PROP_CHECK_PEER_NAME);
assertEquals(BrowserCompatHostnameVerifier.class, getHostnameVerifier(HttpClientUtil.createClient(null)).getClass());
System.setProperty(HttpClientUtil.SYS_PROP_CHECK_PEER_NAME, "true");
assertEquals(BrowserCompatHostnameVerifier.class, getHostnameVerifier(HttpClientUtil.createClient(null)).getClass());
System.setProperty(HttpClientUtil.SYS_PROP_CHECK_PEER_NAME, "");
assertEquals(BrowserCompatHostnameVerifier.class, getHostnameVerifier(HttpClientUtil.createClient(null)).getClass());
System.setProperty(HttpClientUtil.SYS_PROP_CHECK_PEER_NAME, "false");
assertEquals(AllowAllHostnameVerifier.class, getHostnameVerifier(HttpClientUtil.createClient(null)).getClass());
} finally {
SSLTestConfig.clearSSLSystemProperties();
System.clearProperty(HttpClientUtil.SYS_PROP_CHECK_PEER_NAME);
}
}
示例8: test1
import org.apache.http.conn.ssl.AllowAllHostnameVerifier; //导入依赖的package包/类
public void test1() throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException, ClientProtocolException, IOException{
// ## SHOULD FIRE OVER-PERMISSIVE HOSTNAME VERIFIER
CloseableHttpClient httpClient = HttpClients.custom().
setHostnameVerifier(new AllowAllHostnameVerifier()).
setSslcontext(new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy() {
// ## SHOULD FIRE OVER-PERMISSIVE TRUST MANAGER
@Override
public boolean isTrusted(X509Certificate[] arg0, String arg1) throws java.security.cert.CertificateException {
return true;
}
}).build()).build();
HttpGet httpget = new HttpGet("https://www.google.com/");
CloseableHttpResponse response = httpClient.execute(httpget);
try {
System.out.println(response.toString());
} finally {
response.close();
}
}
示例9: getHgmHttpsRestTemplate
import org.apache.http.conn.ssl.AllowAllHostnameVerifier; //导入依赖的package包/类
@Bean
@Qualifier("hgmRestTemplate")
public RestTemplate getHgmHttpsRestTemplate() throws KeyStoreException, NoSuchAlgorithmException,
KeyManagementException {
SSLContext sslContext =
SSLContexts.custom().loadTrustMaterial(null, new TrustSelfSignedStrategy()).useTLS()
.build();
SSLConnectionSocketFactory connectionFactory =
new SSLConnectionSocketFactory(sslContext, new AllowAllHostnameVerifier());
BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(configuration.getUsername(),
configuration.getPassword()));
HttpClient httpClient =
HttpClientBuilder.create().setSSLSocketFactory(connectionFactory)
.setDefaultCredentialsProvider(credentialsProvider).build();
ClientHttpRequestFactory requestFactory =
new HttpComponentsClientHttpRequestFactory(httpClient);
return new RestTemplate(requestFactory);
}
示例10: createSslHttpClient
import org.apache.http.conn.ssl.AllowAllHostnameVerifier; //导入依赖的package包/类
private CloseableHttpClient createSslHttpClient() throws Exception {
final SSLContextBuilder wsBuilder = new SSLContextBuilder();
wsBuilder.loadTrustMaterial(null, new TrustStrategy() {
@Override
public boolean isTrusted(X509Certificate[] chain,
String authType) throws CertificateException {
return true;
}
});
final SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(wsBuilder.build(),
new AllowAllHostnameVerifier());
//This winds up using a PoolingHttpClientConnectionManager so need to pass the
//RegistryBuilder
final Registry<ConnectionSocketFactory> registry = RegistryBuilder
.<ConnectionSocketFactory> create().register("https", sslsf)
.build();
final PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(registry);
return HttpClients
.custom()
.setConnectionManager(cm)
.build();
}
示例11: init
import org.apache.http.conn.ssl.AllowAllHostnameVerifier; //导入依赖的package包/类
@PostConstruct
public void init() {
try {
HttpClientInfo httpci = this.commonConfig.createHttpClientInfo();
http = HttpClients.custom()
.setConnectionManager(httpci.getCm()).setDefaultRequestConfig(httpci.getGlobalConfig()).setHostnameVerifier(new AllowAllHostnameVerifier())
.build();
URL uurl = new URL(commonConfig.getScaleConfig().getServiceConfiguration()
.getUnisonURL());
int port = uurl.getPort();
HttpServletRequest request = (HttpServletRequest) FacesContext
.getCurrentInstance().getExternalContext().getRequest();
this.login = request.getRemoteUser();
} catch (Exception e) {
logger.error("Could not initialize ScaleSession",e);
}
}
示例12: setupClient
import org.apache.http.conn.ssl.AllowAllHostnameVerifier; //导入依赖的package包/类
@SuppressWarnings("deprecation")
@SuppressLint("AllowAllHostnameVerifier")
private void setupClient(HttpURLConnection conn, boolean acceptAnyCertificate)
throws CertificateException, UnrecoverableKeyException,
NoSuchAlgorithmException, KeyStoreException,
KeyManagementException, NoSuchProviderException,
IOException {
// bug caused by Lighttpd
//conn.setRequestProperty("Expect", "100-continue");
conn.setConnectTimeout(CONNECT_TIMEOUT);
conn.setReadTimeout(READ_TIMEOUT);
conn.setDoInput(true);
if (conn instanceof HttpsURLConnection) {
((HttpsURLConnection) conn).setSSLSocketFactory(setupSSLSocketFactory(mContext,
mPrivateKey, mCertificate, acceptAnyCertificate));
if (acceptAnyCertificate)
((HttpsURLConnection) conn).setHostnameVerifier(new AllowAllHostnameVerifier());
}
}
示例13: getHttpsClientTrustAll
import org.apache.http.conn.ssl.AllowAllHostnameVerifier; //导入依赖的package包/类
public HttpClient getHttpsClientTrustAll() {
try {
SSLSocketFactory sf = new SSLSocketFactory(new TrustStrategy(){
@Override
public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
return true;
}
}, new AllowAllHostnameVerifier());
PlainSocketFactory psf = PlainSocketFactory.getSocketFactory();
SchemeRegistry registry = new SchemeRegistry();
registry.register(new Scheme("http", 80, psf));
registry.register(new Scheme("https", 443, sf));
ClientConnectionManager ccm = new PoolingClientConnectionManager(registry);
return new DefaultHttpClient(ccm);
} catch (Exception ex) {
log.error("Failed to create TrustAll https client", ex);
return new DefaultHttpClient();
}
}
示例14: BuildHttpClient
import org.apache.http.conn.ssl.AllowAllHostnameVerifier; //导入依赖的package包/类
public DefaultHttpClient BuildHttpClient() throws UnknownHostException, NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException {
SSLSocketFactory sf = new SSLSocketFactory(new TrustStrategy() {
@Override
public boolean isTrusted(X509Certificate[] chain,
String authType) throws CertificateException {
return true;
}
}, new AllowAllHostnameVerifier());
SchemeRegistry registry = new SchemeRegistry();
registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
registry.register(new Scheme("https", sf, 443));
ThreadSafeClientConnManager ccm = new ThreadSafeClientConnManager(registry);
//ClientConnectionManager ccm=new SingleClientConnManager(registry);
DefaultHttpClient httpclient = new DefaultHttpClient(ccm);
ccm.setMaxTotal(999);
ccm.setDefaultMaxPerRoute(10);
return httpclient;
}
示例15: createClient
import org.apache.http.conn.ssl.AllowAllHostnameVerifier; //导入依赖的package包/类
protected HttpClient createClient() throws Exception {
DefaultHttpClient result = new DefaultHttpClient();
SchemeRegistry sr = result.getConnectionManager().getSchemeRegistry();
SSLSocketFactory sslsf = new SSLSocketFactory(new TrustStrategy() {
@Override
public boolean isTrusted(X509Certificate[] arg0, String arg1)
throws CertificateException {
return true;
}
}, new AllowAllHostnameVerifier());
Scheme httpsScheme2 = new Scheme("https", 443, sslsf);
sr.register(httpsScheme2);
return result;
}