h-tadagawa / rest-client

Automatically exported from code.google.com/p/rest-client
Apache License 2.0
0 stars 0 forks source link

Charset for String body not correct #165

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Post to a url with a string body and set the charset to UTF-8
2. Add i8n characters such as Chinese
3. RestClient 3.1 sends in hex code points rather than UTF-8
(http://www.ltg.ed.ac.uk/~richard/utf-8.cgi?input=751f&mode=hex)

What is the expected output? What do you see instead?

What version of the product are you using? On what operating system?
Rest 3.1 Windows 7

Please provide any additional information below.
I believe for String Entity in Apache HttpClient all you need to do is add a 
charset to match the charset in the client and the put will work correctly.

Original issue reported on code.google.com by jbeja...@gmail.com on 5 Dec 2012 at 9:19

GoogleCodeExporter commented 8 years ago
Looking into it...

Original comment by subwiz on 7 Dec 2012 at 1:21

GoogleCodeExporter commented 8 years ago
Fix:
-------------------------------------------------------------
# This patch file was generated by NetBeans IDE
# It uses platform neutral UTF-8 encoding and \n newlines.
--- HEAD
+++ Modified In Working Tree
@@ -77,21 +77,24 @@
         return sb.toString();
     }

-    static AbstractHttpEntity getEntity(ReqEntitySimple bean) throws 
UnsupportedEncodingException, IOException {
+    static AbstractHttpEntity getEntity(ReqEntitySimple bean)
+            throws UnsupportedEncodingException, IOException {
         AbstractHttpEntity entity = null;
-        if(bean instanceof ReqEntityString) {
-            entity = new StringEntity(((ReqEntityString)bean).getBody());
+        ContentType contentType = null;
+        if (bean.getContentType() != null) {
+            org.wiztools.restclient.bean.ContentType ct = 
bean.getContentType();
+            contentType = ContentType.create(ct.getContentType(), 
ct.getCharset());
         }
-        else if(bean instanceof ReqEntityByteArray) {
-            entity = new ByteArrayEntity(((ReqEntityByteArray)bean).getBody());
+        if (bean instanceof ReqEntityString) {
+            entity = new StringEntity(((ReqEntityString) bean).getBody(), 
contentType);
+        } else if (bean instanceof ReqEntityByteArray) {
+            entity = new ByteArrayEntity(((ReqEntityByteArray) 
bean).getBody(), contentType);
+        } else if (bean instanceof ReqEntityStream) {
+            entity = new InputStreamEntity(((ReqEntityStream) bean).getBody(),
+                    ((ReqEntityStream) bean).getLength(), contentType);
+        } else if (bean instanceof ReqEntityFile) {
+            entity = new FileEntity(((ReqEntityFile) bean).getBody(), 
contentType);
         }
-        else if(bean instanceof ReqEntityStream) {
-            entity = new InputStreamEntity(((ReqEntityStream)bean).getBody(),
-                    ((ReqEntityStream)bean).getLength());
-        }
-        else if(bean instanceof ReqEntityFile) {
-            entity = new FileEntity(((ReqEntityFile)bean).getBody());
-        }
         return entity;
     }
 }
-------------------------------------------------------------
# This patch file was generated by NetBeans IDE
# It uses platform neutral UTF-8 encoding and \n newlines.
--- HEAD
+++ Modified In Working Tree
@@ -280,10 +280,6 @@
                     try {
                         if(bean instanceof ReqEntitySimple) {
                             AbstractHttpEntity e = HTTPClientUtil.getEntity((ReqEntitySimple)bean);
-                            final ContentType ct = 
((ReqEntitySimple)bean).getContentType();
-                            if(ct != null) {
-                                
e.setContentType(HttpUtil.getFormattedContentType(ct));
-                            }
                             eeMethod.setEntity(e);
                         }
                         else if(bean instanceof ReqEntityMultipart) {

-------------------------------------------------------------

Original comment by maxima...@gmail.com on 20 Dec 2012 at 9:08

GoogleCodeExporter commented 8 years ago
wow! Let me try it out in the evening. Can u attach the patch to ur comment?

Original comment by subwiz on 20 Dec 2012 at 9:15

GoogleCodeExporter commented 8 years ago
Please.

Original comment by maxima...@gmail.com on 20 Dec 2012 at 9:21

Attachments:

GoogleCodeExporter commented 8 years ago
I applied the change.  But I still I am getting code-points for this URL (valid 
for 24 hours after this post):

http://web-tester.appspot.com/view/abc

Original comment by subwiz on 23 Dec 2012 at 2:14

GoogleCodeExporter commented 8 years ago
Sorry, my last comment was based on a bug in my web-tester app. But request you 
to test if my patch application has been correct.

Original comment by subwiz on 23 Dec 2012 at 2:21

GoogleCodeExporter commented 8 years ago
Marking as fixed. Did a quick test using request-trace-servlet (available @ 
WizTools.org mini-projects) and seems to be working.

Original comment by subwiz on 27 May 2013 at 10:27