Skip to content

Commit 88a9b83

Browse files
committed
Merge branch 'fix-apiClient' into release-jan25
2 parents 638f7ea + caddb44 commit 88a9b83

File tree

62 files changed

+240
-206
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+240
-206
lines changed

generator/cybersource-java-template/libraries/okhttp-gson/ApiClient.mustache

Lines changed: 40 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,18 @@ public class ApiClient {
142142
*/
143143
public static final String LENIENT_DATETIME_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSSZ";
144144

145+
/**
146+
* Use this field <b>ONLY IF</b> you have more than one instance of ApiClient.
147+
* This field should <b>NOT</b> be used/accessed for a singleton object.
148+
*/
145149
public String responseCode;
150+
151+
/**
152+
* Use this field <b>ONLY IF</b> you have more than one instance of ApiClient.
153+
* This field should <b>NOT</b> be used/accessed for a singleton object.
154+
*/
146155
public String status;
147-
public InputStream responseBody;
148-
public String respBody;
156+
149157
public MerchantConfig merchantConfig;
150158
public RequestTransactionMetrics apiRequestMetrics = new RequestTransactionMetrics();
151159

@@ -1036,6 +1044,8 @@ public class ApiClient {
10361044
return (T) downloadFileFromResponse(response);
10371045
}
10381046

1047+
String respBody = null;
1048+
10391049
try {
10401050
if (response.body() != null)
10411051
respBody = response.body().string();
@@ -1191,8 +1201,9 @@ public class ApiClient {
11911201
try {
11921202
this.apiRequestMetrics.setComputeTime((System.nanoTime() - this.getComputationStartTime()) / 1000000);
11931203
Response response = call.execute();
1194-
responseCode = String.valueOf(response.code());
1195-
status = response.message();
1204+
String responseCode = String.valueOf(response.code());
1205+
this.status = response.message();
1206+
this.responseCode = responseCode;
11961207
11971208
logger.debug("Network Response :\n" + json.serialize(response.headers()));
11981209
@@ -1208,7 +1219,7 @@ public class ApiClient {
12081219

12091220
logger.info("HTTP Response Body :\n{}", data);
12101221

1211-
return new ApiResponse<T>(response.code(), response.headers().toMultimap(), data);
1222+
return new ApiResponse<T>(response.code(), response.headers().toMultimap(), response.message(), data);
12121223
} catch (IOException e) {
12131224
logger.error("ApiException : " + e.getMessage());
12141225
throw new ApiException(e);
@@ -1317,16 +1328,19 @@ public class ApiClient {
13171328
public Call buildCall(String path, String method, List<Pair> queryParams, Object body,
13181329
Map<String, String> headerParams, Map<String, Object> formParams, String[] authNames,
13191330
ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
1320-
1331+
1332+
//create reqHeader parameter here
1333+
Map<String, String> requestHeaderMap = new HashMap<String, String>();
1334+
13211335
if(merchantConfig.getDefaultHeaders() != null && !merchantConfig.getDefaultHeaders().isEmpty()) {
13221336
for (Entry<String, String> header : merchantConfig.getDefaultHeaders().entrySet()) {
13231337
if(!header.getKey().equalsIgnoreCase("Authorization") && !header.getKey().equalsIgnoreCase("Signature")){
1324-
addDefaultHeader(header.getKey(), header.getValue());
1338+
requestHeaderMap.put(header.getKey(), header.getValue());
13251339
}
13261340
}
13271341
}
13281342

1329-
callAuthenticationHeader(method, path, body, queryParams);
1343+
callAuthenticationHeader(method, path, body, queryParams, requestHeaderMap);
13301344

13311345
if (merchantConfig.isEnableClientCert()) {
13321346
addClientCertToKeyStore();
@@ -1339,7 +1353,7 @@ public class ApiClient {
13391353
headerParams.put("Accept", defaultAcceptHeader);
13401354
}
13411355

1342-
headerParams.putAll(defaultHeaderMap);
1356+
headerParams.putAll(requestHeaderMap);
13431357

13441358

13451359
logger.info("Request Header Parameters:\n{}", new PrettyPrintingMap<String, String>(headerParams));
@@ -1353,10 +1367,10 @@ public class ApiClient {
13531367
*
13541368
*/
13551369

1356-
public void callAuthenticationHeader(String method, String path, Object body, List<Pair> queryParams) {
1370+
public void callAuthenticationHeader(String method, String path, Object body, List<Pair> queryParams, Map<String, String> requestHeaderMap) {
13571371
13581372
try {
1359-
merchantConfig.setRequestType(method);
1373+
String requestTarget = null;
13601374
13611375
if (queryParams != null && !queryParams.isEmpty()) {
13621376
StringBuilder url = new StringBuilder();
@@ -1377,10 +1391,10 @@ public class ApiClient {
13771391
url.append(escapeString(param.getName())).append("=").append(escapeString(value));
13781392
}
13791393
}
1380-
merchantConfig.setRequestTarget(url.toString());
1394+
requestTarget= url.toString();
13811395
}
13821396
} else {
1383-
merchantConfig.setRequestTarget(path);
1397+
requestTarget = path;
13841398
}
13851399

13861400
Authorization authorization = new Authorization();
@@ -1395,41 +1409,38 @@ public class ApiClient {
13951409
}
13961410

13971411
logger.debug("HTTP Request Body:\n" + requestBody);
1398-
merchantConfig.setRequestData(requestBody);
1399-
authorization.setJWTRequestBody(requestBody);
1400-
boolean isMerchantDetails = merchantConfig.validateMerchantDetails();
1401-
1402-
merchantConfig.setRequestHost(merchantConfig.getRequestHost().trim());
1412+
boolean isMerchantDetails = merchantConfig.validateMerchantDetails(method);
14031413

14041414
if (isMerchantDetails
14051415
&& !merchantConfig.getAuthenticationType().equalsIgnoreCase(GlobalLabelParameters.MUTUALAUTH)) {
1406-
String token = authorization.getToken(merchantConfig);
1416+
String date = PropertiesUtil.getNewDate();
1417+
String token = authorization.getToken(merchantConfig, method, requestBody, requestTarget, date);
14071418
if (merchantConfig.getAuthenticationType().equalsIgnoreCase(GlobalLabelParameters.HTTP)) {
14081419
1409-
addDefaultHeader("Date", PropertiesUtil.date);
1410-
addDefaultHeader("Host", merchantConfig.getRequestHost().trim());
1411-
addDefaultHeader("v-c-merchant-id", merchantConfig.getMerchantID());
1412-
addDefaultHeader("Signature", token);
1413-
addDefaultHeader("User-Agent", "Mozilla/5.0");
1420+
requestHeaderMap.put("Date", date);
1421+
requestHeaderMap.put("Host", merchantConfig.getRequestHost().trim());
1422+
requestHeaderMap.put("v-c-merchant-id", merchantConfig.getMerchantID());
1423+
requestHeaderMap.put("Signature", token);
1424+
requestHeaderMap.put("User-Agent", "Mozilla/5.0");
14141425
14151426
if (method.equalsIgnoreCase("POST") || method.equalsIgnoreCase("PUT")
14161427
|| method.equalsIgnoreCase("PATCH")) {
1417-
PayloadDigest payloadDigest = new PayloadDigest(merchantConfig);
1428+
PayloadDigest payloadDigest = new PayloadDigest(requestBody);
14181429
String digest = payloadDigest.getDigest();
1419-
addDefaultHeader("Digest", digest);
1430+
requestHeaderMap.put("Digest", digest);
14201431
}
14211432

14221433
} else if (merchantConfig.getAuthenticationType().equalsIgnoreCase(GlobalLabelParameters.JWT)) {
14231434
token = "Bearer " + token;
1424-
addDefaultHeader("Authorization", token);
1435+
requestHeaderMap.put("Authorization", token);
14251436
} else if (merchantConfig.getAuthenticationType().equalsIgnoreCase(GlobalLabelParameters.OAUTH)) {
14261437
token = "Bearer " + token;
1427-
addDefaultHeader("Authorization", token);
1438+
requestHeaderMap.put("Authorization", token);
14281439
}
14291440
}
14301441

14311442
if (versionInfo != null && !versionInfo.isEmpty()) {
1432-
addDefaultHeader("v-c-client-id", "cybs-rest-sdk-java-" + versionInfo);
1443+
requestHeaderMap.put("v-c-client-id", "cybs-rest-sdk-java-" + versionInfo);
14331444
}
14341445

14351446
} catch (ConfigException e) {

generator/cybersource-java-template/libraries/okhttp-gson/ApiResponse.mustache

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,25 @@ public class ApiResponse<T> {
1414
final private int statusCode;
1515
final private Map<String, List<String>> headers;
1616
final private T data;
17+
final private String message;
1718
1819
/**
1920
* @param statusCode The status code of HTTP response
2021
* @param headers The headers of HTTP response
2122
*/
22-
public ApiResponse(int statusCode, Map<String, List<String>> headers) {
23-
this(statusCode, headers, null);
23+
public ApiResponse(int statusCode, Map<String, List<String>> headers, String message) {
24+
this(statusCode, headers, message, null);
2425
}
2526

2627
/**
2728
* @param statusCode The status code of HTTP response
2829
* @param headers The headers of HTTP response
2930
* @param data The object deserialized from response bod
3031
*/
31-
public ApiResponse(int statusCode, Map<String, List<String>> headers, T data) {
32+
public ApiResponse(int statusCode, Map<String, List<String>> headers, String message, T data) {
3233
this.statusCode = statusCode;
3334
this.headers = headers;
35+
this.message= message;
3436
this.data = data;
3537
}
3638

@@ -45,4 +47,8 @@ public class ApiResponse<T> {
4547
public T getData() {
4648
return data;
4749
}
50+
51+
public String getMessage() {
52+
return message;
53+
}
4854
}

generator/cybersource-java-template/libraries/okhttp-gson/api.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,6 @@ public class {{classname}} {
200200
*/
201201
public {{#returnType}}{{{returnType}}} {{/returnType}}{{^returnType}}void {{/returnType}}{{operationId}}({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) throws ApiException {
202202
logger.info("CALL TO METHOD '{{operationId}}' STARTED");
203-
this.apiClient.setComputationStartTime(System.nanoTime());
204203
{{#returnType}}ApiResponse<{{{returnType}}}> {{localVariablePrefix}}resp = {{/returnType}}{{operationId}}WithHttpInfo({{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}});
205204
{{#returnType}}
206205
logger.info("CALL TO METHOD '{{operationId}}' ENDED");
@@ -215,6 +214,7 @@ public class {{classname}} {
215214
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
216215
*/
217216
public ApiResponse<{{#vendorExtensions.x-streaming}}InputStream{{/vendorExtensions.x-streaming}}{{^vendorExtensions.x-streaming}}{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Void{{/returnType}}{{/vendorExtensions.x-streaming}}> {{operationId}}WithHttpInfo({{#allParams}}{{#useBeanValidation}}{{>beanValidationQueryParams}}{{/useBeanValidation}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) throws ApiException {
217+
this.apiClient.setComputationStartTime(System.nanoTime());
218218
okhttp3.Call {{localVariablePrefix}}call = {{operationId}}ValidateBeforeCall({{#allParams}}{{paramName}}, {{/allParams}}null, null);
219219
{{#returnType}}Type {{localVariablePrefix}}localVarReturnType = new TypeToken<{{{returnType}}}>(){}.getType();
220220
return {{localVariablePrefix}}apiClient.execute({{localVariablePrefix}}call, {{localVariablePrefix}}localVarReturnType);{{/returnType}}{{^returnType}}return {{localVariablePrefix}}apiClient.execute({{localVariablePrefix}}call);{{/returnType}}

src/main/java/Api/BatchesApi.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,6 @@ private okhttp3.Call getBatchReportValidateBeforeCall(String batchId, final Prog
159159
*/
160160
public InlineResponse2007 getBatchReport(String batchId) throws ApiException {
161161
logger.info("CALL TO METHOD 'getBatchReport' STARTED");
162-
this.apiClient.setComputationStartTime(System.nanoTime());
163162
ApiResponse<InlineResponse2007> resp = getBatchReportWithHttpInfo(batchId);
164163
logger.info("CALL TO METHOD 'getBatchReport' ENDED");
165164
return resp.getData();
@@ -173,6 +172,7 @@ public InlineResponse2007 getBatchReport(String batchId) throws ApiException {
173172
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
174173
*/
175174
public ApiResponse<InlineResponse2007> getBatchReportWithHttpInfo(String batchId) throws ApiException {
175+
this.apiClient.setComputationStartTime(System.nanoTime());
176176
okhttp3.Call call = getBatchReportValidateBeforeCall(batchId, null, null);
177177
Type localVarReturnType = new TypeToken<InlineResponse2007>(){}.getType();
178178
return apiClient.execute(call, localVarReturnType);
@@ -304,7 +304,6 @@ private okhttp3.Call getBatchStatusValidateBeforeCall(String batchId, final Prog
304304
*/
305305
public InlineResponse2006 getBatchStatus(String batchId) throws ApiException {
306306
logger.info("CALL TO METHOD 'getBatchStatus' STARTED");
307-
this.apiClient.setComputationStartTime(System.nanoTime());
308307
ApiResponse<InlineResponse2006> resp = getBatchStatusWithHttpInfo(batchId);
309308
logger.info("CALL TO METHOD 'getBatchStatus' ENDED");
310309
return resp.getData();
@@ -318,6 +317,7 @@ public InlineResponse2006 getBatchStatus(String batchId) throws ApiException {
318317
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
319318
*/
320319
public ApiResponse<InlineResponse2006> getBatchStatusWithHttpInfo(String batchId) throws ApiException {
320+
this.apiClient.setComputationStartTime(System.nanoTime());
321321
okhttp3.Call call = getBatchStatusValidateBeforeCall(batchId, null, null);
322322
Type localVarReturnType = new TypeToken<InlineResponse2006>(){}.getType();
323323
return apiClient.execute(call, localVarReturnType);
@@ -456,7 +456,6 @@ private okhttp3.Call getBatchesListValidateBeforeCall(Long offset, Long limit, S
456456
*/
457457
public InlineResponse2005 getBatchesList(Long offset, Long limit, String fromDate, String toDate) throws ApiException {
458458
logger.info("CALL TO METHOD 'getBatchesList' STARTED");
459-
this.apiClient.setComputationStartTime(System.nanoTime());
460459
ApiResponse<InlineResponse2005> resp = getBatchesListWithHttpInfo(offset, limit, fromDate, toDate);
461460
logger.info("CALL TO METHOD 'getBatchesList' ENDED");
462461
return resp.getData();
@@ -473,6 +472,7 @@ public InlineResponse2005 getBatchesList(Long offset, Long limit, String fromDat
473472
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
474473
*/
475474
public ApiResponse<InlineResponse2005> getBatchesListWithHttpInfo(Long offset, Long limit, String fromDate, String toDate) throws ApiException {
475+
this.apiClient.setComputationStartTime(System.nanoTime());
476476
okhttp3.Call call = getBatchesListValidateBeforeCall(offset, limit, fromDate, toDate, null, null);
477477
Type localVarReturnType = new TypeToken<InlineResponse2005>(){}.getType();
478478
return apiClient.execute(call, localVarReturnType);
@@ -603,7 +603,6 @@ private okhttp3.Call postBatchValidateBeforeCall(Body body, final ProgressRespon
603603
*/
604604
public InlineResponse202 postBatch(Body body) throws ApiException {
605605
logger.info("CALL TO METHOD 'postBatch' STARTED");
606-
this.apiClient.setComputationStartTime(System.nanoTime());
607606
ApiResponse<InlineResponse202> resp = postBatchWithHttpInfo(body);
608607
logger.info("CALL TO METHOD 'postBatch' ENDED");
609608
return resp.getData();
@@ -617,6 +616,7 @@ public InlineResponse202 postBatch(Body body) throws ApiException {
617616
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
618617
*/
619618
public ApiResponse<InlineResponse202> postBatchWithHttpInfo(Body body) throws ApiException {
619+
this.apiClient.setComputationStartTime(System.nanoTime());
620620
okhttp3.Call call = postBatchValidateBeforeCall(body, null, null);
621621
Type localVarReturnType = new TypeToken<InlineResponse202>(){}.getType();
622622
return apiClient.execute(call, localVarReturnType);

src/main/java/Api/BillingAgreementsApi.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,6 @@ private okhttp3.Call billingAgreementsDeRegistrationValidateBeforeCall(ModifyBil
166166
*/
167167
public PtsV2ModifyBillingAgreementPost201Response billingAgreementsDeRegistration(ModifyBillingAgreement modifyBillingAgreement, String id) throws ApiException {
168168
logger.info("CALL TO METHOD 'billingAgreementsDeRegistration' STARTED");
169-
this.apiClient.setComputationStartTime(System.nanoTime());
170169
ApiResponse<PtsV2ModifyBillingAgreementPost201Response> resp = billingAgreementsDeRegistrationWithHttpInfo(modifyBillingAgreement, id);
171170
logger.info("CALL TO METHOD 'billingAgreementsDeRegistration' ENDED");
172171
return resp.getData();
@@ -181,6 +180,7 @@ public PtsV2ModifyBillingAgreementPost201Response billingAgreementsDeRegistratio
181180
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
182181
*/
183182
public ApiResponse<PtsV2ModifyBillingAgreementPost201Response> billingAgreementsDeRegistrationWithHttpInfo(ModifyBillingAgreement modifyBillingAgreement, String id) throws ApiException {
183+
this.apiClient.setComputationStartTime(System.nanoTime());
184184
okhttp3.Call call = billingAgreementsDeRegistrationValidateBeforeCall(modifyBillingAgreement, id, null, null);
185185
Type localVarReturnType = new TypeToken<PtsV2ModifyBillingAgreementPost201Response>(){}.getType();
186186
return apiClient.execute(call, localVarReturnType);
@@ -318,7 +318,6 @@ private okhttp3.Call billingAgreementsIntimationValidateBeforeCall(IntimateBilli
318318
*/
319319
public PtsV2CreditsPost201Response1 billingAgreementsIntimation(IntimateBillingAgreement intimateBillingAgreement, String id) throws ApiException {
320320
logger.info("CALL TO METHOD 'billingAgreementsIntimation' STARTED");
321-
this.apiClient.setComputationStartTime(System.nanoTime());
322321
ApiResponse<PtsV2CreditsPost201Response1> resp = billingAgreementsIntimationWithHttpInfo(intimateBillingAgreement, id);
323322
logger.info("CALL TO METHOD 'billingAgreementsIntimation' ENDED");
324323
return resp.getData();
@@ -333,6 +332,7 @@ public PtsV2CreditsPost201Response1 billingAgreementsIntimation(IntimateBillingA
333332
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
334333
*/
335334
public ApiResponse<PtsV2CreditsPost201Response1> billingAgreementsIntimationWithHttpInfo(IntimateBillingAgreement intimateBillingAgreement, String id) throws ApiException {
335+
this.apiClient.setComputationStartTime(System.nanoTime());
336336
okhttp3.Call call = billingAgreementsIntimationValidateBeforeCall(intimateBillingAgreement, id, null, null);
337337
Type localVarReturnType = new TypeToken<PtsV2CreditsPost201Response1>(){}.getType();
338338
return apiClient.execute(call, localVarReturnType);
@@ -461,7 +461,6 @@ private okhttp3.Call billingAgreementsRegistrationValidateBeforeCall(CreateBilli
461461
*/
462462
public PtsV2CreateBillingAgreementPost201Response billingAgreementsRegistration(CreateBillingAgreement createBillingAgreement) throws ApiException {
463463
logger.info("CALL TO METHOD 'billingAgreementsRegistration' STARTED");
464-
this.apiClient.setComputationStartTime(System.nanoTime());
465464
ApiResponse<PtsV2CreateBillingAgreementPost201Response> resp = billingAgreementsRegistrationWithHttpInfo(createBillingAgreement);
466465
logger.info("CALL TO METHOD 'billingAgreementsRegistration' ENDED");
467466
return resp.getData();
@@ -475,6 +474,7 @@ public PtsV2CreateBillingAgreementPost201Response billingAgreementsRegistration(
475474
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
476475
*/
477476
public ApiResponse<PtsV2CreateBillingAgreementPost201Response> billingAgreementsRegistrationWithHttpInfo(CreateBillingAgreement createBillingAgreement) throws ApiException {
477+
this.apiClient.setComputationStartTime(System.nanoTime());
478478
okhttp3.Call call = billingAgreementsRegistrationValidateBeforeCall(createBillingAgreement, null, null);
479479
Type localVarReturnType = new TypeToken<PtsV2CreateBillingAgreementPost201Response>(){}.getType();
480480
return apiClient.execute(call, localVarReturnType);

src/main/java/Api/BinLookupApi.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,6 @@ private okhttp3.Call getAccountInfoValidateBeforeCall(CreateBinLookupRequest cre
154154
*/
155155
public InlineResponse2011 getAccountInfo(CreateBinLookupRequest createBinLookupRequest) throws ApiException {
156156
logger.info("CALL TO METHOD 'getAccountInfo' STARTED");
157-
this.apiClient.setComputationStartTime(System.nanoTime());
158157
ApiResponse<InlineResponse2011> resp = getAccountInfoWithHttpInfo(createBinLookupRequest);
159158
logger.info("CALL TO METHOD 'getAccountInfo' ENDED");
160159
return resp.getData();
@@ -168,6 +167,7 @@ public InlineResponse2011 getAccountInfo(CreateBinLookupRequest createBinLookupR
168167
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
169168
*/
170169
public ApiResponse<InlineResponse2011> getAccountInfoWithHttpInfo(CreateBinLookupRequest createBinLookupRequest) throws ApiException {
170+
this.apiClient.setComputationStartTime(System.nanoTime());
171171
okhttp3.Call call = getAccountInfoValidateBeforeCall(createBinLookupRequest, null, null);
172172
Type localVarReturnType = new TypeToken<InlineResponse2011>(){}.getType();
173173
return apiClient.execute(call, localVarReturnType);

0 commit comments

Comments
 (0)