Skip to content

Commit 8d2a23e

Browse files
committed
Intermediate host updates
1 parent 65893eb commit 8d2a23e

File tree

3 files changed

+25
-7
lines changed

3 files changed

+25
-7
lines changed

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import javax.net.ssl.*;
4444
import com.google.gson.Gson;
4545
import com.google.gson.reflect.TypeToken;
4646

47+
import org.apache.commons.lang.StringUtils;
4748
import org.apache.logging.log4j.LogManager;
4849
import org.apache.logging.log4j.Logger;
4950

@@ -734,7 +735,7 @@ public class ApiClient {
734735
* @return ApiClient
735736
*/
736737
public ApiClient addDefaultHeader(String key, String value) {
737-
defaultHeaderMap.put(key, value);
738+
defaultHeaderMap.put(key, value);
738739
return this;
739740
}
740741

@@ -1337,7 +1338,11 @@ public class ApiClient {
13371338
headerParams.put("Accept", defaultAcceptHeader);
13381339
}
13391340

1340-
headerParams.putAll(defaultHeaderMap);
1341+
for (Entry<String, String> header : defaultHeaderMap.entrySet()) {
1342+
if (!headerParams.containsKey(header.getKey())) {
1343+
headerParams.put(header.getKey(), header.getValue());
1344+
}
1345+
}
13411346
logger.info("Request Header Parameters:\n{}", new PrettyPrintingMap<String, String>(headerParams));
13421347
Request request = buildRequest(path, method, queryParams, body, headerParams, formParams, authNames,
13431348
progressRequestListener);
@@ -1502,7 +1507,11 @@ public class ApiClient {
15021507
*/
15031508
public String buildUrl(String path, List<Pair> queryParams) {
15041509
final StringBuilder url = new StringBuilder();
1505-
url.append(GlobalLabelParameters.URL_PREFIX).append(merchantConfig.getRequestHost().trim()).append(path);
1510+
if(StringUtils.isNotBlank(merchantConfig.getIntermediateHost())) {
1511+
url.append(GlobalLabelParameters.URL_PREFIX).append(merchantConfig.getIntermediateHost().trim()).append(path);
1512+
} else {
1513+
url.append(GlobalLabelParameters.URL_PREFIX).append(merchantConfig.getRequestHost().trim()).append(path);
1514+
}
15061515

15071516
if (queryParams != null && !queryParams.isEmpty()) {
15081517
// support (constant) query string in `path`, e.g. "/posts?draft=1"

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

src/main/java/Invokers/ApiClient.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import com.google.gson.Gson;
4545
import com.google.gson.reflect.TypeToken;
4646

47+
import org.apache.commons.lang.StringUtils;
4748
import org.apache.logging.log4j.LogManager;
4849
import org.apache.logging.log4j.Logger;
4950

@@ -734,7 +735,7 @@ public ApiClient setUserAgent(String userAgent) {
734735
* @return ApiClient
735736
*/
736737
public ApiClient addDefaultHeader(String key, String value) {
737-
defaultHeaderMap.put(key, value);
738+
defaultHeaderMap.put(key, value);
738739
return this;
739740
}
740741

@@ -1337,7 +1338,11 @@ public Call buildCall(String path, String method, List<Pair> queryParams, Object
13371338
headerParams.put("Accept", defaultAcceptHeader);
13381339
}
13391340

1340-
headerParams.putAll(defaultHeaderMap);
1341+
for (Entry<String, String> header : defaultHeaderMap.entrySet()) {
1342+
if (!headerParams.containsKey(header.getKey())) {
1343+
headerParams.put(header.getKey(), header.getValue());
1344+
}
1345+
}
13411346
logger.info("Request Header Parameters:\n{}", new PrettyPrintingMap<String, String>(headerParams));
13421347
Request request = buildRequest(path, method, queryParams, body, headerParams, formParams, authNames,
13431348
progressRequestListener);
@@ -1502,7 +1507,11 @@ public Request buildRequest(String path, String method, List<Pair> queryParams,
15021507
*/
15031508
public String buildUrl(String path, List<Pair> queryParams) {
15041509
final StringBuilder url = new StringBuilder();
1505-
url.append(GlobalLabelParameters.URL_PREFIX).append(merchantConfig.getRequestHost().trim()).append(path);
1510+
if(StringUtils.isNotBlank(merchantConfig.getIntermediateHost())) {
1511+
url.append(GlobalLabelParameters.URL_PREFIX).append(merchantConfig.getIntermediateHost().trim()).append(path);
1512+
} else {
1513+
url.append(GlobalLabelParameters.URL_PREFIX).append(merchantConfig.getRequestHost().trim()).append(path);
1514+
}
15061515

15071516
if (queryParams != null && !queryParams.isEmpty()) {
15081517
// support (constant) query string in `path`, e.g. "/posts?draft=1"

0 commit comments

Comments
 (0)