ericf 2003/07/20 16:58:37
Modified: java build.xml
java/src/org/apache/axis/transport/http
CommonsHTTPSender.java
Added: java/src/org/apache/axis/components/net
CommonsHTTPClientProperties.java
CommonsHTTPClientPropertiesFactory.java
DefaultCommonsHTTPClientProperties.java
Log:
Added configuration support to CommonsHTTPSender, making it possible
to set the size of the connection pool, the number of connections
allowed per host by the pool, and the timeout on allocating a
connection from the pool. All values are identical to the defaults
of Commons HTTP Client, so there is no change to the existing
behavior. The default implementation of the new interface for
configuring these values reads them from AxisProperties, which fall
back to system properties, making it possible to configure these
settings through that mechanism as well. Connection timeout --
both in creating the connection and in blocking for socket reads
-- is derived from the Axis message for a specific request, just
as it is in the "regular" http transport. This preserves the
transparent pluggability of the commons http transport option and
separates the concern of connection timeouts from that of pooled
resource management.
None of these files are compiled unless commons-httpclient is present;
hence the modifications to build.xml
This enhancement was built against Commons HTTPClient 2.0 beta 2
Revision Changes Path
1.234 +3 -0 xml-axis/java/build.xml
Index: build.xml
===================================================================
RCS file: /home/cvs/xml-axis/java/build.xml,v
retrieving revision 1.233
retrieving revision 1.234
diff -u -r1.233 -r1.234
--- build.xml 18 Jul 2003 07:16:23 -0000 1.233
+++ build.xml 20 Jul 2003 23:58:37 -0000 1.234
@@ -129,6 +129,9 @@
<exclude
name="**/org/apache/axis/transport/http/ServletEndpointContextImpl.java"
unless="servlet.present"/>
<exclude
name="**/org/apache/axis/transport/configuration/EngineConfigurationFactoryServlet.java"
unless="servlet.present"/>
<exclude name="**/org/apache/axis/transport/http/CommonsHTTPSender.java"
unless="commons-httpclient.present"/>
+ <exclude
name="**/org/apache/axis/components/net/CommonsHTTPClientProperties.java"
unless="commons-httpclient.present"/>
+ <exclude
name="**/org/apache/axis/components/net/CommonsHTTPClientPropertiesFactory.java"
unless="commons-httpclient.present"/>
+ <exclude
name="**/org/apache/axis/components/net/DefaultCommonsHTTPClientProperties.java"
unless="commons-httpclient.present"/>
<exclude name="**/org/apache/axis/transport/mail/*.java"
unless="commons-httpclient.present"/>
<exclude name="**/org/apache/axis/transport/jms/*" unless="jms.present"/>
<exclude name="**/org/apache/axis/components/jms/BeanVendorAdapter.java"
unless="jms.present"/>
1.1
xml-axis/java/src/org/apache/axis/components/net/CommonsHTTPClientProperties.java
Index: CommonsHTTPClientProperties.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2001-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Axis" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.axis.components.net;
/**
* Interface implemented by classes seeking to configure the properties
* of the multi threaded connection pool used in the CommonsHTTPSender
* transport implementation.
*
* @author Eric Friedman
*/
public interface CommonsHTTPClientProperties {
/**
* Used to set the maximum number of connections that the pool can open
* for all hosts. Since connections imply sockets and sockets imply
* file descriptors, the setting you use must not exceed any limits
* your system imposes on the number of open file descriptors a
* single process may have.
*
* @return an integer > 1
*/
public int getMaximumTotalConnections();
/**
* Used to set the maximum number of connections that will be pooled
* for a given host. This setting is also constrained by
* the one returned from getMaximumTotalConnections.
*
* @return an integer > 1
*/
public int getMaximumConnectionsPerHost();
/**
* Used to set the amount of time, in milliseconds, spent waiting
* for an available connection from the pool. An exception is raised
* if the timeout is triggered.
*
* @return an integer > 1 OR 0 for infinite timeout
*/
public int getConnectionPoolTimeout();
}
1.1
xml-axis/java/src/org/apache/axis/components/net/CommonsHTTPClientPropertiesFactory.java
Index: CommonsHTTPClientPropertiesFactory.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2002-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Axis" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.axis.components.net;
import org.apache.axis.AxisProperties;
import org.apache.axis.components.logger.LogFactory;
import org.apache.commons.logging.Log;
/**
* @author Eric Friedman
*/
public class CommonsHTTPClientPropertiesFactory {
protected static Log log =
LogFactory.getLog(CommonsHTTPClientPropertiesFactory.class.getName());
private static CommonsHTTPClientProperties properties;
public static synchronized CommonsHTTPClientProperties create() {
if (properties == null) {
properties = (CommonsHTTPClientProperties)
AxisProperties.newInstance(CommonsHTTPClientProperties.class,
DefaultCommonsHTTPClientProperties.class);
}
return properties;
}
}
1.1
xml-axis/java/src/org/apache/axis/components/net/DefaultCommonsHTTPClientProperties.java
Index: DefaultCommonsHTTPClientProperties.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2001-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Axis" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.axis.components.net;
import org.apache.axis.AxisProperties;
/**
* Default property set for the of the multi threaded connection pool
* used in the CommonsHTTPSender transport implementation. Values
* returned by this implementation are identical to the defaults for
* the Commons HTTPClient library itself, unless overridden with
* Axis properties.
*
* @author Eric Friedman
*/
public class DefaultCommonsHTTPClientProperties implements
CommonsHTTPClientProperties {
/** the key for the Axis Property that controls the maximum total connections
allowed in the httpclient pool */
public static final String MAXIMUM_TOTAL_CONNECTIONS_PROPERTY_KEY =
"axis.http.client.maximum.total.connections";
/** the key for the Axis Property that controls the maximum connections
per host allowed by the httpclient pool */
public static final String MAXIMUM_CONNECTIONS_PER_HOST_PROPERTY_KEY =
"axis.http.client.maximum.connections.per.host";
/** the key for the Axis Property that sets the connection pool timeout
for the httpclient pool */
public static final String CONNECTION_POOL_TIMEOUT_KEY =
"axis.http.client.connection.pool.timeout";
/**
* Convert the value for <tt>property</tt> into an int or, if none is found,
* use the <tt>dephault</tt> value instead.
*
* @return an integer value
*/
protected final int getIntegerProperty(String property, String dephault) {
return Integer.parseInt(AxisProperties.getProperty(property, dephault));
}
/**
* Return the integer value associated with the property
* axis.http.client.maximum.total.connections or a default of 20.
*
* @return a whole integer
*/
public int getMaximumTotalConnections() {
int i = getIntegerProperty(MAXIMUM_TOTAL_CONNECTIONS_PROPERTY_KEY, "20");
if (i < 1) {
throw new IllegalStateException(MAXIMUM_TOTAL_CONNECTIONS_PROPERTY_KEY +
" must be > 1");
}
return i;
}
/**
* Return the integer value associated with the property
* axis.http.client.maximum.connections.per.host or a default of 2.
*
* @return a whole integer
*/
public int getMaximumConnectionsPerHost() {
int i = getIntegerProperty(MAXIMUM_CONNECTIONS_PER_HOST_PROPERTY_KEY, "2");
if (i < 1) {
throw new
IllegalStateException(MAXIMUM_CONNECTIONS_PER_HOST_PROPERTY_KEY + " must be > 1");
}
return i;
}
/**
* Return the integer value associated with the property
* axis.http.client.connection.pool.timeout or a default of 0.
*
* @return an integer >= 0
*/
public int getConnectionPoolTimeout() {
int i = getIntegerProperty(CONNECTION_POOL_TIMEOUT_KEY, "0");
if (i < 0) {
throw new IllegalStateException(CONNECTION_POOL_TIMEOUT_KEY + " must be
>= 0");
}
return i;
}
}
1.18 +15 -3
xml-axis/java/src/org/apache/axis/transport/http/CommonsHTTPSender.java
Index: CommonsHTTPSender.java
===================================================================
RCS file:
/home/cvs/xml-axis/java/src/org/apache/axis/transport/http/CommonsHTTPSender.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- CommonsHTTPSender.java 6 Jul 2003 14:28:29 -0000 1.17
+++ CommonsHTTPSender.java 20 Jul 2003 23:58:37 -0000 1.18
@@ -58,6 +58,8 @@
import org.apache.axis.Message;
import org.apache.axis.MessageContext;
import org.apache.axis.components.logger.LogFactory;
+import org.apache.axis.components.net.CommonsHTTPClientProperties;
+import org.apache.axis.components.net.CommonsHTTPClientPropertiesFactory;
import org.apache.axis.components.net.TransportClientProperties;
import org.apache.axis.components.net.TransportClientPropertiesFactory;
import org.apache.axis.encoding.Base64;
@@ -104,11 +106,14 @@
LogFactory.getLog(CommonsHTTPSender.class.getName());
private HttpConnectionManager connectionManager;
+ private CommonsHTTPClientProperties clientProperties;
public CommonsHTTPSender() {
- // should pull settings for pool size, timeouts from
- // declarative configuration
- connectionManager = new MultiThreadedHttpConnectionManager();
+ MultiThreadedHttpConnectionManager cm = new
MultiThreadedHttpConnectionManager();
+ this.clientProperties = CommonsHTTPClientPropertiesFactory.create();
+
cm.setMaxConnectionsPerHost(clientProperties.getMaximumConnectionsPerHost());
+ cm.setMaxTotalConnections(clientProperties.getMaximumTotalConnections());
+ this.connectionManager = cm;
}
/**
@@ -134,6 +139,8 @@
// the underlying connection manager, however, is retained
// so sockets get recycled when possible.
HttpClient httpClient = new HttpClient(connectionManager);
+ // the timeout value for allocation of connections from the pool
+
httpClient.setHttpConnectionFactoryTimeout(clientProperties.getConnectionPoolTimeout());
HostConfiguration hostConfiguration = getHostConfiguration(httpClient,
targetURL);
@@ -331,7 +338,12 @@
// optionally set a timeout for the request
if (msgContext.getTimeout() != 0) {
+ /* ISSUE: these are not the same, but MessageContext has only one
+ definition of timeout */
+ // SO_TIMEOUT -- timeout for blocking reads
httpClient.setTimeout(msgContext.getTimeout());
+ // timeout for initial connection
+ httpClient.setConnectionTimeout(msgContext.getTimeout());
}
// Get SOAPAction, default to ""