My new ISP is for some reason unable to provide me with access to svn.apache.org, so here is a patch to the json-rpc service.

Mostly I wanted to tweak the debug statements and allow for character encodings, but I updated this to use jabsorb as well.

Note that jabsorb is not available from the regular maven repositories at this point in time, so I have deployed it to our very own special turbine repo.

If someone gets the chance can they please commit this for me.

Thanks,

Scott
Index: src/java/org/apache/turbine/services/jsonrpc/JsonRpcService.java
===================================================================
--- src/java/org/apache/turbine/services/jsonrpc/JsonRpcService.java    
(revision 669803)
+++ src/java/org/apache/turbine/services/jsonrpc/JsonRpcService.java    Fri Oct 
31 17:13:36 EST 2008
@@ -26,7 +26,7 @@
 
 import org.apache.turbine.services.Service;
 
-import com.metaparadigm.jsonrpc.JSONRPCBridge;
+import org.jabsorb.JSONRPCBridge;
 
 /**
  * The interface an JsonRpcService implements.
Index: xdocs/services/index.xml
===================================================================
--- xdocs/services/index.xml    (revision 669803)
+++ xdocs/services/index.xml    Fri Oct 31 23:30:25 EST 2008
@@ -115,7 +115,7 @@
 <a href="jsonrpc-service.html">JSON-RPC Service</a>
 <br/>
 The JSON-RPC Service supports JavaScript to Java AJAX communications using
-<a href="http://oss.metaparadigm.com/jsonrpc/";>JSON-RPC-Java</a>.
+<a href="http://jabsorb.org/";>jabsorb</a>.
 </li>
 
 <li>
Index: src/test/org/apache/turbine/services/jsonrpc/JsonrpcServicelTest.java
===================================================================
--- src/test/org/apache/turbine/services/jsonrpc/JsonrpcServicelTest.java       
(revision 669803)
+++ src/test/org/apache/turbine/services/jsonrpc/JsonrpcServicelTest.java       
Fri Oct 31 17:13:36 EST 2008
@@ -24,7 +24,7 @@
 
 import org.apache.turbine.test.BaseTurbineTest;
 
-import com.metaparadigm.jsonrpc.JSONRPCBridge;
+import org.jabsorb.JSONRPCBridge;
 
 
 public class JsonrpcServicelTest
Index: pom.xml
===================================================================
--- pom.xml     (revision 669803)
+++ pom.xml     Tue Nov 04 00:46:53 EST 2008
@@ -39,7 +39,7 @@
   <groupId>org.apache.turbine</groupId>
   <artifactId>turbine</artifactId>
   <name>turbine-2</name>
-  <version>2.3.3-b1</version>
+  <version>2.3.3-RC1</version>
   <description>Turbine is a servlet based framework that allows experienced 
Java
     developers to quickly build secure web applications. Parts of Turbine
     can also be used independently of the web portion of Turbine as
@@ -516,9 +516,9 @@
 <!--        <configuration/>-->
 <!--      </plugin>-->
       <plugin>
-        <groupId>torque</groupId>
-        <artifactId>maven-torque-plugin</artifactId>
-        <version>3.2</version>
+        <groupId>org.apache.torque</groupId>
+        <artifactId>torque-maven-plugin</artifactId>
+        <version>3.3</version>
         <configuration/>
       </plugin>
       <plugin>
@@ -767,9 +767,9 @@
       <optional>true</optional>
     </dependency>
     <dependency>
-      <groupId>com.metaparadigm</groupId>
-      <artifactId>json-rpc</artifactId>
-      <version>1.0</version>
+      <groupId>org.jabsorb</groupId>
+      <artifactId>jabsorb</artifactId>
+      <version>1.3</version>
       <type>jar</type>
       <scope>compile</scope>
       <optional>true</optional>
Index: src/java/org/apache/turbine/services/jsonrpc/JSONProcessor.java
===================================================================
--- src/java/org/apache/turbine/services/jsonrpc/JSONProcessor.java     
(revision 669803)
+++ src/java/org/apache/turbine/services/jsonrpc/JSONProcessor.java     Mon Nov 
03 23:50:48 EST 2008
@@ -1,7 +1,25 @@
 package org.apache.turbine.services.jsonrpc;
 
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
 import java.io.CharArrayWriter;
-import java.text.ParseException;
 
 import javax.servlet.http.HttpServletRequest;
 
@@ -9,10 +27,17 @@
 import org.apache.commons.logging.LogFactory;
 import org.json.JSONArray;
 import org.json.JSONObject;
+import org.json.JSONException;
 
-import com.metaparadigm.jsonrpc.JSONRPCBridge;
-import com.metaparadigm.jsonrpc.JSONRPCResult;
+import org.jabsorb.JSONRPCBridge;
+import org.jabsorb.JSONRPCResult;
 
+/**
+ * JSON call processor.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Scott Eade</a>
+ * @version $Id$
+ */
 public class JSONProcessor
 {
     /** Log. */
@@ -21,17 +46,22 @@
     public static Object processCall(CharArrayWriter cdata, JSONRPCBridge 
json_bridge, HttpServletRequest request)
     {
         // Process the request
+        String requestString = cdata.toString();
+        if (log.isDebugEnabled())
+        {
+            log.debug(".processCall() - requestString: " + requestString);
+        }
         JSONObject json_req = null;
         Object json_res = null;
         try
         {
-            json_req = new JSONObject(cdata.toString());
+            json_req = new JSONObject(requestString);
             if (log.isDebugEnabled())
             {
                 String methodName = (String) json_req.getString("method");
                 JSONArray arguments = json_req.getJSONArray("params");
                 
-                // If this a CallableReference it will have a non-zero objectID
+                // A CallableReference it will have a non-zero objectID
                 int object_id = json_req.optInt("objectID");
                 StringBuffer sb = new StringBuffer(".doprocessCall(): call ");
                 if (object_id != 0)
@@ -44,15 +74,15 @@
             //json_res = json_bridge.call(new Object[] {request}, object_id, 
methodName, arguments);
             json_res = json_bridge.call(new Object[] {request}, json_req);
         }
-        catch (ParseException e)
+        catch (JSONException e)
         {
-            log.error(".processCall(): can't parse call: " + cdata, e);
+            log.error(".processCall() - can't parse call: " + requestString, 
e);
             json_res = JSONRPCResult.MSG_ERR_PARSE;
         }
         // Write the response
         if (log.isDebugEnabled())
         {
-            log.debug(".processCall():  returns " + json_res.toString());
+            log.debug(".processCall() - returning: " + json_res.toString());
         }
         return json_res;
     }
Index: src/java/org/apache/turbine/modules/screens/JSONSecureScreen.java
===================================================================
--- src/java/org/apache/turbine/modules/screens/JSONSecureScreen.java   
(revision 669803)
+++ src/java/org/apache/turbine/modules/screens/JSONSecureScreen.java   Mon Nov 
03 23:50:48 EST 2008
@@ -72,7 +72,7 @@
  * }
  * </code>
  *
- * @author <a href="mailto:[EMAIL PROTECTED]">Scott Eade</a>
+ * @author <a href="mailto:[EMAIL PROTECTED]">Scott Eade</a>
  * @version $Id$
  */
 public abstract class JSONSecureScreen extends JSONScreen
Index: xdocs/services/jsonrpc-service.xml
===================================================================
--- xdocs/services/jsonrpc-service.xml  (revision 669803)
+++ xdocs/services/jsonrpc-service.xml  Fri Oct 31 23:30:25 EST 2008
@@ -32,7 +32,7 @@
 
 <p>
 The JSON-RPC Service supports JavaScript to Java AJAX communications using
-<a href="http://oss.metaparadigm.com/jsonrpc/";>JSON-RPC-Java</a>.
+<a href="http://jabsorb.org/";>jabsorb</a>.
 </p>
 
 </section>
@@ -152,8 +152,7 @@
 
 <p>
 In these pages you also need to include the JavaScript necessary to process the
-JSON calls - this file is available as part of the JSON-RPC-Java distribution
-(it is included in the <code>webapps\jaonrpc</code> directory):
+JSON calls - this file is available as part of the jabsorb distribution:
 </p>
 
 <source><![CDATA[
Index: src/java/org/apache/turbine/services/jsonrpc/TurbineJsonRpcService.java
===================================================================
--- src/java/org/apache/turbine/services/jsonrpc/TurbineJsonRpcService.java     
(revision 669803)
+++ src/java/org/apache/turbine/services/jsonrpc/TurbineJsonRpcService.java     
Fri Oct 31 17:13:36 EST 2008
@@ -28,7 +28,7 @@
 import org.apache.commons.logging.LogFactory;
 import org.apache.turbine.services.TurbineBaseService;
 
-import com.metaparadigm.jsonrpc.JSONRPCBridge;
+import org.jabsorb.JSONRPCBridge;
 
 /**
  * This is a service that will respond to JSON-RPC calls.
Index: project.xml
===================================================================
--- project.xml (revision 669803)
+++ project.xml Fri Oct 31 23:13:08 EST 2008
@@ -43,7 +43,7 @@
     well. In other words, we strive to make portions of Turbine easily
     available for use in other applications.
   </description>
-  <url>http://turbine.apache.org/turbine/turbine-2.3.3-rc1/index.html</url>
+  <url>http://turbine.apache.org/turbine/turbine-2.3.3-rc1/</url>
   <issueTrackingUrl>http://issues.apache.org/jira/browse/TRB</issueTrackingUrl>
   <siteAddress>people.apache.org</siteAddress>
   
<siteDirectory>/www/turbine.apache.org/turbine/development/turbine-2.3/</siteDirectory>
@@ -644,16 +644,26 @@
       </properties>
     </dependency>
     <dependency>
-      <groupId>com.metaparadigm</groupId>
-      <artifactId>json-rpc</artifactId>
-      <version>1.0</version>
-      <url>http://oss.metaparadigm.com/jsonrpc/</url>
+      <groupId>org.jabsorb</groupId>
+      <artifactId>jabsorb</artifactId>
+      <version>1.3</version>
+      <url>http://jabsorb.org/</url>
       <type>jar</type>
       <properties>
       <war.bundle>true</war.bundle>
       </properties>
     </dependency>
     <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-jcl</artifactId>
+      <version>1.0.1</version>
+      <url>http://slf4j.org/</url>
+      <type>jar</type>
+      <properties>
+      <war.bundle>true</war.bundle>
+      </properties>
+    </dependency>
+    <dependency>
       <groupId>log4j</groupId>
       <artifactId>log4j</artifactId>
       <version>1.2.15</version>
Index: src/java/org/apache/turbine/services/jsonrpc/TurbineJsonRpc.java
===================================================================
--- src/java/org/apache/turbine/services/jsonrpc/TurbineJsonRpc.java    
(revision 669803)
+++ src/java/org/apache/turbine/services/jsonrpc/TurbineJsonRpc.java    Fri Oct 
31 17:13:36 EST 2008
@@ -26,7 +26,7 @@
 
 import org.apache.turbine.services.TurbineServices;
 
-import com.metaparadigm.jsonrpc.JSONRPCBridge;
+import org.jabsorb.JSONRPCBridge;
 
 /**
  * This is a static accessor class for [EMAIL PROTECTED] JsonRpcService}.
Index: xdocs/changes.xml
===================================================================
--- xdocs/changes.xml   (revision 690947)
+++ xdocs/changes.xml   Mon Nov 03 23:58:21 EST 2008
@@ -29,6 +29,15 @@
 <body>
   <release version="2.3.3" date="in SVN">
     <action type="fix" dev="seade">
+      Corrected JSONScreen to set the character set of a response.
+    </action>
+    <action type="update" dev="seade">
+      Updated the JSON-RPC Service from
+      <a href="http://oss.metaparadigm.com/jsonrpc/";>JSON-RPC-Java</a> to its
+      replacement, <a href="http://jabsorb.org";>jabsorb</a>.  Applications
+      should update the related JavaScript files.
+    </action>
+    <action type="fix" dev="seade">
       Minor correction to intake.dtd - added missing fieldClass attribute
       to field element.
     </action>
Index: src/java/org/apache/turbine/modules/screens/JSONScreen.java
===================================================================
--- src/java/org/apache/turbine/modules/screens/JSONScreen.java (revision 
669803)
+++ src/java/org/apache/turbine/modules/screens/JSONScreen.java Tue Nov 04 
00:27:00 EST 2008
@@ -31,7 +31,7 @@
 import org.apache.turbine.services.jsonrpc.TurbineJsonRpc;
 import org.apache.turbine.util.RunData;
 
-import com.metaparadigm.jsonrpc.JSONRPCBridge;
+import org.jabsorb.JSONRPCBridge;
 
 /**
  * A Screen class for dealing with JSON-RPC requests.  Typically you would
@@ -69,7 +69,7 @@
  * }
  * </code>
  *
- * <p>This code is derived from the com.metaparadigm.jsonrpc.JSONRPCServlet
+ * <p>This code is derived from the org.jabsorb.JSONRPCServlet
  *
  * @author [EMAIL PROTECTED]
  * @author <a href="mailto:[EMAIL PROTECTED]">Scott Eade</a>
@@ -77,6 +77,10 @@
  */
 public class JSONScreen extends RawScreen
 {
+    /**
+     * Depending on your needs you may want to override this with something 
like
+     * "application/json; charset=utf-8"
+     */
     protected static final String JSONRPC_CONTENT_TYPE = "text/plain";
 
     protected final static int BUFFER_SIZE = 4096;
@@ -107,13 +111,13 @@
         data.declareDirectResponse();
         HttpServletRequest request = data.getRequest();
         
-        //String charset = request.getCharacterEncoding();
-        //if(charset == null)
-        //{
-        //    charset = "UTF-8";
-        //}
-        //BufferedReader in = new BufferedReader(new 
InputStreamReader(request.getInputStream(), charset));
-        BufferedReader in = new BufferedReader(new 
InputStreamReader(request.getInputStream()));
+        String charset = request.getCharacterEncoding();
+        if(charset == null)
+        {
+            charset = data.getCharSet();
+        }
+        BufferedReader in = new BufferedReader(
+                new InputStreamReader(request.getInputStream(), charset));
 
         // Read the request
         CharArrayWriter cdata = new CharArrayWriter();
@@ -132,7 +136,7 @@
         Object json_res = TurbineJsonRpc.processCall(cdata, json_bridge, 
request);
 
         PrintWriter out = new PrintWriter(
-                new OutputStreamWriter(data.getResponse().getOutputStream()));
+                new OutputStreamWriter(data.getResponse().getOutputStream(), 
charset));
         out.print(json_res.toString());
         out.flush();
         out.close();

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to