We have a maven--jetty-based Java app deployed on heroku.
Locally, when I do:
System.out.println("Default Charset = "+ Charset.defaultCharset());
String s = "Resumé of Schrödinger";
System.out.println("s = "+ s);`
I see (as expected):
Default Charset = UTF-8
s = Resumé of Schrödinger
But, when I push the app to heroku, and check the logs, I see:
Default Charset = US-ASCII
s = Resum?? of Schr??dinger
Actually, I'm facing further problems because of this, since we have to Decode Base-64 encoded text which has UTF-8 encoded characters.
I have even tried the following with no use:
SAXBuilder builder = new SAXBuilder();
InputStream iStream = new ByteArrayInputStream(xmlAsString.getBytes("UTF-8"));
Reader reader = new InputStreamReader(iStream, "UTF-8");
InputSource is = new InputSource(reader);
is.setEncoding("UTF-8");
And later, when doing org.apache.commons.codec.binary.Base64.decodeBase64(byte [])
I am even doing stringObject.getBytes("UTF-8")
But still, I am unable to see the characters like e-acute(é), umlaut(ö), etc.
Is there any way to solve this on Heroku?
The jdk version in pom.xml is 1.6
Is it a quirk of the OpenJDK 1.7 & the virtual machine underneath in Heroku?
Thanks in advance.
Finally, I got in touch with the friendly staff at Heroku--they gave the following suggestion to over-ride
file.encoding
property via theJAVA_OPTS
env-variable.Issued the following from my Heroku Toolbelt, & things began working now.
This way, the JVM picks it up, & now
Charset.defaultCharset( )
returnsUTF-8
, with special characters appearing as they should!They also said, we could alternatively do the following as well:
Also, it would be a good idea to embed this property right into the Procfile of the app, so that our code behaves the same when we push it to a new Heroku app.
Set
file.encoding
system variable. Open jdk uses this to get the default characterset.