You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-commits@axis.apache.org by bi...@apache.org on 2020/04/14 20:03:19 UTC

[axis-axis2-java-core] 13/15: Applied latest patch.

This is an automated email from the ASF dual-hosted git repository.

billblough pushed a commit to branch AXIS2-4318
in repository https://gitbox.apache.org/repos/asf/axis-axis2-java-core.git

commit 5cbc2cb75692fce5497e998e1d681861c85a1a29
Author: Sagara Gunathunga <sa...@apache.org>
AuthorDate: Tue May 8 06:52:55 2012 +0000

    Applied latest patch.
---
 .../HTTPProxyConfigurator.java                     | 67 +++++++++++-----------
 .../http/impl/httpclient3/HTTPSenderImpl.java      |  4 +-
 .../impl/httpclient4/HTTPProxyConfigurator.java    |  5 +-
 3 files changed, 39 insertions(+), 37 deletions(-)

diff --git a/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient4/HTTPProxyConfigurator.java b/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient3/HTTPProxyConfigurator.java
similarity index 92%
copy from modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient4/HTTPProxyConfigurator.java
copy to modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient3/HTTPProxyConfigurator.java
index 67615f4..e47f4f4 100644
--- a/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient4/HTTPProxyConfigurator.java
+++ b/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient3/HTTPProxyConfigurator.java
@@ -17,7 +17,7 @@
  * under the License.
  */
 
-package org.apache.axis2.transport.http.impl.httpclient4;
+package org.apache.axis2.transport.http.impl.httpclient3;
 
 import org.apache.axiom.om.OMElement;
 import org.apache.axis2.AxisFault;
@@ -26,22 +26,20 @@ import org.apache.axis2.description.Parameter;
 import org.apache.axis2.transport.http.HTTPConstants;
 import org.apache.axis2.transport.http.HTTPTransportConstants;
 import org.apache.axis2.transport.http.HttpTransportProperties;
+import org.apache.commons.httpclient.Credentials;
+import org.apache.commons.httpclient.HostConfiguration;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpState;
+import org.apache.commons.httpclient.NTCredentials;
+import org.apache.commons.httpclient.UsernamePasswordCredentials;
+import org.apache.commons.httpclient.auth.AuthScope;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.http.HttpHost;
-import org.apache.http.auth.AuthScope;
-import org.apache.http.auth.Credentials;
-import org.apache.http.auth.NTCredentials;
-import org.apache.http.auth.UsernamePasswordCredentials;
-import org.apache.http.client.params.ClientPNames;
-import org.apache.http.conn.params.ConnRoutePNames;
-import org.apache.http.impl.client.AbstractHttpClient;
 
 import javax.xml.namespace.QName;
 import java.net.URL;
 import java.util.StringTokenizer;
 
-
 public class HTTPProxyConfigurator {
 
     private static Log log = LogFactory.getLog(HTTPProxyConfigurator.class);
@@ -55,16 +53,18 @@ public class HTTPProxyConfigurator {
      * <Configuration> <ProxyHost>example.org</ProxyHost>
      * <ProxyPort>3128</ProxyPort> <ProxyUser>EXAMPLE/John</ProxyUser>
      * <ProxyPassword>password</ProxyPassword> <Configuration> <parameter>
-     *
+     * 
      * @param messageContext
      *            in message context for
      * @param httpClient
-     *            instance
-     * @throws org.apache.axis2.AxisFault
+     *            commons-httpclient instance
+     * @param config
+     *            commons-httpclient HostConfiguration
+     * @throws AxisFault
      *             if Proxy settings are invalid
      */
-    public static void configure(MessageContext messageContext, AbstractHttpClient httpClient)
-            throws AxisFault {
+    public static void configure(MessageContext messageContext, HttpClient httpClient,
+            HostConfiguration config) throws AxisFault {
 
         Credentials proxyCredentials = null;
         String proxyHost = null;
@@ -77,8 +77,7 @@ public class HTTPProxyConfigurator {
         Parameter proxySettingsFromAxisConfig = messageContext.getConfigurationContext()
                 .getAxisConfiguration().getParameter(HTTPTransportConstants.ATTR_PROXY);
         if (proxySettingsFromAxisConfig != null) {
-            OMElement proxyConfiguration =
-                    getProxyConfigurationElement(proxySettingsFromAxisConfig);
+            OMElement proxyConfiguration = getProxyConfigurationElement(proxySettingsFromAxisConfig);
             proxyHost = getProxyHost(proxyConfiguration);
             proxyPort = getProxyPort(proxyConfiguration);
             proxyUser = getProxyUser(proxyConfiguration);
@@ -87,24 +86,25 @@ public class HTTPProxyConfigurator {
                 if (proxyPassword == null) {
                     proxyPassword = "";
                 }
+
+                proxyCredentials = new UsernamePasswordCredentials(proxyUser, proxyPassword);
+
                 int proxyUserDomainIndex = proxyUser.indexOf("\\");
                 if (proxyUserDomainIndex > 0) {
                     String domain = proxyUser.substring(0, proxyUserDomainIndex);
                     if (proxyUser.length() > proxyUserDomainIndex + 1) {
                         String user = proxyUser.substring(proxyUserDomainIndex + 1);
-                        proxyCredentials = new NTCredentials(user, proxyPassword, proxyHost,
-                                                             domain);
+                        proxyCredentials = new NTCredentials(user, proxyPassword, proxyHost, domain);
                     }
                 }
-                proxyCredentials = new UsernamePasswordCredentials(proxyUser, proxyPassword);
+
             }
 
         }
 
         // If there is runtime proxy settings, these settings will override
         // settings from axis2.xml
-        HttpTransportProperties.ProxyProperties proxyProperties =
-                (HttpTransportProperties.ProxyProperties) messageContext
+        HttpTransportProperties.ProxyProperties proxyProperties = (HttpTransportProperties.ProxyProperties) messageContext
                 .getProperty(HTTPConstants.PROXY);
         if (proxyProperties != null) {
             String proxyHostProp = proxyProperties.getProxyHostName();
@@ -140,14 +140,15 @@ public class HTTPProxyConfigurator {
         }
 
         if (proxyCredentials != null) {
-            // TODO : Set preemptive authentication, but its not recommended in HC 4
-            httpClient.getParams().setParameter(ClientPNames.HANDLE_AUTHENTICATION, true);
-
-            httpClient.getCredentialsProvider().setCredentials(AuthScope.ANY, proxyCredentials);
-            HttpHost proxy = new HttpHost(proxyHost, proxyPort);
-            httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
-
+            httpClient.getParams().setAuthenticationPreemptive(true);
+            HttpState cachedHttpState = (HttpState) messageContext
+                    .getProperty(HTTPConstants.CACHED_HTTP_STATE);
+            if (cachedHttpState != null) {
+                httpClient.setState(cachedHttpState);
+            }
+            httpClient.getState().setProxyCredentials(AuthScope.ANY, proxyCredentials);
         }
+        config.setProxy(proxyHost, proxyPort);
     }
 
     private static OMElement getProxyConfigurationElement(Parameter proxySettingsFromAxisConfig)
@@ -224,7 +225,7 @@ public class HTTPProxyConfigurator {
     /**
      * Check whether http proxy is configured or active. This is not a deep
      * check.
-     *
+     * 
      * @param messageContext
      *            in message context
      * @param targetURL
@@ -266,7 +267,7 @@ public class HTTPProxyConfigurator {
      * <p/>
      * false : validation fail : User can use the proxy true : validation pass ;
      * User can't use the proxy
-     *
+     * 
      * @return boolean
      */
     private static boolean validateNonProxyHosts(String host) {
@@ -277,7 +278,7 @@ public class HTTPProxyConfigurator {
 
     /**
      * Check if the specified host is in the list of non proxy hosts.
-     *
+     * 
      * @param host
      *            host name
      * @param nonProxyHosts
@@ -307,7 +308,7 @@ public class HTTPProxyConfigurator {
     /**
      * Matches a string against a pattern. The pattern contains two special
      * characters: '*' which means zero or more characters,
-     *
+     * 
      * @param pattern
      *            the (non-null) pattern to match against
      * @param str
diff --git a/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient3/HTTPSenderImpl.java b/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient3/HTTPSenderImpl.java
index 2c09c35..566db64 100644
--- a/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient3/HTTPSenderImpl.java
+++ b/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient3/HTTPSenderImpl.java
@@ -538,11 +538,11 @@ public class HTTPSenderImpl extends HTTPSender {
         }
         // proxy configuration
 
-        if (HTTPProxcyConfigurator.isProxyEnabled(msgCtx, targetURL)) {
+        if (HTTPProxyConfigurator.isProxyEnabled(msgCtx, targetURL)) {
             if (log.isDebugEnabled()) {
                 log.debug("Configuring HTTP proxy.");
             }
-            HTTPProxcyConfigurator.configure(msgCtx, client, config);
+            HTTPProxyConfigurator.configure(msgCtx, client, config);
         }
 
         return config;
diff --git a/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient4/HTTPProxyConfigurator.java b/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient4/HTTPProxyConfigurator.java
index 67615f4..df7587e 100644
--- a/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient4/HTTPProxyConfigurator.java
+++ b/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient4/HTTPProxyConfigurator.java
@@ -87,6 +87,9 @@ public class HTTPProxyConfigurator {
                 if (proxyPassword == null) {
                     proxyPassword = "";
                 }
+
+                proxyCredentials = new UsernamePasswordCredentials(proxyUser, proxyPassword);
+
                 int proxyUserDomainIndex = proxyUser.indexOf("\\");
                 if (proxyUserDomainIndex > 0) {
                     String domain = proxyUser.substring(0, proxyUserDomainIndex);
@@ -96,9 +99,7 @@ public class HTTPProxyConfigurator {
                                                              domain);
                     }
                 }
-                proxyCredentials = new UsernamePasswordCredentials(proxyUser, proxyPassword);
             }
-
         }
 
         // If there is runtime proxy settings, these settings will override