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 su...@apache.org on 2010/12/21 17:39:07 UTC

svn commit: r1051548 - /axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/AbstractHTTPSender.java

Author: supun
Date: Tue Dec 21 16:39:06 2010
New Revision: 1051548

URL: http://svn.apache.org/viewvc?rev=1051548&view=rev
Log:
fixing issue AXIS2-3945

Modified:
    axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/AbstractHTTPSender.java

Modified: axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/AbstractHTTPSender.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/AbstractHTTPSender.java?rev=1051548&r1=1051547&r2=1051548&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/AbstractHTTPSender.java (original)
+++ axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/AbstractHTTPSender.java Tue Dec 21 16:39:06 2010
@@ -62,6 +62,8 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
 import java.util.*;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
 import java.util.zip.GZIPInputStream;
 
 public abstract class AbstractHTTPSender {
@@ -522,49 +524,64 @@ public abstract class AbstractHTTPSender
     protected HttpClient getHttpClient(MessageContext msgContext) {
         ConfigurationContext configContext = msgContext.getConfigurationContext();
 
-        HttpClient httpClient = (HttpClient) msgContext.getProperty(HTTPConstants.CACHED_HTTP_CLIENT);
+        HttpClient httpClient = (HttpClient) msgContext.getProperty(
+                HTTPConstants.CACHED_HTTP_CLIENT);
+
         if (httpClient == null) {
             httpClient = (HttpClient) configContext.getProperty(HTTPConstants.CACHED_HTTP_CLIENT);
         }
+
         if (httpClient != null) {
             return httpClient;
         }
 
-        HttpConnectionManager connManager =
-            (HttpConnectionManager) msgContext.getProperty(
-                 HTTPConstants.MULTITHREAD_HTTP_CONNECTION_MANAGER);
-        if (connManager == null) {
-            connManager =
-                (HttpConnectionManager) msgContext.getProperty(
-                     HTTPConstants.MUTTITHREAD_HTTP_CONNECTION_MANAGER);
-        }
-        if (connManager == null) {
-            // reuse HttpConnectionManager
-            synchronized (configContext) {
-                connManager = (HttpConnectionManager) configContext.getProperty(
-                                   HTTPConstants.MULTITHREAD_HTTP_CONNECTION_MANAGER);
-                if (connManager == null) {
-                    log.trace("Making new ConnectionManager");
-                    connManager = new MultiThreadedHttpConnectionManager();
-                    configContext.setProperty(HTTPConstants.MULTITHREAD_HTTP_CONNECTION_MANAGER, 
-                                              connManager);
+        synchronized (this) {
+            httpClient = (HttpClient) msgContext.getProperty(HTTPConstants.CACHED_HTTP_CLIENT);
+
+            if (httpClient == null) {
+                httpClient = (HttpClient) configContext.getProperty(
+                        HTTPConstants.CACHED_HTTP_CLIENT);
+            }
+
+            if (httpClient != null) {
+                return httpClient;
+            }
+
+            HttpConnectionManager connManager =
+                    (HttpConnectionManager) msgContext.getProperty(
+                            HTTPConstants.MULTITHREAD_HTTP_CONNECTION_MANAGER);
+            if (connManager == null) {
+                connManager =
+                        (HttpConnectionManager) msgContext.getProperty(
+                                HTTPConstants.MUTTITHREAD_HTTP_CONNECTION_MANAGER);
+            }
+            if (connManager == null) {
+                // reuse HttpConnectionManager
+                synchronized (configContext) {
+                    connManager = (HttpConnectionManager) configContext.getProperty(
+                            HTTPConstants.MULTITHREAD_HTTP_CONNECTION_MANAGER);
+                    if (connManager == null) {
+                        log.trace("Making new ConnectionManager");
+                        connManager = new MultiThreadedHttpConnectionManager();
+                        configContext.setProperty(
+                                HTTPConstants.MULTITHREAD_HTTP_CONNECTION_MANAGER, connManager);
+                    }
                 }
             }
-        }
-
-        /*
-         * Create a new instance of HttpClient since the way
-         * it is used here it's not fully thread-safe.
-         */
-        httpClient = new HttpClient(connManager);
+            /*
+             * Create a new instance of HttpClient since the way
+             * it is used here it's not fully thread-safe.
+             */
+            httpClient = new HttpClient(connManager);
 
-        // Set the default timeout in case we have a connection pool starvation to 30sec
-        httpClient.getParams().setConnectionManagerTimeout(30000);
+            // Set the default timeout in case we have a connection pool starvation to 30sec
+            httpClient.getParams().setConnectionManagerTimeout(30000);
 
-        // Get the timeout values set in the runtime
-        initializeTimeouts(msgContext, httpClient);
+            // Get the timeout values set in the runtime
+            initializeTimeouts(msgContext, httpClient);
 
-        return httpClient;
+            return httpClient;
+        }
     }
 
     protected void executeMethod(HttpClient httpClient, MessageContext msgContext, URL url,