0

I run a Java Spring project. For dev purposes, I have an embedded Tomcat in my Eclipse in order to test my development continuously.

I deployed the spring boot app on a VPS where Tomcat 9 is running, and on the VPS I encounter encoding issues when I get a JSON file.

On the VPS if I type in the terminal root@vps:~# curl --cookie "lang=fr" localhost:8080/utils I get

{signout: "Se déconnecter"}

On my computer, with Firefox if I type in the address bar localhost:8080/utils (it targets tomcat embedded in Eclipse), I get

{signout: "Se déconnecter"}

But on my computer, with the same Firefox if I type in the address bar my.vps.ip:8080/utils I get

{signout: "Se déconnecter"}

The controller function is

@RequestMapping("/utils")
public String getUtils(@CookieValue(defaultValue = "en", value = "lang", required = false) String languageCode) {
    if (!languageService.exists(languageCode)) {
        languageCode = "en";
    }
    return String.format("/msg/%s/displayedWords.js", languageCode);
}

I tried to add URIEncoding="UTF-8" to the Connector definition on Tomcat file /etc/tomcat/server.xml but nothing changed.

What could be wrong? Thanks

EDIT

The locale on the VPS:

root@vps:~# locale
LANG=C.UTF-8
LANGUAGE=
LC_CTYPE="C.UTF-8"
LC_NUMERIC=C.UTF-8
LC_TIME=C.UTF-8
LC_COLLATE="C.UTF-8"
LC_MONETARY=C.UTF-8
LC_MESSAGES="C.UTF-8"
LC_PAPER=C.UTF-8
LC_NAME=C.UTF-8
LC_ADDRESS=C.UTF-8
LC_TELEPHONE=C.UTF-8
LC_MEASUREMENT=C.UTF-8
LC_IDENTIFICATION=C.UTF-8
LC_ALL=
lolo
  • 706
  • 6
  • 19
  • 1
    What locale setting is your VPS using? – nitind Dec 04 '20 at 16:49
  • Hello @nitind I answered your question in the post – lolo Dec 04 '20 at 17:04
  • Thank you. What are the headers for the request that you're sending? – nitind Dec 04 '20 at 17:06
  • I think that's just a list of all _available_ locales. Not the one which is currently in use? – andrewJames Dec 04 '20 at 17:07
  • @andrewjames sorry I edited the anwer with the locale command result. – lolo Dec 04 '20 at 17:40
  • @nitind I just enter in the address bar of Firefox the URL and get the JSON as a result – lolo Dec 04 '20 at 17:41
  • How are you starting Tomcat? I recommend using a [`setenv.sh` file](https://tomcat.apache.org/tomcat-9.0-doc/RUNNING.txt) (or `setenv.bat` on Windows) in which you set `JAVA_OPTS` to include this option: `-Dfile.encoding=UTF-8`. This sets the [default encoding of the JVM](https://stackoverflow.com/questions/361975/setting-the-default-java-character-encoding) in which Tomcat will run. (There may be other points along the way where your data is not being handled as UTF-8 - like the headers mentioned in an earlier comment.) – andrewJames Dec 04 '20 at 19:02

1 Answers1

0

Finally, I ended up by replacing all the special characters by their unicode code, my file became:

{signout: "Se d\u00E9connecter"}
lolo
  • 706
  • 6
  • 19