Skip to content

Commit ac49b8a

Browse files
committed
intermediate host updates
1 parent 8d2a23e commit ac49b8a

File tree

3 files changed

+44
-19
lines changed

3 files changed

+44
-19
lines changed

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

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,9 @@ public class ApiClient {
735735
* @return ApiClient
736736
*/
737737
public ApiClient addDefaultHeader(String key, String value) {
738-
defaultHeaderMap.put(key, value);
738+
if (!defaultHeaderMap.containsKey(key)) {
739+
defaultHeaderMap.put(key, value);
740+
}
739741
return this;
740742
}
741743

@@ -1325,6 +1327,13 @@ public class ApiClient {
13251327
public Call buildCall(String path, String method, List<Pair> queryParams, Object body,
13261328
Map<String, String> headerParams, Map<String, Object> formParams, String[] authNames,
13271329
ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
1330+
1331+
if(merchantConfig.getDefaultHeaders() != null && !merchantConfig.getDefaultHeaders().isEmpty()) {
1332+
for (Entry<String, String> header : merchantConfig.getDefaultHeaders().entrySet()) {
1333+
addDefaultHeader(header.getKey(), header.getValue());
1334+
}
1335+
}
1336+
13281337
callAuthenticationHeader(method, path, body, queryParams);
13291338

13301339
if (merchantConfig.isEnableClientCert()) {
@@ -1337,12 +1346,10 @@ public class ApiClient {
13371346
headerParams.remove("Accept");
13381347
headerParams.put("Accept", defaultAcceptHeader);
13391348
}
1349+
1350+
headerParams.putAll(defaultHeaderMap);
13401351

1341-
for (Entry<String, String> header : defaultHeaderMap.entrySet()) {
1342-
if (!headerParams.containsKey(header.getKey())) {
1343-
headerParams.put(header.getKey(), header.getValue());
1344-
}
1345-
}
1352+
13461353
logger.info("Request Header Parameters:\n{}", new PrettyPrintingMap<String, String>(headerParams));
13471354
Request request = buildRequest(path, method, queryParams, body, headerParams, formParams, authNames,
13481355
progressRequestListener);
@@ -1507,12 +1514,18 @@ public class ApiClient {
15071514
*/
15081515
public String buildUrl(String path, List<Pair> queryParams) {
15091516
final StringBuilder url = new StringBuilder();
1510-
if(StringUtils.isNotBlank(merchantConfig.getIntermediateHost())) {
1511-
url.append(GlobalLabelParameters.URL_PREFIX).append(merchantConfig.getIntermediateHost().trim()).append(path);
1517+
if (StringUtils.isNotBlank(merchantConfig.getIntermediateHost())) {
1518+
if (merchantConfig.getIntermediateHost().startsWith(GlobalLabelParameters.URL_PREFIX)
1519+
|| merchantConfig.getIntermediateHost().startsWith("http://")) {
1520+
url.append(merchantConfig.getIntermediateHost().trim()).append(path);
1521+
} else {
1522+
url.append(GlobalLabelParameters.URL_PREFIX).append(merchantConfig.getIntermediateHost().trim())
1523+
.append(path);
1524+
}
15121525
} else {
15131526
url.append(GlobalLabelParameters.URL_PREFIX).append(merchantConfig.getRequestHost().trim()).append(path);
15141527
}
1515-
1528+
15161529
if (queryParams != null && !queryParams.isEmpty()) {
15171530
// support (constant) query string in `path`, e.g. "/posts?draft=1"
15181531
String prefix = path.contains("?") ? "&" : "?";

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public class {{classname}} {
9393
if ({{paramName}} != null)
9494
{{localVariablePrefix}}localVarQueryParams.addAll({{localVariablePrefix}}apiClient.parameterToPairs("{{#collectionFormat}}{{{collectionFormat}}}{{/collectionFormat}}", "{{baseName}}", {{paramName}}));{{/queryParams}}
9595

96-
{{javaUtilPrefix}}Map<String, String> {{localVariablePrefix}}localVarHeaderParams = new {{javaUtilPrefix}}HashMap<String, String>(apiClient.merchantConfig.getDefaultHeaders());{{#headerParams}}
96+
{{javaUtilPrefix}}Map<String, String> {{localVariablePrefix}}localVarHeaderParams = new {{javaUtilPrefix}}HashMap<String, String>();{{#headerParams}}
9797
if ({{paramName}} != null)
9898
{{localVariablePrefix}}localVarHeaderParams.put("{{baseName}}", {{localVariablePrefix}}apiClient.parameterToString({{paramName}}));{{/headerParams}}
9999

src/main/java/Invokers/ApiClient.java

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,9 @@ public ApiClient setUserAgent(String userAgent) {
735735
* @return ApiClient
736736
*/
737737
public ApiClient addDefaultHeader(String key, String value) {
738-
defaultHeaderMap.put(key, value);
738+
if (!defaultHeaderMap.containsKey(key)) {
739+
defaultHeaderMap.put(key, value);
740+
}
739741
return this;
740742
}
741743

@@ -1324,7 +1326,14 @@ public <T> T handleResponse(Response response, Type returnType) throws ApiExcept
13241326
*/
13251327
public Call buildCall(String path, String method, List<Pair> queryParams, Object body,
13261328
Map<String, String> headerParams, Map<String, Object> formParams, String[] authNames,
1327-
ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
1329+
ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
1330+
1331+
if(merchantConfig.getDefaultHeaders() != null && !merchantConfig.getDefaultHeaders().isEmpty()) {
1332+
for (Entry<String, String> header : merchantConfig.getDefaultHeaders().entrySet()) {
1333+
addDefaultHeader(header.getKey(), header.getValue());
1334+
}
1335+
}
1336+
13281337
callAuthenticationHeader(method, path, body, queryParams);
13291338

13301339
if (merchantConfig.isEnableClientCert()) {
@@ -1338,11 +1347,8 @@ public Call buildCall(String path, String method, List<Pair> queryParams, Object
13381347
headerParams.put("Accept", defaultAcceptHeader);
13391348
}
13401349

1341-
for (Entry<String, String> header : defaultHeaderMap.entrySet()) {
1342-
if (!headerParams.containsKey(header.getKey())) {
1343-
headerParams.put(header.getKey(), header.getValue());
1344-
}
1345-
}
1350+
headerParams.putAll(defaultHeaderMap);
1351+
13461352
logger.info("Request Header Parameters:\n{}", new PrettyPrintingMap<String, String>(headerParams));
13471353
Request request = buildRequest(path, method, queryParams, body, headerParams, formParams, authNames,
13481354
progressRequestListener);
@@ -1507,8 +1513,14 @@ public Request buildRequest(String path, String method, List<Pair> queryParams,
15071513
*/
15081514
public String buildUrl(String path, List<Pair> queryParams) {
15091515
final StringBuilder url = new StringBuilder();
1510-
if(StringUtils.isNotBlank(merchantConfig.getIntermediateHost())) {
1511-
url.append(GlobalLabelParameters.URL_PREFIX).append(merchantConfig.getIntermediateHost().trim()).append(path);
1516+
if (StringUtils.isNotBlank(merchantConfig.getIntermediateHost())) {
1517+
if (merchantConfig.getIntermediateHost().startsWith(GlobalLabelParameters.URL_PREFIX)
1518+
|| merchantConfig.getIntermediateHost().startsWith("http://")) {
1519+
url.append(merchantConfig.getIntermediateHost().trim()).append(path);
1520+
} else {
1521+
url.append(GlobalLabelParameters.URL_PREFIX).append(merchantConfig.getIntermediateHost().trim())
1522+
.append(path);
1523+
}
15121524
} else {
15131525
url.append(GlobalLabelParameters.URL_PREFIX).append(merchantConfig.getRequestHost().trim()).append(path);
15141526
}

0 commit comments

Comments
 (0)