manifoldcf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kwri...@apache.org
Subject svn commit: r1449391 - in /manifoldcf/branches/CONNECTORS-63/framework: api-servlet/src/main/java/org/apache/manifoldcf/apiservlet/APIServlet.java pull-agent/src/main/java/org/apache/manifoldcf/crawler/system/ManifoldCF.java
Date Sat, 23 Feb 2013 19:12:09 GMT
Author: kwright
Date: Sat Feb 23 19:12:08 2013
New Revision: 1449391

URL: http://svn.apache.org/r1449391
Log:
Hook up query string parsing, and pass parsed query string into API read method.

Modified:
    manifoldcf/branches/CONNECTORS-63/framework/api-servlet/src/main/java/org/apache/manifoldcf/apiservlet/APIServlet.java
    manifoldcf/branches/CONNECTORS-63/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/system/ManifoldCF.java

Modified: manifoldcf/branches/CONNECTORS-63/framework/api-servlet/src/main/java/org/apache/manifoldcf/apiservlet/APIServlet.java
URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-63/framework/api-servlet/src/main/java/org/apache/manifoldcf/apiservlet/APIServlet.java?rev=1449391&r1=1449390&r2=1449391&view=diff
==============================================================================
--- manifoldcf/branches/CONNECTORS-63/framework/api-servlet/src/main/java/org/apache/manifoldcf/apiservlet/APIServlet.java
(original)
+++ manifoldcf/branches/CONNECTORS-63/framework/api-servlet/src/main/java/org/apache/manifoldcf/apiservlet/APIServlet.java
Sat Feb 23 19:12:08 2013
@@ -43,37 +43,12 @@ public class APIServlet extends HttpServ
     throws ServletException
   {
     super.init(config);
-/*
-    try
-    {
-      // Set up the environment
-      ManifoldCF.initializeEnvironment();
-      // Nothing more needs to be done at this point.
-    }
-    catch (ManifoldCFException e)
-    {
-      Logging.misc.error("Error starting API service: "+e.getMessage(),e);
-      throw new ServletException("Error starting API service: "+e.getMessage(),e);
-    }
-*/
   }
 
   /** The destroy method.
   */
   public void destroy()
   {
-/*
-    try
-    {
-      // Set up the environment
-      ManifoldCF.initializeEnvironment();
-      // Nothing more needs to be done.
-    }
-    catch (ManifoldCFException e)
-    {
-      Logging.misc.error("Error shutting down API service: "+e.getMessage(),e);
-    }
-*/
     super.destroy();
   }
 
@@ -84,14 +59,13 @@ public class APIServlet extends HttpServ
   {
     try
     {
-      // Set up the environment
-      //ManifoldCF.initializeEnvironment();
-
       // Mint a thread context
       IThreadContext tc = ThreadContextFactory.make();
       
       // Get the path info string.  This will furnish the command.
       String pathInfo = request.getPathInfo();
+      // Get query string.  This is used by some GET operations.
+      String queryString = request.getQueryString();
       
       if (pathInfo == null)
       {
@@ -100,7 +74,7 @@ public class APIServlet extends HttpServ
       }
 
       // Perform the deletion
-      executeRead(tc,response,pathInfo);
+      executeRead(tc,response,pathInfo,queryString);
       
     }
     catch (ManifoldCFException e)
@@ -118,9 +92,6 @@ public class APIServlet extends HttpServ
   {
     try
     {
-      // Set up the environment
-      //ManifoldCF.initializeEnvironment();
-
       // Mint a thread context
       IThreadContext tc = ThreadContextFactory.make();
       
@@ -161,9 +132,6 @@ public class APIServlet extends HttpServ
   {
     try
     {
-      // Set up the environment
-      //ManifoldCF.initializeEnvironment();
-
       // Mint a thread context
       IThreadContext tc = ThreadContextFactory.make();
       
@@ -204,9 +172,6 @@ public class APIServlet extends HttpServ
   {
     try
     {
-      // Set up the environment
-      //ManifoldCF.initializeEnvironment();
-
       // Mint a thread context
       IThreadContext tc = ThreadContextFactory.make();
       
@@ -235,7 +200,7 @@ public class APIServlet extends HttpServ
   
   /** Perform a general "read" operation.
   */
-  protected static void executeRead(IThreadContext tc, HttpServletResponse response, String
pathInfo)
+  protected static void executeRead(IThreadContext tc, HttpServletResponse response, String
pathInfo, String queryString)
     throws ManifoldCFException, IOException
   {
     // Strip off leading "/"
@@ -256,12 +221,15 @@ public class APIServlet extends HttpServ
       command = pathInfo.substring(index+1);
     }
 
+    // If query string exists, parse it
+    Map<String,List<String>> queryParameters = parseQueryString(queryString);
+    
     // Execute the request.
     // Since there are no input arguments, we can do this before we look at the protocol.
     
     // There the only response distinction we have here is between exception and no exception.
     Configuration output = new Configuration();
-    boolean exists = ManifoldCF.executeReadCommand(tc,output,command);
+    boolean exists = ManifoldCF.executeReadCommand(tc,output,command,queryParameters);
     
     // Output
     
@@ -612,4 +580,33 @@ public class APIServlet extends HttpServ
     // return code 200 assumed!
   }
   
+  protected static Map<String,List<String>> parseQueryString(String queryString)
+    throws UnsupportedEncodingException
+  {
+    if (queryString == null)
+      return null;
+    Map<String,List<String>> rval = new HashMap<String,List<String>>();
+    String[] terms = queryString.split("&");
+    for (String term : terms)
+    {
+      int index = queryString.indexOf("=");
+      if (index == -1)
+        addValue(rval,URLDecoder.decode(term,"utf-8"),"");
+      else
+        addValue(rval,URLDecoder.decode(term.substring(0,index),"utf-8"),URLDecoder.decode(term.substring(index+1),"utf-8"));
+    }
+    return rval;
+  }
+  
+  protected static void addValue(Map<String,List<String>> rval, String name,
String value)
+  {
+    List<String> valueList = rval.get(name);
+    if (valueList == null)
+    {
+      valueList = new ArrayList<String>(1);
+      rval.put(name,valueList);
+    }
+    valueList.add(value);
+  }
+  
 }

Modified: manifoldcf/branches/CONNECTORS-63/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/system/ManifoldCF.java
URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-63/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/system/ManifoldCF.java?rev=1449391&r1=1449390&r2=1449391&view=diff
==============================================================================
--- manifoldcf/branches/CONNECTORS-63/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/system/ManifoldCF.java
(original)
+++ manifoldcf/branches/CONNECTORS-63/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/system/ManifoldCF.java
Sat Feb 23 19:12:08 2013
@@ -2220,8 +2220,8 @@ public class ManifoldCF extends org.apac
   *@param path is the object path.
   *@return true if the resource exists, false otherwise.
   */
-  public static boolean executeReadCommand(IThreadContext tc, Configuration output, String
path)
-    throws ManifoldCFException
+  public static boolean executeReadCommand(IThreadContext tc, Configuration output, String
path,
+    Map<String,List<String>> queryParameters) throws ManifoldCFException
   {
     if (path.equals("jobs"))
     {



Mime
View raw message