Skip to content

Commit 99da304

Browse files
committed
+ Feedback Changes
1 parent 641bb58 commit 99da304

File tree

2 files changed

+37
-25
lines changed

2 files changed

+37
-25
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ import java.util.concurrent.TimeUnit;
4141
import java.util.regex.Matcher;
4242
import java.util.regex.Pattern;
4343
import javax.net.ssl.*;
44+
import com.cybersource.authsdk.util.Utility;
4445
import com.google.gson.Gson;
46+
import com.google.gson.reflect.TypeToken;
4547
import org.apache.logging.log4j.Logger;
4648
import com.cybersource.authsdk.core.Authorization;
4749
import com.cybersource.authsdk.core.ConfigException;
@@ -1164,6 +1166,10 @@ public class ApiClient {
11641166
responseCode = String.valueOf(response.code());
11651167
status = response.message();
11661168
1169+
if(returnType == new TypeToken< Model.AccessTokenResponse >(){}.getType()) {
1170+
Logger logger = Log4j.getInstance(merchantConfig);
1171+
Utility.log(logger, response.peekBody(Long.MAX_VALUE).string(), org.apache.logging.log4j.Level.DEBUG);
1172+
}
11671173
T data = handleResponse(response, returnType);
11681174

11691175
return new ApiResponse<T>(response.code(), response.headers().toMultimap(), data);
@@ -1355,7 +1361,7 @@ public class ApiClient {
13551361

13561362
merchantConfig.setRequestHost(merchantConfig.getRequestHost().trim());
13571363

1358-
if (isMerchantDetails && !merchantConfig.getAuthenticationType().equalsIgnoreCase(GlobalLabelParameters.NOAUTH)) {
1364+
if (isMerchantDetails && !merchantConfig.getAuthenticationType().equalsIgnoreCase(GlobalLabelParameters.MUTUALAUTH)) {
13591365
String token = authorization.getToken(merchantConfig);
13601366
if (merchantConfig.getAuthenticationType().equalsIgnoreCase(GlobalLabelParameters.HTTP)) {
13611367

src/main/java/Invokers/ApiClient.java

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@
4141
import java.util.regex.Matcher;
4242
import java.util.regex.Pattern;
4343
import javax.net.ssl.*;
44+
import com.cybersource.authsdk.util.Utility;
4445
import com.google.gson.Gson;
46+
import com.google.gson.reflect.TypeToken;
4547
import org.apache.logging.log4j.Logger;
4648
import com.cybersource.authsdk.core.Authorization;
4749
import com.cybersource.authsdk.core.ConfigException;
@@ -1164,6 +1166,10 @@ public <T> ApiResponse<T> execute(Call call, Type returnType) throws ApiExceptio
11641166
responseCode = String.valueOf(response.code());
11651167
status = response.message();
11661168

1169+
if(returnType == new TypeToken< Model.AccessTokenResponse >(){}.getType()) {
1170+
Logger logger = Log4j.getInstance(merchantConfig);
1171+
Utility.log(logger, response.peekBody(Long.MAX_VALUE).string(), org.apache.logging.log4j.Level.DEBUG);
1172+
}
11671173
T data = handleResponse(response, returnType);
11681174

11691175
return new ApiResponse<T>(response.code(), response.headers().toMultimap(), data);
@@ -1355,33 +1361,33 @@ public void callAuthenticationHeader(String method, String path, Object body, Li
13551361

13561362
merchantConfig.setRequestHost(merchantConfig.getRequestHost().trim());
13571363

1358-
if (isMerchantDetails && !merchantConfig.getAuthenticationType().equalsIgnoreCase(GlobalLabelParameters.NOAUTH)) {
1359-
String token = authorization.getToken(merchantConfig);
1360-
if (merchantConfig.getAuthenticationType().equalsIgnoreCase(GlobalLabelParameters.HTTP)) {
13611364

1362-
addDefaultHeader("Date", PropertiesUtil.date);
1363-
addDefaultHeader("Host", merchantConfig.getRequestHost().trim());
1364-
addDefaultHeader("v-c-merchant-id", merchantConfig.getMerchantID());
1365-
addDefaultHeader("Signature", token);
1366-
addDefaultHeader("User-Agent", "Mozilla/5.0");
1367-
1368-
if (method.equalsIgnoreCase("POST") || method.equalsIgnoreCase("PUT")
1369-
|| method.equalsIgnoreCase("PATCH")) {
1370-
PayloadDigest payloadDigest = new PayloadDigest(merchantConfig);
1371-
String digest = payloadDigest.getDigest();
1372-
addDefaultHeader("Digest", digest);
1373-
}
1365+
if (isMerchantDetails && !merchantConfig.getAuthenticationType().equalsIgnoreCase(GlobalLabelParameters.MUTUALAUTH)) {
1366+
String token = authorization.getToken(merchantConfig);
1367+
if (merchantConfig.getAuthenticationType().equalsIgnoreCase(GlobalLabelParameters.HTTP)) {
13741368

1375-
} else if (merchantConfig.getAuthenticationType().equalsIgnoreCase(GlobalLabelParameters.JWT)) {
1376-
token = "Bearer " + token;
1377-
addDefaultHeader("Authorization", token);
1378-
}
1379-
else if(merchantConfig.getAuthenticationType().equalsIgnoreCase(GlobalLabelParameters.OAUTH))
1380-
{
1381-
token = "Bearer " + token;
1382-
addDefaultHeader("Authorization", token);
1369+
addDefaultHeader("Date", PropertiesUtil.date);
1370+
addDefaultHeader("Host", merchantConfig.getRequestHost().trim());
1371+
addDefaultHeader("v-c-merchant-id", merchantConfig.getMerchantID());
1372+
addDefaultHeader("Signature", token);
1373+
addDefaultHeader("User-Agent", "Mozilla/5.0");
1374+
1375+
if (method.equalsIgnoreCase("POST") || method.equalsIgnoreCase("PUT")
1376+
|| method.equalsIgnoreCase("PATCH")) {
1377+
PayloadDigest payloadDigest = new PayloadDigest(merchantConfig);
1378+
String digest = payloadDigest.getDigest();
1379+
addDefaultHeader("Digest", digest);
1380+
}
1381+
1382+
} else if (merchantConfig.getAuthenticationType().equalsIgnoreCase(GlobalLabelParameters.JWT)) {
1383+
token = "Bearer " + token;
1384+
addDefaultHeader("Authorization", token);
1385+
}
1386+
else if (merchantConfig.getAuthenticationType().equalsIgnoreCase(GlobalLabelParameters.OAUTH)) {
1387+
token = "Bearer " + token;
1388+
addDefaultHeader("Authorization", token);
1389+
}
13831390
}
1384-
}
13851391

13861392
if (versionInfo != null && !versionInfo.isEmpty()) {
13871393
addDefaultHeader("v-c-client-id", "cybs-rest-sdk-java-" + versionInfo);

0 commit comments

Comments
 (0)