3

I have a project that runs on WebSphere Liberty on Linux. My language is brazilian portuguese and we have some accented words. My java code sets some user messages like below:

...
ErroResponse erroResponse = new ErroResponse();
erroResponse.setMensagem("Esse grupo não pode ser criado. Já existe um grupo criado com esse nome.");
response = Response.status(Status.BAD_REQUEST).entity(erroResponse).build();
...

When the same message is show to the user, it looks this way: enter image description here

I don't think it's a browser encoding problem because the message looks the same on my server logs. enter image description here

I've tried to set JVM encoding using -Dclient.encoding.override -Dfile.encoding to ISO-8859-1 and UTF-8, without success.

The same project, running on a Windows server, runs without problem, showing the messages with the correct accents.

Only message that were directly written in the source code has this problem. Accented words that came from database query result are correctly presented.

I'm using Suse 11.4.

I really appreciate any help.

Thanks

Andy Guibert
  • 41,446
  • 8
  • 38
  • 61
Ranieri Mazili
  • 723
  • 6
  • 21

4 Answers4

0

Try to check your Suse encoding and language, by doing:

$ echo $LC_CTYPE
ISO-8859-1

$ echo $LANG
pt_BR

Get all languages:

$ locale -a

Change to pt_PT.utf8:

$ export LC_ALL=pt_PT.utf8 
$ export LANG="$LC_ALL"
andreybleme
  • 689
  • 9
  • 23
0

It is likely that before adding those JVM encoding properties, you were getting UTF-8 encoding of that character in the response, but your browser was unwilling to interpret them as UTF-8. I'd suggest deleting them and keeping that within your JAX-RS resources.

A useful debugging step is to look at the respone with a command like client and hex editor (like od -t x1) because there are many things that can obscure what data is actually being transmitted (browser, terminal emulator, etc).

If you explicitly tell the server to use a charset (UTF-8 or a local codepage like ISO8859-1) your strings will be transformed to the specified codepage. The browser will also see the charset in the Content-Type header.

The simplest way is to use @Produces in JAX-RS as in:

@Produces("text/html; charset=UTF-8")

or

@Produces("text/html; charset=ISO8859-1")
covener
  • 17,402
  • 2
  • 31
  • 45
0

The problem was solved changing the project text encoding. By default eclipse was saving the source code as UTF-8 and javac was compiling it as CP1252 (Windows Default).

To make this change I had to right click on Project -> Properties -> Resource then changed Text file encoding to Other (ISO-8859-1).

Ranieri Mazili
  • 723
  • 6
  • 21
  • If you use Maven or a similar build tool, the declaration of the correct encoding belongs in the pom.xml (Maven) or build.properties (Gradle) or build.xml (Ant) file so that it survives a reinstallation of Eclipse. – Roland Illig Feb 26 '19 at 02:34
0

I've had a similar problem with maven and jax-ws service which returned bad characters (of text inside source code).

Resolved it by adding this to the parent maven project:

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>