本文整理匯總了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;
}