You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@manifoldcf.apache.org by kw...@apache.org on 2013/03/07 13:34:35 UTC

svn commit: r1453815 - in /manifoldcf/integration/solr-4.x/trunk/mcf/src/java/org/apache/solr/mcf: ManifoldCFQParserPlugin.java ManifoldCFSearchComponent.java

Author: kwright
Date: Thu Mar  7 12:34:35 2013
New Revision: 1453815

URL: http://svn.apache.org/r1453815
Log:
Add connection timeout, and abort connection on error.

Modified:
    manifoldcf/integration/solr-4.x/trunk/mcf/src/java/org/apache/solr/mcf/ManifoldCFQParserPlugin.java
    manifoldcf/integration/solr-4.x/trunk/mcf/src/java/org/apache/solr/mcf/ManifoldCFSearchComponent.java

Modified: manifoldcf/integration/solr-4.x/trunk/mcf/src/java/org/apache/solr/mcf/ManifoldCFQParserPlugin.java
URL: http://svn.apache.org/viewvc/manifoldcf/integration/solr-4.x/trunk/mcf/src/java/org/apache/solr/mcf/ManifoldCFQParserPlugin.java?rev=1453815&r1=1453814&r2=1453815&view=diff
==============================================================================
--- manifoldcf/integration/solr-4.x/trunk/mcf/src/java/org/apache/solr/mcf/ManifoldCFQParserPlugin.java (original)
+++ manifoldcf/integration/solr-4.x/trunk/mcf/src/java/org/apache/solr/mcf/ManifoldCFQParserPlugin.java Thu Mar  7 12:34:35 2013
@@ -49,7 +49,7 @@ import org.apache.http.params.CoreConnec
 import org.apache.http.util.EntityUtils;
 import org.apache.http.impl.client.DefaultHttpClient;
 import org.apache.http.impl.client.DefaultRedirectStrategy;
-import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
+import org.apache.http.impl.conn.PoolingClientConnectionManager;
 import org.slf4j.*;
 
 import java.io.*;
@@ -85,9 +85,10 @@ public class ManifoldCFQParserPlugin ext
   String fieldDenyDocument = null;
   String fieldAllowShare = null;
   String fieldDenyShare = null;
+  int connectionTimeOut;
   int socketTimeOut;
   Integer connectionManagerSynchronizer = new Integer(0);
-  ThreadSafeClientConnManager httpConnectionManager = null;
+  PoolingClientConnectionManager httpConnectionManager = null;
   DefaultHttpClient client = null;
   int poolSize;
   
@@ -102,6 +103,8 @@ public class ManifoldCFQParserPlugin ext
     authorityBaseURL = (String)args.get("AuthorityServiceBaseURL");
     if (authorityBaseURL == null)
       authorityBaseURL = "http://localhost:8345/mcf-authority-service";
+    Integer cTimeOut = (Integer)args.get("ConnectionTimeOut");
+    connectionTimeOut = cTimeOut == null ? 60000 : cTimeOut;
     Integer timeOut = (Integer)args.get("SocketTimeOut");
     socketTimeOut = timeOut == null ? 300000 : timeOut;
     String allowAttributePrefix = (String)args.get("AllowAttributePrefix");
@@ -125,13 +128,14 @@ public class ManifoldCFQParserPlugin ext
       if (client == null)
       {
         // Initialize the connection pool
-        httpConnectionManager = new ThreadSafeClientConnManager();
+        httpConnectionManager = new PoolingClientConnectionManager();
         httpConnectionManager.setMaxTotal(poolSize);
         httpConnectionManager.setDefaultMaxPerRoute(poolSize);
         BasicHttpParams params = new BasicHttpParams();
         params.setBooleanParameter(CoreConnectionPNames.TCP_NODELAY,true);
         params.setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK,false);
         params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT,socketTimeOut);
+        params.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT,connectionTimeOut);
         client = new DefaultHttpClient(httpConnectionManager,params);
         client.setRedirectStrategy(new DefaultRedirectStrategy());
         core.addCloseHook(new CloseHandler());
@@ -278,7 +282,7 @@ public class ManifoldCFQParserPlugin ext
         int rval = httpResponse.getStatusLine().getStatusCode();
         if (rval != 200)
         {
-          String response = EntityUtils.toString(httpResponse.getEntity(),null);
+          String response = EntityUtils.toString(httpResponse.getEntity(),"utf-8");
           throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,"Couldn't fetch user's access tokens from ManifoldCF authority service: "+Integer.toString(rval)+"; "+response);
         }
         InputStream is = httpResponse.getEntity().getContent();
@@ -329,7 +333,7 @@ public class ManifoldCFQParserPlugin ext
       }
       finally
       {
-        //method.releaseConnection();
+        method.abort();
       }
     }
   }

Modified: manifoldcf/integration/solr-4.x/trunk/mcf/src/java/org/apache/solr/mcf/ManifoldCFSearchComponent.java
URL: http://svn.apache.org/viewvc/manifoldcf/integration/solr-4.x/trunk/mcf/src/java/org/apache/solr/mcf/ManifoldCFSearchComponent.java?rev=1453815&r1=1453814&r2=1453815&view=diff
==============================================================================
--- manifoldcf/integration/solr-4.x/trunk/mcf/src/java/org/apache/solr/mcf/ManifoldCFSearchComponent.java (original)
+++ manifoldcf/integration/solr-4.x/trunk/mcf/src/java/org/apache/solr/mcf/ManifoldCFSearchComponent.java Thu Mar  7 12:34:35 2013
@@ -41,7 +41,7 @@ import org.apache.http.params.CoreConnec
 import org.apache.http.util.EntityUtils;
 import org.apache.http.impl.client.DefaultHttpClient;
 import org.apache.http.impl.client.DefaultRedirectStrategy;
-import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
+import org.apache.http.impl.conn.PoolingClientConnectionManager;
 import org.slf4j.*;
 
 import java.io.*;
@@ -78,8 +78,9 @@ public class ManifoldCFSearchComponent e
   String fieldDenyDocument = null;
   String fieldAllowShare = null;
   String fieldDenyShare = null;
+  int connectionTimeOut;
   int socketTimeOut;
-  ThreadSafeClientConnManager httpConnectionManager = null;
+  PoolingClientConnectionManager httpConnectionManager = null;
   DefaultHttpClient client = null;
   int poolSize;
   
@@ -98,6 +99,8 @@ public class ManifoldCFSearchComponent e
       System.out.println("USING DEFAULT BASE URL!!");
       authorityBaseURL = "http://localhost:8345/mcf-authority-service";
     }
+    Integer cTimeOut = (Integer)args.get("ConnectionTimeOut");
+    connectionTimeOut = cTimeOut == null ? 60000 : cTimeOut;
     Integer timeOut = (Integer)args.get("SocketTimeOut");
     socketTimeOut = timeOut == null ? 300000 : timeOut;
     String allowAttributePrefix = (String)args.get("AllowAttributePrefix");
@@ -114,13 +117,14 @@ public class ManifoldCFSearchComponent e
     poolSize = (connectionPoolSize==null)?50:connectionPoolSize.intValue();
 
     // Initialize the connection pool
-    httpConnectionManager = new ThreadSafeClientConnManager();
+    httpConnectionManager = new PoolingClientConnectionManager();
     httpConnectionManager.setMaxTotal(poolSize);
     httpConnectionManager.setDefaultMaxPerRoute(poolSize);
     BasicHttpParams params = new BasicHttpParams();
     params.setBooleanParameter(CoreConnectionPNames.TCP_NODELAY,true);
     params.setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK,false);
     params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT,socketTimeOut);
+    params.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT,connectionTimeOut);
     client = new DefaultHttpClient(httpConnectionManager,params);
     client.setRedirectStrategy(new DefaultRedirectStrategy());
   }
@@ -301,7 +305,7 @@ public class ManifoldCFSearchComponent e
       int rval = httpResponse.getStatusLine().getStatusCode();
       if (rval != 200)
       {
-        String response = EntityUtils.toString(httpResponse.getEntity(),null);
+        String response = EntityUtils.toString(httpResponse.getEntity(),"utf-8");
         throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,"Couldn't fetch user's access tokens from ManifoldCF authority service: "+Integer.toString(rval)+"; "+response);
       }
       InputStream is = httpResponse.getEntity().getContent();
@@ -352,7 +356,7 @@ public class ManifoldCFSearchComponent e
     }
     finally
     {
-      //method.releaseConnection();
+      method.abort();
     }
   }