11package org .baeldung .httpclient ;
22
3+ import static org .hamcrest .CoreMatchers .equalTo ;
4+ import static org .junit .Assert .assertThat ;
5+
6+ import java .io .IOException ;
7+ import java .security .GeneralSecurityException ;
8+ import java .security .KeyManagementException ;
9+ import java .security .KeyStoreException ;
10+ import java .security .NoSuchAlgorithmException ;
11+
12+ import javax .net .ssl .SSLContext ;
13+ import javax .net .ssl .SSLException ;
14+
315import org .apache .http .HttpResponse ;
416import org .apache .http .client .methods .HttpGet ;
517import org .apache .http .conn .ClientConnectionManager ;
618import org .apache .http .conn .scheme .Scheme ;
719import org .apache .http .conn .scheme .SchemeRegistry ;
8- import org .apache .http .conn .ssl .*;
20+ import org .apache .http .conn .ssl .NoopHostnameVerifier ;
21+ import org .apache .http .conn .ssl .SSLConnectionSocketFactory ;
22+ import org .apache .http .conn .ssl .SSLContextBuilder ;
23+ import org .apache .http .conn .ssl .SSLContexts ;
24+ import org .apache .http .conn .ssl .SSLSocketFactory ;
25+ import org .apache .http .conn .ssl .TrustSelfSignedStrategy ;
26+ import org .apache .http .conn .ssl .TrustStrategy ;
927import org .apache .http .impl .client .CloseableHttpClient ;
1028import org .apache .http .impl .client .DefaultHttpClient ;
1129import org .apache .http .impl .client .HttpClientBuilder ;
1230import org .apache .http .impl .client .HttpClients ;
1331import org .apache .http .impl .conn .PoolingClientConnectionManager ;
1432import org .junit .Test ;
1533
16- import javax .net .ssl .SSLContext ;
17- import javax .net .ssl .SSLException ;
18- import java .io .IOException ;
19- import java .security .GeneralSecurityException ;
20- import java .security .KeyManagementException ;
21- import java .security .KeyStoreException ;
22- import java .security .NoSuchAlgorithmException ;
23-
24- import static org .hamcrest .CoreMatchers .equalTo ;
25- import static org .junit .Assert .assertThat ;
26-
2734/**
2835 * This test requires a localhost server over HTTPS <br>
2936 * It should only be manually run, not part of the automated build
@@ -96,7 +103,7 @@ public final void givenHttpClientPost4_3_whenAcceptingAllCertificates_thenCanCon
96103 @ Test
97104 public final void givenIgnoringCertificates_whenHttpsUrlIsConsumed_thenCorrect () throws IOException {
98105
99- TrustStrategy acceptingTrustStrategy = (certificate , authType ) -> true ;
106+ final TrustStrategy acceptingTrustStrategy = (certificate , authType ) -> true ;
100107
101108 SSLContext sslContext = null ;
102109 try {
@@ -106,8 +113,8 @@ public final void givenIgnoringCertificates_whenHttpsUrlIsConsumed_thenCorrect()
106113 e .printStackTrace ();
107114 }
108115
109- CloseableHttpClient client = HttpClients .custom ().setSSLContext (sslContext ).setSSLHostnameVerifier (new NoopHostnameVerifier ()).build ();
110- final HttpGet httpGet = new HttpGet ("https://sesar3.geoinfogeochem.org/sample/igsn/ODP000002" );
116+ final CloseableHttpClient client = HttpClients .custom ().setSSLContext (sslContext ).setSSLHostnameVerifier (new NoopHostnameVerifier ()).build ();
117+ final HttpGet httpGet = new HttpGet (HOST_WITH_SSL );
111118 httpGet .setHeader ("Accept" , "application/xml" );
112119
113120 final HttpResponse response = client .execute (httpGet );
0 commit comments