Revision: 37178
Author:   mnour
Date:     2012-11-26 13:46:20 +0100 (Mon, 26 Nov 2012)
Log Message:
-----------
CMS7-6706: Use MultiThreadedHttpConnectionManager instead of a new HttpClient 
for every ping
  - Removed the commons-httpclient dependency
  - Used http components httpclient instead
  - Refactored the REST service proxy plugin to use it
  - Removed the bootstrap configursation of ping service timeout as it has been 
decided not to be configurable
  - Removed a duplicate dependency was pointed out by IDEA

Modified Paths:
--------------
    hippo-cms7/cms/trunk/config/src/main/resources/cms-services.xml
    hippo-cms7/cms/trunk/engine/pom.xml
    
hippo-cms7/cms/trunk/engine/src/main/java/org/hippoecm/frontend/service/restproxy/RestProxyServicePlugin.java
    hippo-cms7/cms/trunk/pom.xml

Modified: hippo-cms7/cms/trunk/config/src/main/resources/cms-services.xml
===================================================================
--- hippo-cms7/cms/trunk/config/src/main/resources/cms-services.xml     
2012-11-26 11:58:24 UTC (rev 37177)
+++ hippo-cms7/cms/trunk/config/src/main/resources/cms-services.xml     
2012-11-26 12:46:20 UTC (rev 37178)
@@ -74,9 +74,6 @@
     <sv:property sv:name="ping.service.uri" sv:type="String">
       <sv:value>/sites/#areAlive</sv:value>
     </sv:property>
-    <sv:property sv:name="ping.service.timeout" sv:type="Long">
-      <sv:value>1000</sv:value>
-    </sv:property>
     <sv:property sv:name="service.id" sv:type="String">
       <sv:value>hst.rest.proxy.service</sv:value>
     </sv:property>

Modified: hippo-cms7/cms/trunk/engine/pom.xml
===================================================================
--- hippo-cms7/cms/trunk/engine/pom.xml 2012-11-26 11:58:24 UTC (rev 37177)
+++ hippo-cms7/cms/trunk/engine/pom.xml 2012-11-26 12:46:20 UTC (rev 37178)
@@ -102,10 +102,9 @@
       <artifactId>jackson-xc</artifactId>
     </dependency>
     <dependency>
-      <groupId>commons-httpclient</groupId>
-      <artifactId>commons-httpclient</artifactId>
+      <groupId>org.apache.httpcomponents</groupId>
+      <artifactId>httpclient</artifactId>
     </dependency>
-
     <dependency>
       <groupId>org.apache.wicket</groupId>
       <artifactId>wicket</artifactId>
@@ -127,10 +126,6 @@
     </dependency>
     <dependency>
       <groupId>org.onehippo.cms7</groupId>
-      <artifactId>hippo-cms7-commons</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.onehippo.cms7</groupId>
       <artifactId>hippo-services</artifactId>
     </dependency>
 

Modified: 
hippo-cms7/cms/trunk/engine/src/main/java/org/hippoecm/frontend/service/restproxy/RestProxyServicePlugin.java
===================================================================
--- 
hippo-cms7/cms/trunk/engine/src/main/java/org/hippoecm/frontend/service/restproxy/RestProxyServicePlugin.java
       2012-11-26 11:58:24 UTC (rev 37177)
+++ 
hippo-cms7/cms/trunk/engine/src/main/java/org/hippoecm/frontend/service/restproxy/RestProxyServicePlugin.java
       2012-11-26 12:46:20 UTC (rev 37178)
@@ -6,8 +6,6 @@
 import java.net.URLEncoder;
 import java.nio.charset.Charset;
 import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
@@ -17,15 +15,18 @@
 import javax.security.auth.Subject;
 import javax.ws.rs.core.MediaType;
 
-import org.apache.commons.httpclient.HttpClient;
-import org.apache.commons.httpclient.HttpException;
-import org.apache.commons.httpclient.HttpMethod;
-import org.apache.commons.httpclient.HttpStatus;
-import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
-import org.apache.commons.httpclient.methods.GetMethod;
 import org.apache.cxf.common.util.StringUtils;
 import org.apache.cxf.jaxrs.client.JAXRSClientFactory;
 import org.apache.cxf.jaxrs.client.WebClient;
+import org.apache.http.HttpResponse;
+import org.apache.http.HttpStatus;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
+import org.apache.http.params.CoreConnectionPNames;
+import org.apache.http.protocol.BasicHttpContext;
+import org.apache.http.protocol.HttpContext;
 import org.codehaus.jackson.Version;
 import org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider;
 import org.codehaus.jackson.map.ObjectMapper;
@@ -59,7 +60,6 @@
     public static final String CONFIG_SERVICE_ID = "service.id";
     public static final String DEFAULT_SERVICE_ID = 
IRestProxyService.class.getName();
     public static final String PING_SERVICE_URI = "ping.service.uri";
-    public static final String PING_SERVICE_TIMEOUT = "ping.service.timeout";
 
     private static final long serialVersionUID = 1L;
     private static final JacksonJaxbJsonProvider defaultJJJProvider;
@@ -85,11 +85,14 @@
 
     protected static HttpClient httpClient = null;
     static {
-        MultiThreadedHttpConnectionManager mgr = new 
MultiThreadedHttpConnectionManager();
-        mgr.getParams().setDefaultMaxConnectionsPerHost(MAX_CONNECTIONS);
-        mgr.getParams().setMaxTotalConnections(MAX_CONNECTIONS);
-        mgr.getParams().setConnectionTimeout(PING_SERVLET_TIMEOUT);
-        httpClient = new HttpClient(mgr);
+        ThreadSafeClientConnManager mgr = new ThreadSafeClientConnManager();
+        mgr.setDefaultMaxPerRoute(MAX_CONNECTIONS);
+        mgr.setMaxTotal(MAX_CONNECTIONS);
+        httpClient = new DefaultHttpClient(mgr);
+        // @see 
http://hc.apache.org/httpcomponents-client-ga/tutorial/html/connmgmt.html#d5e399
+        
httpClient.getParams().setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 
PING_SERVLET_TIMEOUT);
+        
httpClient.getParams().setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 
PING_SERVLET_TIMEOUT);
+        
httpClient.getParams().setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK,
 false);
     }
 
     public RestProxyServicePlugin(IPluginContext context, IPluginConfig 
config) {
@@ -221,7 +224,8 @@
         String normalizedPingServiceUri = "";
 
         // Check whether the site is up and running or not
-        HttpMethod method = null;
+        HttpGet httpGet = null;
+
         try {
             // Make sure that it is URL encoded correctly, except for the '/' 
and ':' characters
             normalizedPingServiceUri = URLEncoder.encode(pingServiceUri, 
Charset.defaultCharset().name())
@@ -229,17 +233,11 @@
 
             // Set the timeout for the HTTP connection in milliseconds, if the 
configuration parameter is missing or not set
             // use default value of 1 second
-            method = new GetMethod(normalizedPingServiceUri);
-            final int responceCode = httpClient.executeMethod(method);
-            siteIsAlive = (responceCode == HttpStatus.SC_OK);
-        } catch (HttpException httpex) {
-            if (log.isDebugEnabled()) {
-                log.warn("Error while pinging site using URI " + 
normalizedPingServiceUri, httpex);
-            } else {
-                log.warn("Error while pinging site using URI {} - {}", 
normalizedPingServiceUri, httpex.toString());
-            }
-
-            siteIsAlive = false;
+            httpGet = new HttpGet(normalizedPingServiceUri);
+            // @see 
http://hc.apache.org/httpcomponents-client-ga/tutorial/html/connmgmt.html#d5e639
+            final HttpContext httpContext = new BasicHttpContext();
+            final HttpResponse httpResponse = httpClient.execute(httpGet, 
httpContext);
+            siteIsAlive = (httpResponse.getStatusLine().getStatusCode() == 
HttpStatus.SC_OK);
         } catch (UnsupportedEncodingException usence) {
             if (log.isDebugEnabled()) {
                 log.warn("Error while pinging site using URI " + 
normalizedPingServiceUri, usence);
@@ -257,8 +255,8 @@
 
             siteIsAlive = false;
         } finally {
-            if (method != null) {
-                method.releaseConnection();
+            if (httpGet != null) {
+                httpGet.abort();
             }
         }
 

Modified: hippo-cms7/cms/trunk/pom.xml
===================================================================
--- hippo-cms7/cms/trunk/pom.xml        2012-11-26 11:58:24 UTC (rev 37177)
+++ hippo-cms7/cms/trunk/pom.xml        2012-11-26 12:46:20 UTC (rev 37178)
@@ -418,18 +418,6 @@
         </exclusions>
       </dependency>
       <dependency>
-        <groupId>commons-httpclient</groupId>
-        <artifactId>commons-httpclient</artifactId>
-        <version>${commons-httpclient.version}</version>
-        <!-- JCR-683: Exclude bad transitive dependencies -->
-        <exclusions>
-          <exclusion>
-            <groupId>junit</groupId>
-            <artifactId>junit</artifactId>
-          </exclusion>
-        </exclusions>
-      </dependency>
-      <dependency>
         <groupId>org.apache.httpcomponents</groupId>
         <artifactId>httpclient</artifactId>
         <version>${httpclient.version}</version>

_______________________________________________
Hippocms-svn mailing list
[email protected]
https://lists.onehippo.org/mailman/listinfo/hippocms-svn

Reply via email to