编码JMS TextMessage [英] Encoding a JMS TextMessage

查看:318
本文介绍了编码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屋!

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