From 247d04e0f66debdd334f505a32e6557931841607 Mon Sep 17 00:00:00 2001 From: Christian Ortlepp Date: Mon, 4 Nov 2024 09:02:46 +0100 Subject: [PATCH] fix: correct http proxy configuration precedence (#AXIS2-6044) Changes the precedence from "System Properties > MessageContext > Axis2.xml" to "MessageContext > Axis2.xml > System Properties". --- .../httpclient5/HTTPProxyConfigurator.java | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/modules/transport/http/src/main/java/org/apache/axis2/transport/http/impl/httpclient5/HTTPProxyConfigurator.java b/modules/transport/http/src/main/java/org/apache/axis2/transport/http/impl/httpclient5/HTTPProxyConfigurator.java index 418af501bb..f8cf1ef64b 100644 --- a/modules/transport/http/src/main/java/org/apache/axis2/transport/http/impl/httpclient5/HTTPProxyConfigurator.java +++ b/modules/transport/http/src/main/java/org/apache/axis2/transport/http/impl/httpclient5/HTTPProxyConfigurator.java @@ -76,7 +76,18 @@ public static void configure(MessageContext messageContext, RequestConfig.Builde String proxyUser = null; String proxyPassword = null; - // Getting configuration values from Axis2.xml + + // First: get settings from system properties + String host = System.getProperty(HTTPTransportConstants.HTTP_PROXY_HOST); + if (host != null) { + proxyHost = host; + } + String port = System.getProperty(HTTPTransportConstants.HTTP_PROXY_PORT); + if (port != null && !port.isEmpty()) { + proxyPort = Integer.parseInt(port); + } + + // Override with settings from Axis2.xml Parameter proxySettingsFromAxisConfig = messageContext.getConfigurationContext() .getAxisConfiguration().getParameter(HTTPTransportConstants.ATTR_PROXY); if (proxySettingsFromAxisConfig != null) { @@ -99,17 +110,16 @@ public static void configure(MessageContext messageContext, RequestConfig.Builde if (proxyUser.length() > proxyUserDomainIndex + 1) { String user = proxyUser.substring(proxyUserDomainIndex + 1); proxyCredentials = new NTCredentials(user, proxyPassword.toCharArray(), proxyHost, - domain); + domain); } } } } - // If there is runtime proxy settings, these settings will override - // settings from axis2.xml + // Override with settings from MessageContext HttpTransportProperties.ProxyProperties proxyProperties = (HttpTransportProperties.ProxyProperties) messageContext - .getProperty(HTTPConstants.PROXY); + .getProperty(HTTPConstants.PROXY); if (proxyProperties != null) { String proxyHostProp = proxyProperties.getProxyHostName(); if (proxyHostProp == null || proxyHostProp.length() <= 0) { @@ -132,16 +142,7 @@ public static void configure(MessageContext messageContext, RequestConfig.Builde } - // Overriding proxy settings if proxy is available from JVM settings - String host = System.getProperty(HTTPTransportConstants.HTTP_PROXY_HOST); - if (host != null) { - proxyHost = host; - } - String port = System.getProperty(HTTPTransportConstants.HTTP_PROXY_PORT); - if (port != null && !port.isEmpty()) { - proxyPort = Integer.parseInt(port); - } // AXIS2-6051, CredentialsProvider no longer has setCredentials() however BasicCredentialsProvider // does have it. clientContext.getCredentialsProvider() returns CredentialsProvider.