incubator-connectors-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kwri...@apache.org
Subject svn commit: r1243916 - in /incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine: DELETECommand.java GETCommand.java POSTCommand.java PUTCommand.java ScriptParser.java
Date Tue, 14 Feb 2012 13:42:28 GMT
Author: kwright
Date: Tue Feb 14 13:42:28 2012
New Revision: 1243916

URL: http://svn.apache.org/viewvc?rev=1243916&view=rev
Log:
Partial fix for CONNECTORS-406.  Use multithreaded connection manager for script engine.

Modified:
    incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/DELETECommand.java
    incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/GETCommand.java
    incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/POSTCommand.java
    incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/PUTCommand.java
    incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/ScriptParser.java

Modified: incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/DELETECommand.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/DELETECommand.java?rev=1243916&r1=1243915&r2=1243916&view=diff
==============================================================================
--- incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/DELETECommand.java
(original)
+++ incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/DELETECommand.java
Tue Feb 14 13:42:28 2012
@@ -50,17 +50,24 @@ public class DELETECommand implements Co
     
     try
     {
-      HttpClient client = new HttpClient();
+      HttpClient client = sp.getHttpClient();
       DeleteMethod method = new DeleteMethod(urlString);
-      int resultCode = client.executeMethod(method);
-      byte[] responseData = method.getResponseBody();
-      // We presume that the data is utf-8, since that's what the API
-      // uses throughout.
-      String resultJSON = new String(responseData,"utf-8");
+      try
+      {
+        int resultCode = client.executeMethod(method);
+        byte[] responseData = method.getResponseBody();
+        // We presume that the data is utf-8, since that's what the API
+        // uses throughout.
+        String resultJSON = new String(responseData,"utf-8");
 
-      result.setReference(new VariableResult(resultCode,resultJSON));
-    
-      return false;
+        result.setReference(new VariableResult(resultCode,resultJSON));
+      
+        return false;
+      }
+      finally
+      {
+        method.releaseConnection();
+      }
     }
     catch (IOException e)
     {

Modified: incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/GETCommand.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/GETCommand.java?rev=1243916&r1=1243915&r2=1243916&view=diff
==============================================================================
--- incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/GETCommand.java
(original)
+++ incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/GETCommand.java
Tue Feb 14 13:42:28 2012
@@ -50,17 +50,24 @@ public class GETCommand implements Comma
     
     try
     {
-      HttpClient client = new HttpClient();
+      HttpClient client = sp.getHttpClient();
       GetMethod method = new GetMethod(urlString);
-      int resultCode = client.executeMethod(method);
-      byte[] responseData = method.getResponseBody();
-      // We presume that the data is utf-8, since that's what the API
-      // uses throughout.
-      String resultJSON = new String(responseData,"utf-8");
+      try
+      {
+        int resultCode = client.executeMethod(method);
+        byte[] responseData = method.getResponseBody();
+        // We presume that the data is utf-8, since that's what the API
+        // uses throughout.
+        String resultJSON = new String(responseData,"utf-8");
 
-      result.setReference(new VariableResult(resultCode,resultJSON));
-    
-      return false;
+        result.setReference(new VariableResult(resultCode,resultJSON));
+      
+        return false;
+      }
+      finally
+      {
+        method.releaseConnection();
+      }
     }
     catch (IOException e)
     {

Modified: incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/POSTCommand.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/POSTCommand.java?rev=1243916&r1=1243915&r2=1243916&view=diff
==============================================================================
--- incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/POSTCommand.java
(original)
+++ incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/POSTCommand.java
Tue Feb 14 13:42:28 2012
@@ -60,19 +60,26 @@ public class POSTCommand implements Comm
     try
     {
       String json = configuration.toJSON();
-      HttpClient client = new HttpClient();
+      HttpClient client = sp.getHttpClient();
       PostMethod method = new PostMethod(urlString);
-      method.setRequestHeader("Content-type", "text/plain; charset=UTF-8");
-      method.setRequestBody(json);
-      int resultCode = client.executeMethod(method);
-      byte[] responseData = method.getResponseBody();
-      // We presume that the data is utf-8, since that's what the API
-      // uses throughout.
-      String resultJSON = new String(responseData,"utf-8");
+      try
+      {
+        method.setRequestHeader("Content-type", "text/plain; charset=UTF-8");
+        method.setRequestBody(json);
+        int resultCode = client.executeMethod(method);
+        byte[] responseData = method.getResponseBody();
+        // We presume that the data is utf-8, since that's what the API
+        // uses throughout.
+        String resultJSON = new String(responseData,"utf-8");
 
-      result.setReference(new VariableResult(resultCode,resultJSON));
-    
-      return false;
+        result.setReference(new VariableResult(resultCode,resultJSON));
+      
+        return false;
+      }
+      finally
+      {
+        method.releaseConnection();
+      }
     }
     catch (ManifoldCFException e)
     {

Modified: incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/PUTCommand.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/PUTCommand.java?rev=1243916&r1=1243915&r2=1243916&view=diff
==============================================================================
--- incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/PUTCommand.java
(original)
+++ incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/PUTCommand.java
Tue Feb 14 13:42:28 2012
@@ -60,19 +60,26 @@ public class PUTCommand implements Comma
     try
     {
       String json = configuration.toJSON();
-      HttpClient client = new HttpClient();
+      HttpClient client = sp.getHttpClient();
       PutMethod method = new PutMethod(urlString);
-      method.setRequestHeader("Content-type", "text/plain; charset=UTF-8");
-      method.setRequestBody(json);
-      int resultCode = client.executeMethod(method);
-      byte[] responseData = method.getResponseBody();
-      // We presume that the data is utf-8, since that's what the API
-      // uses throughout.
-      String resultJSON = new String(responseData,"utf-8");
+      try
+      {
+        method.setRequestHeader("Content-type", "text/plain; charset=UTF-8");
+        method.setRequestBody(json);
+        int resultCode = client.executeMethod(method);
+        byte[] responseData = method.getResponseBody();
+        // We presume that the data is utf-8, since that's what the API
+        // uses throughout.
+        String resultJSON = new String(responseData,"utf-8");
 
-      result.setReference(new VariableResult(resultCode,resultJSON));
-    
-      return false;
+        result.setReference(new VariableResult(resultCode,resultJSON));
+      
+        return false;
+      }
+      finally
+      {
+        method.releaseConnection();
+      }
     }
     catch (ManifoldCFException e)
     {

Modified: incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/ScriptParser.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/ScriptParser.java?rev=1243916&r1=1243915&r2=1243916&view=diff
==============================================================================
--- incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/ScriptParser.java
(original)
+++ incubator/lcf/trunk/framework/script-engine/src/main/java/org/apache/manifoldcf/scriptengine/ScriptParser.java
Tue Feb 14 13:42:28 2012
@@ -19,6 +19,7 @@
 
 package org.apache.manifoldcf.scriptengine;
 
+import org.apache.commons.httpclient.*;
 import java.util.*;
 import java.io.*;
 
@@ -26,6 +27,15 @@ import java.io.*;
 */
 public class ScriptParser
 {
+  /** The connection manager. */
+  protected HttpConnectionManager connectionManager = null;
+  
+  /** The client instance */
+  protected HttpClient httpClient = null;
+  
+  /** The lock for the httpclient factory */
+  protected Integer httpClientLock = new Integer(0);
+  
   /** The current variable context. */
   protected Map<String,ContextVariableReference> context = new HashMap<String,ContextVariableReference>();
   
@@ -1131,6 +1141,18 @@ public class ScriptParser
       t.throwException(message + ": "+t);
   }
   
+  public HttpClient getHttpClient()
+  {
+    synchronized (httpClientLock)
+    {
+      if (httpClient == null)
+      {
+        connectionManager = new MultiThreadedHttpConnectionManager();
+        httpClient = new HttpClient(connectionManager);
+      }
+    }
+    return httpClient;
+  }
   
   public static void main(String[] argv)
   {



Mime
View raw message