Skip to content

Commit 7ff2834

Browse files
committed
added fixApiClient changes in mustache file
1 parent 9dac5d4 commit 7ff2834

File tree

2 files changed

+37
-38
lines changed

2 files changed

+37
-38
lines changed

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

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,6 @@ public class ApiClient {
144144

145145
public String responseCode;
146146
public String status;
147-
public InputStream responseBody;
148-
public String respBody;
149147
public MerchantConfig merchantConfig;
150148
public RequestTransactionMetrics apiRequestMetrics = new RequestTransactionMetrics();
151149

@@ -1036,6 +1034,8 @@ public class ApiClient {
10361034
return (T) downloadFileFromResponse(response);
10371035
}
10381036

1037+
String respBody = null;
1038+
10391039
try {
10401040
if (response.body() != null)
10411041
respBody = response.body().string();
@@ -1191,8 +1191,9 @@ public class ApiClient {
11911191
try {
11921192
this.apiRequestMetrics.setComputeTime((System.nanoTime() - this.getComputationStartTime()) / 1000000);
11931193
Response response = call.execute();
1194-
responseCode = String.valueOf(response.code());
1195-
status = response.message();
1194+
String responseCode = String.valueOf(response.code());
1195+
this.status = response.message();
1196+
this.responseCode= responseCode;
11961197
11971198
logger.debug("Network Response :\n" + json.serialize(response.headers()));
11981199
@@ -1317,16 +1318,19 @@ public class ApiClient {
13171318
public Call buildCall(String path, String method, List<Pair> queryParams, Object body,
13181319
Map<String, String> headerParams, Map<String, Object> formParams, String[] authNames,
13191320
ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
1320-
1321+
1322+
//create reqHeader parameter here
1323+
Map<String, String> requestHeaderMap = new HashMap<String, String>();
1324+
13211325
if(merchantConfig.getDefaultHeaders() != null && !merchantConfig.getDefaultHeaders().isEmpty()) {
13221326
for (Entry<String, String> header : merchantConfig.getDefaultHeaders().entrySet()) {
13231327
if(!header.getKey().equalsIgnoreCase("Authorization") && !header.getKey().equalsIgnoreCase("Signature")){
1324-
addDefaultHeader(header.getKey(), header.getValue());
1328+
requestHeaderMap.put(header.getKey(), header.getValue());
13251329
}
13261330
}
13271331
}
13281332

1329-
callAuthenticationHeader(method, path, body, queryParams);
1333+
callAuthenticationHeader(method, path, body, queryParams, requestHeaderMap);
13301334

13311335
if (merchantConfig.isEnableClientCert()) {
13321336
addClientCertToKeyStore();
@@ -1339,7 +1343,7 @@ public class ApiClient {
13391343
headerParams.put("Accept", defaultAcceptHeader);
13401344
}
13411345

1342-
headerParams.putAll(defaultHeaderMap);
1346+
headerParams.putAll(requestHeaderMap);
13431347

13441348

13451349
logger.info("Request Header Parameters:\n{}", new PrettyPrintingMap<String, String>(headerParams));
@@ -1353,10 +1357,10 @@ public class ApiClient {
13531357
*
13541358
*/
13551359

1356-
public void callAuthenticationHeader(String method, String path, Object body, List<Pair> queryParams) {
1360+
public void callAuthenticationHeader(String method, String path, Object body, List<Pair> queryParams, Map<String, String> requestHeaderMap) {
13571361
13581362
try {
1359-
merchantConfig.setRequestType(method);
1363+
String requestTarget = null;
13601364
13611365
if (queryParams != null && !queryParams.isEmpty()) {
13621366
StringBuilder url = new StringBuilder();
@@ -1377,10 +1381,10 @@ public class ApiClient {
13771381
url.append(escapeString(param.getName())).append("=").append(escapeString(value));
13781382
}
13791383
}
1380-
merchantConfig.setRequestTarget(url.toString());
1384+
requestTarget= url.toString();
13811385
}
13821386
} else {
1383-
merchantConfig.setRequestTarget(path);
1387+
requestTarget =path;
13841388
}
13851389

13861390
Authorization authorization = new Authorization();
@@ -1395,41 +1399,38 @@ public class ApiClient {
13951399
}
13961400

13971401
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());
1402+
boolean isMerchantDetails = merchantConfig.validateMerchantDetails(method);
14031403

14041404
if (isMerchantDetails
14051405
&& !merchantConfig.getAuthenticationType().equalsIgnoreCase(GlobalLabelParameters.MUTUALAUTH)) {
1406-
String token = authorization.getToken(merchantConfig);
1406+
String date = PropertiesUtil.getNewDate();
1407+
String token = authorization.getToken(merchantConfig, method, requestBody, requestTarget, date);
14071408
if (merchantConfig.getAuthenticationType().equalsIgnoreCase(GlobalLabelParameters.HTTP)) {
14081409
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");
1410+
requestHeaderMap.put("Date", date);
1411+
requestHeaderMap.put("Host", merchantConfig.getRequestHost().trim());
1412+
requestHeaderMap.put("v-c-merchant-id", merchantConfig.getMerchantID());
1413+
requestHeaderMap.put("Signature", token);
1414+
requestHeaderMap.put("User-Agent", "Mozilla/5.0");
14141415
14151416
if (method.equalsIgnoreCase("POST") || method.equalsIgnoreCase("PUT")
14161417
|| method.equalsIgnoreCase("PATCH")) {
1417-
PayloadDigest payloadDigest = new PayloadDigest(merchantConfig);
1418+
PayloadDigest payloadDigest = new PayloadDigest(requestBody);
14181419
String digest = payloadDigest.getDigest();
1419-
addDefaultHeader("Digest", digest);
1420+
requestHeaderMap.put("Digest", digest);
14201421
}
14211422

14221423
} else if (merchantConfig.getAuthenticationType().equalsIgnoreCase(GlobalLabelParameters.JWT)) {
14231424
token = "Bearer " + token;
1424-
addDefaultHeader("Authorization", token);
1425+
requestHeaderMap.put("Authorization", token);
14251426
} else if (merchantConfig.getAuthenticationType().equalsIgnoreCase(GlobalLabelParameters.OAUTH)) {
14261427
token = "Bearer " + token;
1427-
addDefaultHeader("Authorization", token);
1428+
requestHeaderMap.put("Authorization", token);
14281429
}
14291430
}
14301431

14311432
if (versionInfo != null && !versionInfo.isEmpty()) {
1432-
addDefaultHeader("v-c-client-id", "cybs-rest-sdk-java-" + versionInfo);
1433+
requestHeaderMap.put("v-c-client-id", "cybs-rest-sdk-java-" + versionInfo);
14331434
}
14341435

14351436
} catch (ConfigException e) {

src/main/java/Invokers/ApiClient.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,9 +1033,9 @@ public <T> T deserialize(Response response, Type returnType) throws ApiException
10331033
// Handle file downloading.
10341034
return (T) downloadFileFromResponse(response);
10351035
}
1036-
1036+
10371037
String respBody = null;
1038-
1038+
10391039
try {
10401040
if (response.body() != null)
10411041
respBody = response.body().string();
@@ -1318,19 +1318,19 @@ public <T> T handleResponse(Response response, Type returnType) throws ApiExcept
13181318
public Call buildCall(String path, String method, List<Pair> queryParams, Object body,
13191319
Map<String, String> headerParams, Map<String, Object> formParams, String[] authNames,
13201320
ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
1321-
1321+
13221322
//create reqHeader parameter here
13231323
Map<String, String> requestHeaderMap = new HashMap<String, String>();
1324-
1324+
13251325
if(merchantConfig.getDefaultHeaders() != null && !merchantConfig.getDefaultHeaders().isEmpty()) {
13261326
for (Entry<String, String> header : merchantConfig.getDefaultHeaders().entrySet()) {
13271327
if(!header.getKey().equalsIgnoreCase("Authorization") && !header.getKey().equalsIgnoreCase("Signature")){
1328-
requestHeaderMap.put(header.getKey(), header.getValue());
1328+
requestHeaderMap.put(header.getKey(), header.getValue());
13291329
}
13301330
}
13311331
}
13321332

1333-
callAuthenticationHeader(method, path, body, queryParams,requestHeaderMap);
1333+
callAuthenticationHeader(method, path, body, queryParams, requestHeaderMap);
13341334

13351335
if (merchantConfig.isEnableClientCert()) {
13361336
addClientCertToKeyStore();
@@ -1347,7 +1347,6 @@ public Call buildCall(String path, String method, List<Pair> queryParams, Object
13471347

13481348

13491349
logger.info("Request Header Parameters:\n{}", new PrettyPrintingMap<String, String>(headerParams));
1350-
//till here completed
13511350
Request request = buildRequest(path, method, queryParams, body, headerParams, formParams, authNames,
13521351
progressRequestListener);
13531352
return httpClient.newCall(request);
@@ -1407,6 +1406,7 @@ public void callAuthenticationHeader(String method, String path, Object body, Li
14071406
String date = PropertiesUtil.getNewDate();
14081407
String token = authorization.getToken(merchantConfig, method, requestBody, requestTarget, date);
14091408
if (merchantConfig.getAuthenticationType().equalsIgnoreCase(GlobalLabelParameters.HTTP)) {
1409+
14101410
requestHeaderMap.put("Date", date);
14111411
requestHeaderMap.put("Host", merchantConfig.getRequestHost().trim());
14121412
requestHeaderMap.put("v-c-merchant-id", merchantConfig.getMerchantID());
@@ -1435,11 +1435,9 @@ public void callAuthenticationHeader(String method, String path, Object body, Li
14351435

14361436
} catch (ConfigException e) {
14371437
logger.error(e.getMessage());
1438-
} catch (NullPointerException e){
1439-
logger.error(e);
14401438
}
14411439

1442-
}
1440+
}
14431441

14441442
/**
14451443
* Build an HTTP request with the given options.

0 commit comments

Comments
 (0)