UTF-8 (Chinese) in servoy REST Webservice

Questions and answers on designing your Servoy solutions, database modelling and other 'how do I do this' that don't fit in any of the other categories

UTF-8 (Chinese) in servoy REST Webservice

Postby Janssenjos » Sun Dec 30, 2018 4:12 pm

Hi,

I'm trying to get chinese working in the REST service and I hope someone can point me in the right direction.
Inside of Servoy it is all working correctly, but when it exits servoy and we look in a sniffer and at the client, the texts is wrong.

What I have so far. (when I check _result, it is still 羅莎大)
Code: Select all
var bytes = _result.getBytes("UTF-8");
return bytes;


Before I had only .getBytes() --> this resulted in ??? instead of 羅莎大.
When we added .getBytes("UTF-8") --> it became 羅莎大. Which is the ANSI encoding.

Other actions we have tried: changed the server.xml of tomcat/apache and added URIEncoding="UTF-8" to the connector, but that also doesn't work. Still 羅莎大.
Also I made a test c# client, which ads UTF8 to the request, but it still returns 羅莎大.

Code: Select all
HttpResponseMessage response = await client.PostAsync(targetUrl, new StringContent(requestData, Encoding.UTF8, "application/json"));
            HttpContent content = response.Content;                       
            var byteArray = await content.ReadAsByteArrayAsync();
            var result = Encoding.UTF8.GetString(byteArray, 0, byteArray.Length);


Is there anyone who knows in which direction we can further look?
It feels like I'm missing something in servoy or in apache/tomcat.
Jos Janssen
Software Developer
Axerrio
http://www.axerrio.com
Janssenjos
 
Posts: 148
Joined: Thu Aug 13, 2009 3:55 pm
Location: Bergen op Zoom

Re: UTF-8 (Chinese) in servoy REST Webservice

Postby ROCLASI » Sun Dec 30, 2018 4:21 pm

Hi Jos,

What is the reason to return bytes instead of the string?
Also what content-type does the REST api return?
Robert Ivens
SAN Developer / Servoy Valued Professional / Servoy Certified Developer

ROCLASI Software Solutions / JBS Group, Partner
Mastodon: @roclasi
--
ServoyForge - Building Open Source Software.
PostgreSQL - The world's most advanced open source database.
User avatar
ROCLASI
Servoy Expert
 
Posts: 5438
Joined: Thu Oct 02, 2003 9:49 am
Location: Netherlands/Belgium

Re: UTF-8 (Chinese) in servoy REST Webservice

Postby Janssenjos » Sun Dec 30, 2018 8:49 pm

Hi,

To be honest, I don't know why it returns bytes. The project was developed by another developer and transferred to me.
But the difference I notice when I remove the .getBytes() is that the json that is returned isn't valid.

For example without the .getBytes it is:
Code: Select all
/"property/"=10

Instead of
Code: Select all
"property"=10



But the content type of the response is application/json;charset=UTF-8.
So I'm starting to think, I'm doing something strange somewhere. As it all seems to be correct. :)

Code: Select all
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: xxxxx
Vary: Origin
Access-Control-Max-Age: 1728000
Cache-Control: max-age=0, must-revalidate, proxy-revalidate
Expires: 0
Content-Type: application/json;charset=UTF-8
Content-Length: 533
Date: Sun, 30 Dec 2018 18:42:00 GMT

Still the:
"productgroup":"羅莎大"
Jos Janssen
Software Developer
Axerrio
http://www.axerrio.com
Janssenjos
 
Posts: 148
Joined: Thu Aug 13, 2009 3:55 pm
Location: Bergen op Zoom

Re: UTF-8 (Chinese) in servoy REST Webservice

Postby Janssenjos » Mon Dec 31, 2018 10:26 am

Thanks Robert!
It did gave me the idea, to build up a object in code to return immediatly, instead of building the json object in a string.

That has solved the problem.

This project was still on servoy 6.x though, so it was a bit of a search, because JSON.stringify came available later. But luckily I found the answer on this forum to, to use json2 stringify.
Jos Janssen
Software Developer
Axerrio
http://www.axerrio.com
Janssenjos
 
Posts: 148
Joined: Thu Aug 13, 2009 3:55 pm
Location: Bergen op Zoom


Return to Programming with Servoy

Who is online

Users browsing this forum: No registered users and 9 guests