编码JMS TextMessage [英] Encoding a JMS TextMessage
问题描述
我正在从JMS MQ队列接收消息,消息应该是utf-8
编码的.但是在使用msgText = ((TextMessage)msg).getText();
读出时
我在存在非标准字符的地方收到问号.使用bytemessage
时似乎可以指定编码,但是我找不到在读出TextMessage
时指定编码的方法.有没有办法解决这个问题,还是我应该按bytemessages
键?
I'm receiving messages from a JMS MQ queue which are supposedly utf-8
encoded. However on reading the out using msgText = ((TextMessage)msg).getText();
I get question marks where non standard characters were present. It seems possible to specify the encoding when using a bytemessage
, but I cant find a way to specify encoding while reading out the TextMessage
. Is there a way to solve this, or should I press for bytemessages
?
推荐答案
我们尝试在Websphere
的jvm中添加Dfile.encoding="UTF-8"
并添加
We tried adding Dfile.encoding="UTF-8"
to Websphere
's jvm and we added
source = new StreamSource(new ByteArrayInputStream(
((TextMessage) msg).getText().getBytes("UTF-8")));
在我们的MessageListener
中.这对我们有用,因此我们把Dfile.encoding
拿走了一点,对我们仍然有用.
In our MessageListener
. This worked for us, so then we took out the Dfile.encoding
bit away and it still works for us.
由于Websphere
的首选最低配置,我们决定采用这种方式,同时考虑到我们可以通过文件或数据库中的设置更轻松地切换UTF-8
字符串.
Due to preferred minimum configuration for Websphere
we decided to leave it this way, also taking into account that we may easier switch the UTF-8
string by a setting from file or database.
这篇关于编码JMS TextMessage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!