SoftInstigate / restheart

Rapid API Development with MongoDB
https://restheart.org
GNU Affero General Public License v3.0
807 stars 171 forks source link

UTF-8 Encoding problem #206

Closed jcheron closed 7 years ago

jcheron commented 7 years ago

With this datas in MongoDb :

{  "code" : "Beer1", "descriptif" : "affichage de la liste des bières /beers (L'affichage de la bière n'affiche pas le brasseur associé)"}

The Http response given by restHeart does not seem to be interpreted as UTF-8 :

{"code":"Beer1","descriptif":"affichage de la liste des bières /beers (L'affichage de la bière n'affiche pas le brasseur associé)"

This is not a RestHeart bug, since on another computer, there is no encoding problem.

Would the RestHeart server use the default encoding of the java virtual machine?

Configuration :

ujibang commented 7 years ago

Hi @jcheron

just tried but it worked for me, it must be your http client that mess ups the strings...are you on windows terminal?

$ (master) http -a a:a 127.0.0.1:8080/test/coll/58dcb924ab36667a54a57efc
HTTP/1.1 200 OK
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: *
Access-Control-Expose-Headers: Location, ETag, Auth-Token, Auth-Token-Valid-Until, Auth-Token-Location, X-Powered-By
Auth-Token: 0b3c7498-b660-4cab-b593-51d88c19f6cd
Auth-Token-Location: /_authtokens/a
Auth-Token-Valid-Until: 2017-03-30T11:46:23.497Z
Connection: keep-alive
Content-Encoding: gzip
Content-Length: 155
Content-Type: application/json
Date: Thu, 30 Mar 2017 11:31:23 GMT
X-Powered-By: restheart.org

{
    "_id": {
        "$oid": "58dcb924ab36667a54a57efc"
    }, 
    "code": "Beer1", 
    "descriptif": "affichage de la liste des bières /beers (L'affichage de la bière n'affiche pas le brasseur associé)"
}
jcheron commented 7 years ago

Hi @ujibang Did you see that I changed the initial message of the issue. This also works for me on some computers

mkjsix commented 7 years ago

You mentioned different computers: which operating systems?

jcheron commented 7 years ago

I tried on debian 8 and windows 10 => no problems

I have the problem on windows 7

Which does not mean that the problem is related to the operating system...

Is there a way to force the encoding in the configuration file ?

mkjsix commented 7 years ago

To me this sounds like a Java configuration issue on Windows 7, maybe you can try to force the JVM to use the UTF-8 file encoding by passing the following JVM parameter when starting RESTHeart:

-Dfile.encoding=UTF-8.

On Windows, you can also set a global environment variable for that, but beware it will affect all of your JVM processes:

By setting the (Windows) environment variable JAVA_TOOL_OPTIONS to -Dfile.encoding=UTF8, the (Java) System property will be set automatically every time a JVM is started. You will know that the parameter has been picked up because the following message will be posted to System.err:

Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF8

jcheron commented 7 years ago

Indeed, it depends on the jvm. Launching with -Dfile.encoding = UTF-8 solves the problem. Thank you ! It may be a parameter that could be included in the configuration file..

mkjsix commented 7 years ago

Hi @jcheron Indeed adding that parameter in the configuration file could be a good idea, I'll have a look into this.

mkjsix commented 7 years ago

I added "-Dfile.encoding=UTF-8" parameter to bin/start.sh

jcheron commented 7 years ago

This is what is called "be responsive". "être réactif" in French and with accents. I will test this (on my old win 7) Thank you @mkjsix