Java – the default character set (us-ascii) on heroku causes problems
We deployed a Java application based on Maven jetty on heroku
Locals, when I do this:
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
However, when I push the application to heroku and check the log, I see:
Default Charset = US-ASCII s = Resum?? of Schr??dinger
In fact, I have more problems because we have to decode base-64 encoded text with UTF-8 encoded characters
I've even tried the following:
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");
Later, I was doing org apache. commons. codec. binary. Base64. When decodebase64 (byte []), I even made stringobject getBytes(“UTF-8”)
However, I still can't see characters like e - acute (é), umlaut (ö), etc
Is there any way to solve this problem on heroku?
pom. The JDK version in XML is 1.6
This is openjdk 1.7 & amp; Virtual machine under heroku?
Thank you in advance
Solution
Finally, I got in touch with the friendly staff of heroku – they made the following suggestions through Java_ Opts env variable overrides file Encoding property
From my heroku toolkit, send out the following, & things are now working
heroku config:add JAVA_OPTS='-Xmx384m -Xss512k -XX:+UseCompressedOops -Dfile.encoding=UTF-8'
In this way, the JVM can select it, & now charset Defaultcharset() returns UTF-8. Special characters should appear!
They also said that we could also do the following:
heroku config:add JAVA_TOOL_OPTIONS='-Dfile.encoding=UTF-8'
In addition, it is a good idea to embed this property directly into the application's procfile, so that our code behaves the same when we push it to a new heroku application