Coverage Report - org.apache.turbine.services.jsonrpc.JSONProcessor
 
Classes in this File Line Coverage Branch Coverage Complexity
JSONProcessor
0%
0/22
0%
0/6
5
 
 1  
 package org.apache.turbine.services.jsonrpc;
 2  
 
 3  
 import java.io.CharArrayWriter;
 4  
 
 5  
 import javax.servlet.http.HttpServletRequest;
 6  
 
 7  
 import org.apache.commons.logging.Log;
 8  
 import org.apache.commons.logging.LogFactory;
 9  
 import org.jabsorb.JSONRPCBridge;
 10  
 import org.jabsorb.JSONRPCResult;
 11  
 import org.json.JSONArray;
 12  
 import org.json.JSONException;
 13  
 import org.json.JSONObject;
 14  
 
 15  
 /**
 16  
  * Process a JSON RPC call
 17  
  *
 18  
  * @author <a href="mailto:seade@backstagetech.com.au">Scott Eade</a>
 19  
  */
 20  0
 public class JSONProcessor
 21  
 {
 22  
     /** Log. */
 23  0
     private static Log log = LogFactory.getLog(JSONProcessor.class);
 24  
 
 25  
     /**
 26  
      * Process a JSON RPC call
 27  
      * @param cdata the JSON data
 28  
      * @param json_bridge the {@link JSONRPCBridge} object
 29  
      * @param request the request
 30  
      * @return the return object of the JSON RPC call
 31  
      */
 32  
     public static Object processCall(CharArrayWriter cdata, JSONRPCBridge json_bridge, HttpServletRequest request)
 33  
     {
 34  
         // Process the request
 35  0
         JSONObject json_req = null;
 36  0
         Object json_res = null;
 37  
         try
 38  
         {
 39  0
             json_req = new JSONObject(cdata.toString());
 40  0
             if (log.isDebugEnabled())
 41  
             {
 42  0
                 String methodName = json_req.getString("method");
 43  0
                 JSONArray arguments = json_req.getJSONArray("params");
 44  
 
 45  
                 // If this a CallableReference it will have a non-zero objectID
 46  0
                 int object_id = json_req.optInt("objectID");
 47  0
                 StringBuilder sb = new StringBuilder(".doprocessCall(): call ");
 48  0
                 if (object_id != 0)
 49  
                 {
 50  0
                     sb.append("objectID=").append(object_id).append(" ");
 51  
                 }
 52  0
                 sb.append(methodName).append("(").append(arguments).append(")");
 53  0
                 log.debug(sb.toString());
 54  
             }
 55  
             //json_res = json_bridge.call(new Object[] {request}, object_id, methodName, arguments);
 56  0
             json_res = json_bridge.call(new Object[] {request}, json_req);
 57  
         }
 58  0
         catch (JSONException e)
 59  
         {
 60  0
             log.error(".processCall(): can't parse call: " + cdata, e);
 61  0
             json_res = JSONRPCResult.MSG_ERR_PARSE;
 62  0
         }
 63  
         // Write the response
 64  0
         if (log.isDebugEnabled())
 65  
         {
 66  0
             log.debug(".processCall():  returns " + json_res.toString());
 67  
         }
 68  0
         return json_res;
 69  
     }
 70  
 
 71  
 }