Heroku上的默认字符集(US-ASCII)导致问题 [英] Default Charset on Heroku (US-ASCII) causing problems

查看:174
本文介绍了Heroku上的默认字符集(US-ASCII)导致问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在heroku上部署了一个基于maven-jetty的Java应用程序。

We have a maven--jetty-based Java app deployed on heroku.

本地,当我这样做时:

System.out.println("Default Charset = "+ Charset.defaultCharset());
String s = "Resumé of Schrödinger";
System.out.println("s = "+ s);`

我明白了(按预期):

Default Charset = UTF-8
s = Resumé of Schrödinger

但是,当我将应用程序推送到heroku并检查日志时,我看到:

But, when I push the app to heroku, and check the logs, I see:

Default Charset = US-ASCII
s = Resum?? of Schr??dinger 

实际上,由于这个原因,我面临更多问题,因为我们必须解码具有UTF-8编码字符的Base-64编码文本。

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");

以后,在做 org.apache.commons.codec.binary时。 Base64.decodeBase64(byte [])我甚至在做 stringObject.getBytes(UTF-8)

And later, when doing org.apache.commons.codec.binary.Base64.decodeBase64(byte []) I am even doing stringObject.getBytes("UTF-8")

但是,我仍然无法看到像e-acute(é),umlaut(ö)等字符。

But still, I am unable to see the characters like e-acute(é), umlaut(ö), etc.

有没有在Heroku上解决这个问题的方法?

Is there any way to solve this on Heroku?

pom.xml中的jdk版本是1.6

The jdk version in pom.xml is 1.6

这是一个怪癖OpenJDK 1.7& Heroku下面的虚拟机?

Is it a quirk of the OpenJDK 1.7 & the virtual machine underneath in Heroku?

提前致谢。

推荐答案

最后,我与Heroku友好的工作人员取得联系 - 他们通过 JAVA_OPTS提出以下建议来覆盖 file.encoding 财产 env-variable。

Finally, I got in touch with the friendly staff at Heroku--they gave the following suggestion to over-ride file.encoding property via the JAVA_OPTS env-variable.

从我的Heroku Toolbelt发出以下内容,&事情现在开始起作用。

Issued the following from my Heroku Toolbelt, & things began working now.

heroku config:add JAVA_OPTS='-Xmx384m -Xss512k -XX:+UseCompressedOops -Dfile.encoding=UTF-8'

这样,JVM可以选择它,&现在 Charset.defaultCharset()返回 UTF-8 ,特殊字符应该出现!

This way, the JVM picks it up, & now Charset.defaultCharset( ) returns UTF-8, with special characters appearing as they should!

他们还说,我们也可以做以下事情:

They also said, we could alternatively do the following as well:

heroku config:add JAVA_TOOL_OPTIONS='-Dfile.encoding=UTF-8'

此外,这是个好主意将此属性嵌入到应用程序的 Procfile 中,以便当我们将它推送到新的Heroku应用程序时,我们的代码行为相同。

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.

这篇关于Heroku上的默认字符集(US-ASCII)导致问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆