48
48
import javax .net .ssl .TrustManager ;
49
49
import javax .net .ssl .TrustManagerFactory ;
50
50
import java .io .IOException ;
51
- import java .io .UnsupportedEncodingException ;
52
51
import java .net .InetSocketAddress ;
53
52
import java .net .Proxy ;
54
53
import java .net .URI ;
@@ -70,7 +69,6 @@ public class AdyenHttpClient implements ClientInterface {
70
69
71
70
private static final String CHARSET = "UTF-8" ;
72
71
private static final String TERMINAL_CERTIFICATE_ALIAS = "TerminalCertificate" ;
73
- private static final String JAVA_KEYSTORE = "JKS" ;
74
72
private static final String SSL = "SSL" ;
75
73
private Proxy proxy ;
76
74
@@ -150,25 +148,26 @@ private void setHeaders(Config config, RequestOptions requestOptions, HttpReques
150
148
}
151
149
}
152
150
153
- private HttpRequestBase createHttpRequestBase (URI endpoint , String requestBody , ApiConstants .HttpMethod httpMethod ) throws HTTPClientException {
154
- try {
155
- switch (httpMethod ) {
156
- case GET :
157
- return new HttpGet (endpoint );
158
- case PATCH :
159
- HttpPatch httpPatch = new HttpPatch (endpoint );
160
- httpPatch .setEntity (new StringEntity (requestBody ));
161
- return httpPatch ;
162
- case DELETE :
163
- new HttpDelete (endpoint );
164
- default :
165
- // Default to POST if httpMethod is not provided
166
- HttpPost httpPost = new HttpPost (endpoint );
167
- httpPost .setEntity (new StringEntity (requestBody ));
168
- return httpPost ;
169
- }
170
- } catch (UnsupportedEncodingException e ) {
171
- throw new HTTPClientException ("Unsupported encoding" , e );
151
+ private HttpRequestBase createHttpRequestBase (URI endpoint , String requestBody , ApiConstants .HttpMethod httpMethod ) {
152
+ StringEntity requestEntity = null ;
153
+ if (requestBody != null && !requestBody .isEmpty ()) {
154
+ requestEntity = new StringEntity (requestBody , CHARSET );
155
+ }
156
+
157
+ switch (httpMethod ) {
158
+ case GET :
159
+ return new HttpGet (endpoint );
160
+ case PATCH :
161
+ HttpPatch httpPatch = new HttpPatch (endpoint );
162
+ httpPatch .setEntity (requestEntity );
163
+ return httpPatch ;
164
+ case DELETE :
165
+ return new HttpDelete (endpoint );
166
+ default :
167
+ // Default to POST if httpMethod is not provided
168
+ HttpPost httpPost = new HttpPost (endpoint );
169
+ httpPost .setEntity (requestEntity );
170
+ return httpPost ;
172
171
}
173
172
}
174
173
@@ -193,7 +192,7 @@ private CloseableHttpClient createCloseableHttpClient(Config config) throws HTTP
193
192
HttpClientBuilder httpClientBuilder = HttpClients .custom ();
194
193
// Create new KeyStore for the terminal certificate
195
194
try {
196
- KeyStore keyStore = KeyStore .getInstance (JAVA_KEYSTORE );
195
+ KeyStore keyStore = KeyStore .getInstance (KeyStore . getDefaultType () );
197
196
keyStore .load (null , null );
198
197
keyStore .setCertificateEntry (TERMINAL_CERTIFICATE_ALIAS , config .getTerminalCertificate ());
199
198
@@ -275,4 +274,4 @@ private void setBasicAuthentication(HttpUriRequest httpUriRequest, String userna
275
274
276
275
httpUriRequest .addHeader ("Authorization" , "Basic " + authStringEnc );
277
276
}
278
- }
277
+ }
0 commit comments