You are viewing a plain text version of this content. The canonical link for it is here.
Posted to portalapps-dev@portals.apache.org by wo...@apache.org on 2009/09/21 17:58:34 UTC

svn commit: r817303 - in /portals/applications/webcontent/trunk: webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/proxy/impl/RewritableHttpReverseProxyServiceImpl.java webcontent-war/src/main/webapp/WEB-INF/web.xml

Author: woonsan
Date: Mon Sep 21 15:58:34 2009
New Revision: 817303

URL: http://svn.apache.org/viewvc?rev=817303&view=rev
Log:
APA-17: Fixing advanced configuration feature for httpclient connection properties. Also adding some example configurations in web.xml.

Modified:
    portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/proxy/impl/RewritableHttpReverseProxyServiceImpl.java
    portals/applications/webcontent/trunk/webcontent-war/src/main/webapp/WEB-INF/web.xml

Modified: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/proxy/impl/RewritableHttpReverseProxyServiceImpl.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/proxy/impl/RewritableHttpReverseProxyServiceImpl.java?rev=817303&r1=817302&r2=817303&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/proxy/impl/RewritableHttpReverseProxyServiceImpl.java (original)
+++ portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/proxy/impl/RewritableHttpReverseProxyServiceImpl.java Mon Sep 21 15:58:34 2009
@@ -33,18 +33,20 @@
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
-import org.apache.commons.beanutils.PropertyUtils;
+import org.apache.commons.beanutils.BeanUtils;
 import org.apache.commons.fileupload.FileItem;
 import org.apache.commons.fileupload.FileUploadException;
 import org.apache.commons.fileupload.disk.DiskFileItem;
 import org.apache.commons.fileupload.disk.DiskFileItemFactory;
 import org.apache.commons.fileupload.servlet.ServletFileUpload;
 import org.apache.commons.httpclient.Header;
+import org.apache.commons.httpclient.HostConfiguration;
 import org.apache.commons.httpclient.HttpClient;
 import org.apache.commons.httpclient.HttpMethod;
 import org.apache.commons.httpclient.HttpMethodBase;
 import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
 import org.apache.commons.httpclient.NameValuePair;
+import org.apache.commons.httpclient.URI;
 import org.apache.commons.httpclient.cookie.CookiePolicy;
 import org.apache.commons.httpclient.methods.GetMethod;
 import org.apache.commons.httpclient.methods.PostMethod;
@@ -55,6 +57,7 @@
 import org.apache.commons.httpclient.methods.multipart.Part;
 import org.apache.commons.httpclient.methods.multipart.PartSource;
 import org.apache.commons.httpclient.methods.multipart.StringPart;
+import org.apache.commons.httpclient.params.HttpConnectionManagerParams;
 import org.apache.commons.io.IOUtils;
 import org.apache.portals.applications.webcontent.proxy.HttpReverseProxyPathMapper;
 import org.apache.portals.applications.webcontent.proxy.HttpReverseProxyPathMapperProvider;
@@ -176,6 +179,7 @@
     public void initialize()
     {
         MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
+        HttpConnectionManagerParams connectionManagerParams = connectionManager.getParams();
         
         if (connectionProperties != null)
         {
@@ -186,7 +190,19 @@
                 
                 try
                 {
-                    PropertyUtils.setProperty(connectionManager, propName, propValue);
+                    if (propName.startsWith("maxConnectionsPerHost."))
+                    {
+                        int offset = "maxConnectionsPerHost.".length();
+                        String hostURI = propName.substring(offset);
+                        HostConfiguration hostConfig = new HostConfiguration();
+                        hostConfig.setHost(new URI(hostURI, false));
+                        int maxConnectionsPerHost = Integer.parseInt(propValue);
+                        connectionManagerParams.setMaxConnectionsPerHost(hostConfig, maxConnectionsPerHost);
+                    }
+                    else
+                    {
+                        BeanUtils.setProperty(connectionManagerParams, propName, propValue);
+                    }
                 }
                 catch (Exception e)
                 {

Modified: portals/applications/webcontent/trunk/webcontent-war/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/webcontent-war/src/main/webapp/WEB-INF/web.xml?rev=817303&r1=817302&r2=817303&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/webcontent-war/src/main/webapp/WEB-INF/web.xml (original)
+++ portals/applications/webcontent/trunk/webcontent-war/src/main/webapp/WEB-INF/web.xml Mon Sep 21 15:58:34 2009
@@ -56,7 +56,21 @@
       <param-name>reverseproxy.urlmappings</param-name>
       <param-value>/WEB-INF/conf/reverseproxy-urlmappings.properties</param-value>
     </init-param>
-    <load-on-startup>10</load-on-startup>
+    <!-- You can set httpclient's HttpConnectionManagerParams properties by prefixing 'connection.property.'. -->
+    <init-param>
+      <param-name>connection.property.maxTotalConnections</param-name>
+      <param-value>200</param-value>
+    </init-param>
+    <init-param>
+      <param-name>connection.property.defaultMaxConnectionsPerHost</param-name>
+      <param-value>20</param-value>
+    </init-param>
+    <!-- You can set max connection per host by appending the host uri after 'maxConnectionsPerHost.'. -->
+    <init-param>
+      <param-name>connection.property.maxConnectionsPerHost.http://portals.apache.org/</param-name>
+      <param-value>40</param-value>
+    </init-param>
+    <load-on-startup>11</load-on-startup>
   </servlet>
   
   <!-- Map *.vm files to Velocity  -->