6
votes

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?

2
Which JMS transport are you using ? Are you passing XML messages ? Which platform are you consuming and producing messages from/to ?Romain Hippeau
We're on Websphere MQ, the messages are XML with encoding="UTF-8"dr jerry
I'm not sure which platform is producing but we're consuming With Websphere running on solaris. Unfortunately we're completely agnostic about the mq implementation so I cant give an version numbers at this point.dr jerry

2 Answers

4
votes

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

In our MessageListener. This worked for us, so then we took out the Dfile.encoding bit away and it still works for us.

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.

2
votes

If the text is not decoded correctly, then probably the client is not sending the message with the utf-8 codec; this should work:

byte[] by = ((TextMessage) msg).getText().getBytes("ISO-8859-1");
String text = new String(by,"UTF-8");