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 2010/07/21 17:32:54 UTC

svn commit: r966280 - in /incubator/lcf/trunk/modules/framework: api/org/apache/lcf/api/APIServlet.java core/org/apache/lcf/core/interfaces/Configuration.java

Author: kwright
Date: Wed Jul 21 15:32:53 2010
New Revision: 966280

URL: http://svn.apache.org/viewvc?rev=966280&view=rev
Log:
Improve API servlet error logging.  Also fix problem with alternate reordering case, introduced yesterday.

Modified:
    incubator/lcf/trunk/modules/framework/api/org/apache/lcf/api/APIServlet.java
    incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/interfaces/Configuration.java

Modified: incubator/lcf/trunk/modules/framework/api/org/apache/lcf/api/APIServlet.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/modules/framework/api/org/apache/lcf/api/APIServlet.java?rev=966280&r1=966279&r2=966280&view=diff
==============================================================================
--- incubator/lcf/trunk/modules/framework/api/org/apache/lcf/api/APIServlet.java (original)
+++ incubator/lcf/trunk/modules/framework/api/org/apache/lcf/api/APIServlet.java Wed Jul 21 15:32:53 2010
@@ -138,7 +138,18 @@ public class APIServlet extends HttpServ
         Configuration output = LCF.executeCommand(tc,command,input);
           
         // Format the response
-        outputText = output.toJSON();
+        try
+        {
+          outputText = output.toJSON();
+        }
+        catch (LCFException e)
+        {
+          // Log it
+          Logging.api.error("Error forming JSON response: "+e.getMessage(),e);
+          // Internal server error
+          response.sendError(response.SC_INTERNAL_SERVER_ERROR);
+          return;
+        }
       }
       else
       {
@@ -170,7 +181,6 @@ public class APIServlet extends HttpServ
     catch (LCFException e)
     {
       // We should only see this error if there's an API problem, not if there's an actual problem with the method being called.
-      //Logging.authorityService.error("API servlet error: "+e.getMessage(),e);
       response.sendError(response.SC_BAD_REQUEST,e.getMessage());
     }
   }

Modified: incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/interfaces/Configuration.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/interfaces/Configuration.java?rev=966280&r1=966279&r2=966280&view=diff
==============================================================================
--- incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/interfaces/Configuration.java (original)
+++ incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/interfaces/Configuration.java Wed Jul 21 15:32:53 2010
@@ -212,11 +212,7 @@ public class Configuration
         while (i < getChildCount())
         {
           ConfigurationNode child = findChild(i++);
-          writer.object();
-          writer.key(JSON_TYPE);
-          writer.value(child.getType());
-          writeNode(writer,child,false);
-          writer.endObject();
+          writeNode(writer,child,false,true);
         }
         writer.endArray();
       }
@@ -240,14 +236,14 @@ public class Configuration
             while (i < list.size())
             {
               ConfigurationNode child = (ConfigurationNode)list.get(i++);
-              writeNode(writer,child,false);
+              writeNode(writer,child,false,false);
             }
             writer.endArray();
           }
           else
           {
             // Write it as a singleton
-            writeNode(writer,(ConfigurationNode)list.get(0),true);
+            writeNode(writer,(ConfigurationNode)list.get(0),true,false);
           }
         }
       }
@@ -300,7 +296,7 @@ public class Configuration
   *@param node is the node.
   *@param writeKey is true if the key needs to be written, false otherwise.
   */
-  protected static void writeNode(JSONWriter writer, ConfigurationNode node, boolean writeKey)
+  protected static void writeNode(JSONWriter writer, ConfigurationNode node, boolean writeKey, boolean writeSpecialKey)
     throws LCFException
   {
     try
@@ -312,6 +308,13 @@ public class Configuration
         String type = node.getType();
         writer.key(type);
       }
+      else if (writeSpecialKey)
+      {
+        writer.object();
+        writer.key(JSON_TYPE);
+        writer.value(node.getType());
+      }
+      
       // Problem: Two ways of handling a naked 'value'.  First way is to NOT presume a nested object is needed.  Second way is to require a nested
       // object.  On reconstruction, the right thing will happen, and a naked value will become a node with a value, while an object will become
       // a node that has an optional "_value_" key inside it.
@@ -322,7 +325,8 @@ public class Configuration
       }
       else
       {
-        writer.object();
+        if (!writeSpecialKey)
+          writer.object();
         
         if (value != null)
         {
@@ -382,11 +386,7 @@ public class Configuration
           while (i < node.getChildCount())
           {
             ConfigurationNode child = node.findChild(i++);
-            writer.object();
-            writer.key(JSON_TYPE);
-            writer.value(child.getType());
-            writeNode(writer,child,false);
-            writer.endObject();
+            writeNode(writer,child,false,true);
           }
           writer.endArray();
         }
@@ -410,19 +410,22 @@ public class Configuration
               while (i < list.size())
               {
                 ConfigurationNode child = (ConfigurationNode)list.get(i++);
-                writeNode(writer,child,false);
+                writeNode(writer,child,false,false);
               }
               writer.endArray();
             }
             else
             {
               // Write it as a singleton
-              writeNode(writer,(ConfigurationNode)list.get(0),true);
+              writeNode(writer,(ConfigurationNode)list.get(0),true,false);
             }
           }
         }
-        writer.endObject();
+        if (!writeSpecialKey)
+          writer.endObject();
       }
+      if (writeSpecialKey)
+        writer.endObject();
     }
     catch (JSONException e)
     {