svn commit: r650083 - in /ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event: DojoJSONServiceEventHandler.java JSONJavaEventHandler.java JSONServiceEventHandler.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r650083 - in /ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event: DojoJSONServiceEventHandler.java JSONJavaEventHandler.java JSONServiceEventHandler.java

jleroux@apache.org
Author: jleroux
Date: Mon Apr 21 03:18:20 2008
New Revision: 650083

URL: http://svn.apache.org/viewvc?rev=650083&view=rev
Log:
A patch from Nicolas Mervaillie "JSON event handlers send truncated response when it contains accented chars" (https://issues.apache.org/jira/browse/OFBIZ-1752) - OFBIZ-1752

Modified:
    ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/DojoJSONServiceEventHandler.java
    ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/JSONJavaEventHandler.java
    ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/JSONServiceEventHandler.java

Modified: ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/DojoJSONServiceEventHandler.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/DojoJSONServiceEventHandler.java?rev=650083&r1=650082&r2=650083&view=diff
==============================================================================
--- ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/DojoJSONServiceEventHandler.java (original)
+++ ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/DojoJSONServiceEventHandler.java Mon Apr 21 03:18:20 2008
@@ -19,6 +19,7 @@
 package org.ofbiz.webapp.event;
 
 import java.io.IOException;
+import java.io.UnsupportedEncodingException;
 import java.io.Writer;
 import java.util.Enumeration;
 import java.util.HashMap;
@@ -118,7 +119,12 @@
         String htmlJsonStr = "<html><head></head><body><textarea style=\"width: 100%%; height: 100px;\">" + jsonStr + "</textarea></body></html>";
         // set the X-JSON content type
         response.setContentType("text/html");
-        response.setContentLength(htmlJsonStr.length());
+        // jsonStr.length is not reliable for unicode characters
+        try {
+            response.setContentLength(jsonStr.getBytes("UTF8").length);
+        } catch (UnsupportedEncodingException e) {
+            throw new EventHandlerException("Problems with Json encoding", e);
+        }
 
         // return the JSON String
         Writer out;

Modified: ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/JSONJavaEventHandler.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/JSONJavaEventHandler.java?rev=650083&r1=650082&r2=650083&view=diff
==============================================================================
--- ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/JSONJavaEventHandler.java (original)
+++ ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/JSONJavaEventHandler.java Mon Apr 21 03:18:20 2008
@@ -19,6 +19,7 @@
 package org.ofbiz.webapp.event;
 
 import java.io.IOException;
+import java.io.UnsupportedEncodingException;
 import java.io.Writer;
 import java.util.Enumeration;
 import java.util.Map;
@@ -61,7 +62,12 @@
 
         // set the X-JSON content type
         response.setContentType("application/x-json");
-        response.setContentLength(jsonStr.length());
+        // jsonStr.length is not reliable for unicode characters
+        try {
+            response.setContentLength(jsonStr.getBytes("UTF8").length);
+        } catch (UnsupportedEncodingException e) {
+            throw new EventHandlerException("Problems with Json encoding", e);
+        }
 
         // return the JSON String
         Writer out;

Modified: ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/JSONServiceEventHandler.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/JSONServiceEventHandler.java?rev=650083&r1=650082&r2=650083&view=diff
==============================================================================
--- ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/JSONServiceEventHandler.java (original)
+++ ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/JSONServiceEventHandler.java Mon Apr 21 03:18:20 2008
@@ -19,6 +19,7 @@
 package org.ofbiz.webapp.event;
 
 import java.io.IOException;
+import java.io.UnsupportedEncodingException;
 import java.io.Writer;
 import java.util.Enumeration;
 import java.util.Map;
@@ -61,7 +62,12 @@
 
         // set the X-JSON content type
         response.setContentType("application/x-json");
-        response.setContentLength(jsonStr.length());
+        // jsonStr.length is not reliable for unicode characters
+        try {
+            response.setContentLength(jsonStr.getBytes("UTF8").length);
+        } catch (UnsupportedEncodingException e) {
+            throw new EventHandlerException("Problems with Json encoding", e);
+        }
 
         // return the JSON String
         Writer out;