17
17
18
18
import com .fasterxml .jackson .databind .ObjectMapper ;
19
19
import com .unzer .payment .ApplePaySession ;
20
- import org .apache .http .HttpEntity ;
21
- import org .apache .http .client .methods .CloseableHttpResponse ;
22
- import org .apache .http .client .methods .HttpPost ;
23
- import org .apache .http .conn .ssl .SSLConnectionSocketFactory ;
24
- import org .apache .http .entity .ContentType ;
25
- import org .apache .http .entity .StringEntity ;
26
- import org .apache .http .impl .client .CloseableHttpClient ;
27
- import org .apache .http .impl .client .HttpClients ;
28
- import org .apache .http .util .EntityUtils ;
20
+ import org .apache .hc .client5 .http .classic .methods .HttpPost ;
21
+ import org .apache .hc .client5 .http .impl .classic .CloseableHttpClient ;
22
+ import org .apache .hc .client5 .http .impl .classic .CloseableHttpResponse ;
23
+ import org .apache .hc .client5 .http .impl .classic .HttpClients ;
24
+ import org .apache .hc .client5 .http .impl .io .PoolingHttpClientConnectionManagerBuilder ;
25
+ import org .apache .hc .client5 .http .io .HttpClientConnectionManager ;
26
+ import org .apache .hc .client5 .http .ssl .HttpsSupport ;
27
+ import org .apache .hc .client5 .http .ssl .SSLConnectionSocketFactory ;
28
+ import org .apache .hc .core5 .http .ContentType ;
29
+ import org .apache .hc .core5 .http .HttpEntity ;
30
+ import org .apache .hc .core5 .http .ParseException ;
31
+ import org .apache .hc .core5 .http .io .entity .EntityUtils ;
32
+ import org .apache .hc .core5 .http .io .entity .StringEntity ;
29
33
30
34
import javax .net .ssl .KeyManagerFactory ;
31
35
import javax .net .ssl .SSLContext ;
@@ -71,18 +75,26 @@ public static void setCustomAppleValidationUrls(List<String> appleUrls) {
71
75
urls = new HashSet <>(appleUrls );
72
76
}
73
77
74
- public static String validateApplePayMerchant (String merchantValidationURL , ApplePaySession applePaySession , KeyManagerFactory keyManagerFactory , TrustManagerFactory trustManagerFactory ) throws IOException , NoSuchAlgorithmException , KeyManagementException , URISyntaxException {
78
+ public static String validateApplePayMerchant (
79
+ String merchantValidationURL ,
80
+ ApplePaySession applePaySession ,
81
+ KeyManagerFactory keyManagerFactory ,
82
+ TrustManagerFactory trustManagerFactory
83
+ ) throws IOException , NoSuchAlgorithmException , KeyManagementException , URISyntaxException , ParseException {
75
84
ObjectMapper mapper = new ObjectMapper ();
76
85
SSLConnectionSocketFactory sslsf = setupSSLSocketFactory (keyManagerFactory , trustManagerFactory );
77
86
String response = "" ;
78
87
88
+
89
+ HttpClientConnectionManager cm = PoolingHttpClientConnectionManagerBuilder .create ().setSSLSocketFactory (sslsf ).build ();
90
+
79
91
if (doesUrlContainValidDomainName (merchantValidationURL )) {
80
- try (CloseableHttpClient httpclient = HttpClients .custom ().setSSLSocketFactory ( sslsf ).build ()) {
92
+ try (CloseableHttpClient client = HttpClients .custom ().setConnectionManager ( cm ).build ()) {
81
93
HttpPost post = new HttpPost (merchantValidationURL );
82
94
StringEntity reqEntity = new StringEntity (mapper .writeValueAsString (applePaySession ), ContentType .APPLICATION_JSON );
83
95
post .setEntity (reqEntity );
84
96
85
- CloseableHttpResponse res = httpclient .execute (post );
97
+ CloseableHttpResponse res = client .execute (post );
86
98
HttpEntity entity = res .getEntity ();
87
99
response = EntityUtils .toString (entity , "UTF-8" );
88
100
EntityUtils .consume (entity );
@@ -98,11 +110,14 @@ public static boolean doesUrlContainValidDomainName(String merchantValidationURL
98
110
return urls .contains (merchantValidationUrlDomain );
99
111
}
100
112
101
- private static SSLConnectionSocketFactory setupSSLSocketFactory (KeyManagerFactory keyManagerFactory , TrustManagerFactory trustManagerFactory ) throws KeyManagementException , NoSuchAlgorithmException {
113
+ private static SSLConnectionSocketFactory setupSSLSocketFactory (
114
+ KeyManagerFactory keyManagerFactory ,
115
+ TrustManagerFactory trustManagerFactory
116
+ ) throws KeyManagementException , NoSuchAlgorithmException {
102
117
SSLContext sslcontext = SSLContext .getInstance ("TLS" );
103
118
sslcontext .init (keyManagerFactory .getKeyManagers (), trustManagerFactory .getTrustManagers (), null );
104
119
105
- return new SSLConnectionSocketFactory (sslcontext , new String []{"TLSv1.2" }, null , SSLConnectionSocketFactory .getDefaultHostnameVerifier ());
120
+ return new SSLConnectionSocketFactory (sslcontext , new String []{"TLSv1.2" }, null , HttpsSupport .getDefaultHostnameVerifier ());
106
121
}
107
122
108
123
private static String getPlainDomainName (String url ) throws URISyntaxException {
0 commit comments