@@ -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) {
0 commit comments