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 ga...@apache.org on 2010/07/13 15:32:58 UTC
svn commit: r963711 -
/axis/axis2/java/core/branches/java/1_5/modules/transport/http/src/org/apache/axis2/transport/http/AbstractHTTPSender.java
Author: gawor
Date: Tue Jul 13 13:32:58 2010
New Revision: 963711
URL: http://svn.apache.org/viewvc?rev=963711&view=rev
Log:
AXIS2-4751: Create a new instance of HttpClient since it is not used in thread-safe way. The connection manager is not automatically reused right now because other bugs in Axis2 or related libraries cause test failures when connection reuse is enabled.
Modified:
axis/axis2/java/core/branches/java/1_5/modules/transport/http/src/org/apache/axis2/transport/http/AbstractHTTPSender.java
Modified: axis/axis2/java/core/branches/java/1_5/modules/transport/http/src/org/apache/axis2/transport/http/AbstractHTTPSender.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/branches/java/1_5/modules/transport/http/src/org/apache/axis2/transport/http/AbstractHTTPSender.java?rev=963711&r1=963710&r2=963711&view=diff
==============================================================================
--- axis/axis2/java/core/branches/java/1_5/modules/transport/http/src/org/apache/axis2/transport/http/AbstractHTTPSender.java (original)
+++ axis/axis2/java/core/branches/java/1_5/modules/transport/http/src/org/apache/axis2/transport/http/AbstractHTTPSender.java Tue Jul 13 13:32:58 2010
@@ -41,8 +41,7 @@ import org.apache.commons.httpclient.Htt
import org.apache.commons.httpclient.HttpConnectionManager;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.HttpMethodBase;
-import org.apache.commons.httpclient.HttpVersion;
-import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
+import org.apache.commons.httpclient.HttpVersion;import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
import org.apache.commons.httpclient.NTCredentials;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
@@ -479,35 +478,57 @@ public abstract class AbstractHTTPSender
}
protected HttpClient getHttpClient(MessageContext msgContext) {
- HttpClient httpClient;
- final ConfigurationContext configContext = msgContext.getConfigurationContext();
- synchronized (lock) {
+ ConfigurationContext configContext = msgContext.getConfigurationContext();
+
+ HttpClient httpClient = (HttpClient) msgContext.getProperty(HTTPConstants.CACHED_HTTP_CLIENT);
+ if (httpClient == null) {
httpClient = (HttpClient) configContext.getProperty(HTTPConstants.CACHED_HTTP_CLIENT);
- if (httpClient == null) {
- log.trace("Making new ConnectionManager");
- HttpConnectionManager connManager = new MultiThreadedHttpConnectionManager();
-
- // In case we need to set any params, do it here, but for now use defaults.
-// HttpConnectionManagerParams params = new HttpConnectionManagerParams();
-// params.setMaxConnectionsPerHost(HostConfiguration.ANY_HOST_CONFIGURATION, 200);
-// etc...
-// connManager.setParams(params);
-
- httpClient = new HttpClient(connManager);
- HttpClientParams clientParams = new HttpClientParams();
- // Set the default timeout in case we have a connection pool starvation to 30sec
- clientParams.setConnectionManagerTimeout(30000);
- httpClient.setParams(clientParams);
- configContext.setProperty(HTTPConstants.CACHED_HTTP_CLIENT, httpClient);
- }
+ }
+ if (httpClient != null) {
+ return httpClient;
+ }
- // Get the timeout values set in the runtime
- initializeTimeouts(msgContext, 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();
+ /*
+ * Commented out for now as bugs in other parts of Axis2 cause test failures when
+ * proper connection reuse is enabled.
+ */
+ // 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);
+
+ // 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);
+
return httpClient;
}
- static final Object lock = new Object();
protected void executeMethod(HttpClient httpClient, MessageContext msgContext, URL url,
HttpMethod method) throws IOException {
HostConfiguration config = this.getHostConfiguration(httpClient, msgContext, url);