@@ -138,7 +138,7 @@ public class ApiClient {
138138
139139 private JSON json ;
140140 private String versionInfo ;
141- private static ConnectionPool connectionPool = new ConnectionPool (5 , 10 , TimeUnit .SECONDS );
141+ private static ConnectionPool defaultConnectionPool = new ConnectionPool (5 , 10 , TimeUnit .SECONDS );
142142 private HttpLoggingInterceptor loggingInterceptor ;
143143 private long computationStartTime ;
144144 private static Logger logger = LogManager .getLogger (ApiClient .class );
@@ -165,7 +165,7 @@ public static OkHttpClient initializeFinalVariables() {
165165 .connectTimeout (1 , TimeUnit .SECONDS )
166166 .writeTimeout (60 , TimeUnit .SECONDS )
167167 .readTimeout (60 , TimeUnit .SECONDS )
168- .connectionPool (ApiClient .connectionPool )
168+ .connectionPool (ApiClient .defaultConnectionPool )
169169 .addInterceptor (logging )
170170 .build ();
171171 }
@@ -244,6 +244,8 @@ public ApiClient(MerchantConfig merchantConfig) {
244244 int connectionTimeout = Math .max (merchantConfig .getUserDefinedConnectionTimeout (), 1 );
245245 int readTimeout = Math .max (merchantConfig .getUserDefinedReadTimeout (), 60 );
246246 int writeTimeout = Math .max (merchantConfig .getUserDefinedWriteTimeout (), 60 );
247+ int keepAliveDuration = Math .max (merchantConfig .getUserDefinedKeepAliveDuration (), 10 );
248+ ConnectionPool connectionPool = new ConnectionPool (5 , keepAliveDuration , TimeUnit .SECONDS );
247249
248250 Authenticator proxyAuthenticator ;
249251
@@ -286,6 +288,7 @@ public Request authenticate(Route route, Response response) throws IOException {
286288 .readTimeout (readTimeout , TimeUnit .SECONDS )
287289 .retryOnConnectionFailure (true )
288290 .addInterceptor (new RetryInterceptor (this .apiRequestMetrics ))
291+ .connectionPool (connectionPool )
289292 .eventListener (new NetworkEventListener (this .getNewRandomId (), System .nanoTime ()))
290293 .build ();
291294 }
@@ -304,6 +307,7 @@ public Request authenticate(Route route, Response response) throws IOException {
304307 .connectTimeout (connectionTimeout , TimeUnit .SECONDS )
305308 .writeTimeout (writeTimeout , TimeUnit .SECONDS )
306309 .readTimeout (readTimeout , TimeUnit .SECONDS )
310+ .connectionPool (connectionPool )
307311 .retryOnConnectionFailure (true )
308312 .addInterceptor (new RetryInterceptor (this .apiRequestMetrics ))
309313 .eventListener (new NetworkEventListener (this .getNewRandomId (), System .nanoTime ()))
@@ -1207,9 +1211,13 @@ public <T> ApiResponse<T> execute(Call call, Type returnType) throws ApiExceptio
12071211
12081212 return new ApiResponse <T >(response .code (), response .headers ().toMultimap (), data );
12091213 } catch (IOException e ) {
1210- logger .error ("ApiException : " + e );
1214+ logger .error ("ApiException : " + e . getMessage () );
12111215 throw new ApiException (e );
12121216 }
1217+ catch (NullPointerException e ) {
1218+ logger .error ("ApiException : " + e .getMessage ());
1219+ return null ;
1220+ }
12131221 }
12141222
12151223 /**
@@ -1280,7 +1288,7 @@ public <T> T handleResponse(Response response, Type returnType) throws ApiExcept
12801288 if (response .body () != null ) {
12811289 try {
12821290 respBody = response .body ().string ();
1283- System . out . println (respBody );
1291+ logger . info (respBody );
12841292 } catch (IOException e ) {
12851293 logger .error ("ApiException : " + e + " " + response .code () + " " + response .message ());
12861294 throw new ApiException (response .message (), e , response .code (), response .headers ().toMultimap ());
@@ -1407,7 +1415,7 @@ public void callAuthenticationHeader(String method, String path, Object body, Li
14071415 }
14081416
14091417 } catch (ConfigException e ) {
1410- System . out . println (e .getMessage ());
1418+ logger . error (e .getMessage ());
14111419 }
14121420
14131421 }
0 commit comments