You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by do...@apache.org on 2009/04/30 17:06:30 UTC

svn commit: r770273 - in /webservices/axis2/trunk/java/modules: kernel/src/org/apache/axis2/transport/http/ transport/http/src/org/apache/axis2/transport/http/

Author: dobri
Date: Thu Apr 30 15:06:30 2009
New Revision: 770273

URL: http://svn.apache.org/viewvc?rev=770273&view=rev
Log:
Support HttpState object association with a client and use it when invoking httpClient.executeMethod(...). For more information refer to https://issues.apache.org/jira/browse/AXIS2-4288

Modified:
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/HTTPConstants.java
    webservices/axis2/trunk/java/modules/transport/http/src/org/apache/axis2/transport/http/AbstractHTTPSender.java
    webservices/axis2/trunk/java/modules/transport/http/src/org/apache/axis2/transport/http/ProxyConfiguration.java

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/HTTPConstants.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/HTTPConstants.java?rev=770273&r1=770272&r2=770273&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/HTTPConstants.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/HTTPConstants.java Thu Apr 30 15:06:30 2009
@@ -22,6 +22,8 @@
 
 import java.io.UnsupportedEncodingException;
 
+import org.apache.commons.httpclient.HttpState;
+
 /**
  * HTTP protocol and message context constants.
  */
@@ -438,6 +440,12 @@
     public static final String CACHED_HTTP_CLIENT = "CACHED_HTTP_CLIENT";
 
     /**
+     * The name of the property that sets a HTTP state to be cached. 
+     * The property value should be of type {@link HttpState}.  
+     */
+    public static final String CACHED_HTTP_STATE = "CACHED_HTTP_STATE";    
+
+    /**
      * @deprecated please use MULTITHREAD_HTTP_CONNECTION_MANAGER
      */
     public static final String MUTTITHREAD_HTTP_CONNECTION_MANAGER = "MUTTITHREAD_HTTP_CONNECTION_MANAGER";

Modified: webservices/axis2/trunk/java/modules/transport/http/src/org/apache/axis2/transport/http/AbstractHTTPSender.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/transport/http/src/org/apache/axis2/transport/http/AbstractHTTPSender.java?rev=770273&r1=770272&r2=770273&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/transport/http/src/org/apache/axis2/transport/http/AbstractHTTPSender.java (original)
+++ webservices/axis2/trunk/java/modules/transport/http/src/org/apache/axis2/transport/http/AbstractHTTPSender.java Thu Apr 30 15:06:30 2009
@@ -40,6 +40,7 @@
 import org.apache.commons.httpclient.HttpConnectionManager;
 import org.apache.commons.httpclient.HttpMethod;
 import org.apache.commons.httpclient.HttpMethodBase;
+import org.apache.commons.httpclient.HttpState;
 import org.apache.commons.httpclient.HttpVersion;
 import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
 import org.apache.commons.httpclient.NTCredentials;
@@ -322,6 +323,14 @@
 
                 Credentials creds;
 
+                HttpState tmpHttpState = null;
+                HttpState httpState = (HttpState)msgCtx.getProperty(HTTPConstants.CACHED_HTTP_STATE);
+                if (httpState != null) {
+                    tmpHttpState = httpState;
+                } else {
+                    tmpHttpState = agent.getState();
+                }
+                
                 agent.getParams()
                         .setAuthenticationPreemptive(authenticator.getPreemptiveAuthentication());
 
@@ -333,17 +342,17 @@
                         /*Credentials for Digest and Basic Authentication*/
                         creds = new UsernamePasswordCredentials(username, password);
                     }
-                    agent.getState().setCredentials(new AuthScope(host, port, realm), creds);
+                    tmpHttpState.setCredentials(new AuthScope(host, port, realm), creds);
                 } else {
                     if (domain != null) {
                         /*Credentials for NTLM Authentication when host is ANY_HOST*/
                         creds = new NTCredentials(username, password, AuthScope.ANY_HOST, domain);
-                        agent.getState().setCredentials(
+                        tmpHttpState.setCredentials(
                                 new AuthScope(AuthScope.ANY_HOST, port, realm), creds);
                     } else {
                         /*Credentials only for Digest and Basic Authentication*/
                         creds = new UsernamePasswordCredentials(username, password);
-                        agent.getState().setCredentials(new AuthScope(AuthScope.ANY), creds);
+                        tmpHttpState.setCredentials(new AuthScope(AuthScope.ANY), creds);
                     }
                 }
                 /* Customizing the priority Order */
@@ -547,7 +556,8 @@
         if (cookiePolicy != null) {
             method.getParams().setCookiePolicy(cookiePolicy);   
         }
-        httpClient.executeMethod(config, method);
+        HttpState httpState = (HttpState)msgContext.getProperty(HTTPConstants.CACHED_HTTP_STATE);        
+        httpClient.executeMethod(config, method, httpState);
     }
 
     public void addCustomHeaders(HttpMethod method, MessageContext msgContext) {

Modified: webservices/axis2/trunk/java/modules/transport/http/src/org/apache/axis2/transport/http/ProxyConfiguration.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/transport/http/src/org/apache/axis2/transport/http/ProxyConfiguration.java?rev=770273&r1=770272&r2=770273&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/transport/http/src/org/apache/axis2/transport/http/ProxyConfiguration.java (original)
+++ webservices/axis2/trunk/java/modules/transport/http/src/org/apache/axis2/transport/http/ProxyConfiguration.java Thu Apr 30 15:06:30 2009
@@ -26,6 +26,7 @@
 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;
@@ -197,7 +198,12 @@
         }
         
         httpClient.getParams().setAuthenticationPreemptive(true);
-        httpClient.getState().setProxyCredentials(AuthScope.ANY, proxyCred);
+        HttpState tmpHttpState = httpClient.getState();
+        HttpState httpState = (HttpState)messageContext.getProperty(HTTPConstants.CACHED_HTTP_STATE);
+        if (httpState != null) {
+            tmpHttpState = httpState;
+        }        
+        tmpHttpState.setProxyCredentials(AuthScope.ANY, proxyCred);
         config.setProxy(this.getProxyHost(), this.getProxyPort());
     }