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