[jboss-svn-commits] JBL Code SVN: r29108 - in labs/jbossesb/branches/JBESB_4_4_GA_CP/product: rosetta/src/org/jboss/soa/esb/http/configurators and 1 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Fri Aug 28 07:59:11 EDT 2009
Author: tfennelly
Date: 2009-08-28 07:59:11 -0400 (Fri, 28 Aug 2009)
New Revision: 29108
Added:
labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/http/configurators/Connection.java
Modified:
labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/http/HttpClientFactory.java
labs/jbossesb/branches/JBESB_4_4_GA_CP/product/samples/quickstarts/https_2way_ssl/HttpRouter-localhost-https-9433.properties
Log:
https://jira.jboss.org/jira/browse/JBESB-2803
Merge JBESB-2635: Move HTTP Connection configuration code in HttpClientFactory to a Configurator
https://jira.jboss.org/jira/browse/JBESB-2804
Merge JBESB-2548: HttpClientFactory not configuring the "default-max-connections-per-host" on the connection manager
Modified: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/http/HttpClientFactory.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/http/HttpClientFactory.java 2009-08-28 11:43:29 UTC (rev 29107)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/http/HttpClientFactory.java 2009-08-28 11:59:11 UTC (rev 29108)
@@ -21,13 +21,13 @@
import org.jboss.soa.esb.ConfigurationException;
import org.jboss.soa.esb.http.configurators.HttpProtocol;
+import org.jboss.soa.esb.http.configurators.Connection;
import org.jboss.soa.esb.util.ClassUtil;
import org.jboss.internal.soa.esb.assertion.AssertArgument;
import org.jboss.internal.soa.esb.util.StreamUtils;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpConnectionManager;
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
-import org.apache.commons.httpclient.params.HttpConnectionManagerParams;
import java.util.Properties;
import java.io.IOException;
@@ -45,6 +45,7 @@
public static final String TARGET_HOST_URL = "target-host-url";
/**
* Max total connections.
+ * @deprecated
*/
public static final String MAX_TOTAL_CONNECTIONS = "max-total-connections";
@@ -59,19 +60,7 @@
public static HttpClient createHttpClient(Properties properties) throws ConfigurationException {
AssertArgument.isNotNull(properties, "properties");
- final HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager() ;
- final String maxTotalConnections = properties.getProperty(MAX_TOTAL_CONNECTIONS) ;
- if (maxTotalConnections != null) {
- final HttpConnectionManagerParams params = new HttpConnectionManagerParams() ;
- try {
- params.setMaxTotalConnections(Integer.parseInt(maxTotalConnections)) ;
- } catch (final NumberFormatException nfe) {
- throw new ConfigurationException("Invalid " + MAX_TOTAL_CONNECTIONS + " property: " + maxTotalConnections) ;
- }
- connectionManager.setParams(params) ;
- }
-
- HttpClient httpClient = new HttpClient(connectionManager);
+ HttpClient httpClient = new HttpClient();
String fileConfig = (String) properties.remove("file");
String[] configurators;
@@ -83,6 +72,10 @@
}
}
+ // Apply the mandatory Configurators...
+ new Connection().configure(httpClient, properties);
+
+ // Apply the optional (configured) Configurators...
configurators = properties.getProperty("configurators", HttpProtocol.class.getName()).split(",");
for(String configuratorClass : configurators) {
Configurator configurator = createConfigurator(configuratorClass.trim());
Copied: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/http/configurators/Connection.java (from rev 27111, labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/http/configurators/Connection.java)
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/http/configurators/Connection.java (rev 0)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/http/configurators/Connection.java 2009-08-28 11:59:11 UTC (rev 29108)
@@ -0,0 +1,122 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006, JBoss Inc.
+ */
+package org.jboss.soa.esb.http.configurators;
+
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.ProxyHost;
+import org.apache.commons.httpclient.HttpConnectionManager;
+import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
+import org.apache.commons.httpclient.params.HttpConnectionManagerParams;
+import org.apache.commons.httpclient.contrib.ssl.StrictSSLProtocolSocketFactory;
+import org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory;
+import org.apache.commons.httpclient.protocol.Protocol;
+import org.apache.commons.httpclient.protocol.ProtocolSocketFactory;
+import org.apache.commons.ssl.KeyMaterial;
+import org.apache.commons.ssl.SSLClient;
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.http.Configurator;
+import org.jboss.soa.esb.http.protocol.ProtocolSocketFactoryBuilder;
+import org.jboss.soa.esb.util.ClassUtil;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.security.GeneralSecurityException;
+import java.security.KeyManagementException;
+import java.security.KeyStoreException;
+import java.security.NoSuchAlgorithmException;
+import java.security.cert.CertificateException;
+import java.util.Properties;
+
+/**
+ * HTTP Connection configurator.
+ * <p/>
+ * This {@link Configurator} is always applied to HttpClient instances created by the
+ * {@link org.jboss.soa.esb.http.HttpClientFactory}. Of course, if you wish to make the
+ * connection configurations in a different way, you can always create a custom {@link Configurator}
+ * that creates and attches a different {@link HttpConnectionManager} instance that has differnt
+ * configurations.
+ * <p/>
+ * Properties:
+ * <ul>
+ * <li><b>max-total-connections</b>: Maximum total number of connection for the HttpClient instance.</li>
+ * <li><b>max-connections-per-host</b>: Maximum connection per target host for the HttpClient instance. Note that
+ * the default value for this configuration is 2. So, configuring the "max-total-connections" property
+ * without also configuring this property will have little effect on performance for a single host
+ * because it will only ever open a max of 2 connections (as per the default).
+ * </li>
+ * </ul>
+ * <p/>
+ *
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class Connection extends Configurator {
+
+ private Logger logger = Logger.getLogger(Connection.class);
+ /**
+ * Max total connections.
+ */
+ public static final String MAX_TOTAL_CONNECTIONS = "max-total-connections";
+ /**
+ * Max connections per host.
+ */
+ public static final String MAX_CONNECTIONS_PER_HOST = "max-connections-per-host";
+
+ public void configure(HttpClient httpClient, Properties properties) throws ConfigurationException {
+ final HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager() ;
+ final String maxTotalConnections = properties.getProperty(MAX_TOTAL_CONNECTIONS) ;
+ final String maxConnectionsPerHost = properties.getProperty(MAX_CONNECTIONS_PER_HOST) ;
+
+ if (maxTotalConnections != null) {
+ final HttpConnectionManagerParams params = getConnectionManagerParams(connectionManager);
+ try {
+ params.setMaxTotalConnections(Integer.parseInt(maxTotalConnections.trim())) ;
+ } catch (final NumberFormatException nfe) {
+ throw new ConfigurationException("Invalid " + MAX_TOTAL_CONNECTIONS + " property: " + maxTotalConnections) ;
+ }
+ }
+
+ if (maxConnectionsPerHost != null) {
+ final HttpConnectionManagerParams params = getConnectionManagerParams(connectionManager);
+ try {
+ params.setMaxConnectionsPerHost(httpClient.getHostConfiguration(), Integer.parseInt(maxConnectionsPerHost.trim()));
+ } catch (final NumberFormatException nfe) {
+ throw new ConfigurationException("Invalid " + MAX_CONNECTIONS_PER_HOST + " property: " + maxConnectionsPerHost) ;
+ }
+ }
+
+ httpClient.setHttpConnectionManager(connectionManager);
+ }
+
+ private HttpConnectionManagerParams getConnectionManagerParams(HttpConnectionManager connectionManager) {
+ HttpConnectionManagerParams params = connectionManager.getParams();
+
+ if(params == null) {
+ params = new HttpConnectionManagerParams();
+ connectionManager.setParams(params) ;
+ }
+
+ return params;
+ }
+}
\ No newline at end of file
Modified: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/samples/quickstarts/https_2way_ssl/HttpRouter-localhost-https-9433.properties
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/samples/quickstarts/https_2way_ssl/HttpRouter-localhost-https-9433.properties 2009-08-28 11:43:29 UTC (rev 29107)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/samples/quickstarts/https_2way_ssl/HttpRouter-localhost-https-9433.properties 2009-08-28 11:59:11 UTC (rev 29108)
@@ -13,3 +13,6 @@
keystore-passw=https_2way_ssl_pass
truststore=@keystore@
truststore-passw=https_2way_ssl_pass
+
+# Connection config
+max-connections-per-host=5
More information about the jboss-svn-commits
mailing list