@@ -44,6 +44,7 @@ import javax.net.ssl.*;
4444import com.google.gson.Gson;
4545import com.google.gson.reflect.TypeToken;
4646
47+ import org.apache.commons.lang.StringUtils;
4748import org.apache.logging.log4j.LogManager;
4849import org.apache.logging.log4j.Logger;
4950
@@ -734,7 +735,9 @@ public class ApiClient {
734735 * @return ApiClient
735736 */
736737 public ApiClient addDefaultHeader(String key, String value) {
737- defaultHeaderMap.put(key, value);
738+ if (! defaultHeaderMap.containsKey(key)) {
739+ defaultHeaderMap.put(key, value);
740+ }
738741 return this;
739742 }
740743
@@ -1324,6 +1327,13 @@ public class ApiClient {
13241327 public Call buildCall(String path, String method, List<Pair > queryParams, Object body,
13251328 Map<String , String > headerParams, Map<String , Object > formParams, String[] authNames,
13261329 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+
13271337 callAuthenticationHeader(method, path, body, queryParams);
13281338
13291339 if (merchantConfig.isEnableClientCert()) {
@@ -1336,8 +1346,10 @@ public class ApiClient {
13361346 headerParams.remove(" Accept" );
13371347 headerParams.put(" Accept" , defaultAcceptHeader);
13381348 }
1339-
1349+
13401350 headerParams.putAll(defaultHeaderMap);
1351+
1352+
13411353 logger.info("Request Header Parameters:\n{ } ", new PrettyPrintingMap<String , String >(headerParams));
13421354 Request request = buildRequest(path, method, queryParams, body, headerParams, formParams, authNames,
13431355 progressRequestListener);
@@ -1502,8 +1514,18 @@ public class ApiClient {
15021514 */
15031515 public String buildUrl(String path, List<Pair > queryParams) {
15041516 final StringBuilder url = new StringBuilder();
1505- url.append(GlobalLabelParameters.URL_PREFIX).append(merchantConfig.getRequestHost().trim()).append(path);
1506-
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+ }
1525+ } else {
1526+ url.append(GlobalLabelParameters.URL_PREFIX).append(merchantConfig.getRequestHost().trim()).append(path);
1527+ }
1528+
15071529 if (queryParams != null && !queryParams.isEmpty()) {
15081530 // support (constant ) query string in `path`, e.g. " /posts?draft=1"
15091531 String prefix = path.contains(" ?" ) ? " &" : " ?" ;
0 commit comments