@@ -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