Skip to content

Commit 89bf007

Browse files
committed
+ Fix for issue #285 & #288.
1 parent bc78dbf commit 89bf007

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

src/main/java/Api/SearchTransactionsApi.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@ public TssV2TransactionsPost201Response createSearch(CreateSearchRequest createS
142142
this.apiClient.setComputationStartTime(System.nanoTime());
143143
ApiResponse<TssV2TransactionsPost201Response> resp = createSearchWithHttpInfo(createSearchRequest);
144144
logger.info("CALL TO METHOD 'createSearch' ENDED");
145+
if(resp == null)
146+
{
147+
logger.info("CALL TO METHOD 'createSearch' FAILED DUE TO AN EXCEPTION");
148+
return null;
149+
}
145150
return resp.getData();
146151
}
147152

src/main/java/Invokers/ApiClient.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)