[英]JMS Read Message MalformedInputException
I always get an MalformedInputException, when read an Queue-Meassage with JMS.使用 JMS 读取队列消息时,我总是收到 MalformedInputException 异常。
My code is:我的代码是:
Message message = mqMessageConsumer.receiveNoWait();
while (message != null) {
if (message instanceof TextMessage) {
String inputTmp = ((TextMessage) message).getText();
[...]
I think the Problem is the Message, it starts with Hex-Representation of the length x'02A8', and he can't convert it:我认为问题是消息,它以长度 x'02A8' 的十六进制表示开头,他无法转换它:
.y<?xml version="1.0" encoding="UTF-8"?><Document xmlns:xsi=...
Stacktrace is:堆栈跟踪是:
com.ibm.msg.client.jms.DetailedJMSException: JMSCMQ1049: The character set '1208(UTF-8) Unmappable Action: REPORT, Unmappable Replac
ement: 63, spaceByte: 32' cannot convert some or all of the string 'ÝB§755cab7'
An attempt was made to send or receive string data using a character set not capable of translating the strings content.
Only encode a message using a character set known to be appropriate for the string data being transmitted.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:83)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:57)
at java.lang.reflect.Constructor.newInstance(Constructor.java:437)
at com.ibm.msg.client.commonservices.j2se.NLSServices.createException(NLSServices.java:319)
at com.ibm.msg.client.commonservices.nls.NLSServices.createException(NLSServices.java:226)
at com.ibm.msg.client.wmq.common.internal.WMQUtils.computeTextFromBytes(WMQUtils.java:382)
at com.ibm.msg.client.wmq.common.internal.WMQUtils.computeTextFromByteBuffer(WMQUtils.java:421)
at com.ibm.msg.client.wmq.common.internal.messages.WMQTextMessage.getText(WMQTextMessage.java:240)
at com.ibm.msg.client.jms.internal.JmsTextMessageImpl.getText(JmsTextMessageImpl.java:205)
at com.ibm.jms.JMSTextMessage.getText(JMSTextMessage.java:124)
at myProgramm
Caused by: java.nio.charset.MalformedInputException: Input length = 1
at java.nio.charset.CoderResult.throwException(CoderResult.java:292)
at java.nio.charset.CharsetDecoder.decode(CharsetDecoder.java:816)
at com.ibm.mq.jmqi.system.JmqiCodepage.bytesToString(JmqiCodepage.java:917)
at com.ibm.msg.client.wmq.common.internal.WMQUtils.computeTextFromBytes(WMQUtils.java:375)
... 6 more
Is there an option to get the Message as byte[] or without conversion.是否可以选择将消息作为字节 [] 或不进行转换。
Unfortunately, the sender can not change the Message.不幸的是,发件人无法更改消息。
Or should i use the MQI Api?还是我应该使用 MQI Api?
Thank you very much!非常感谢!
Florian弗洛里安
Use this instead:改用这个:
Message message = mqMessageConsumer.receiveNoWait();
while (message != null) {
if (message instanceofJMSBytesMessage) {
String inputTmp = ((JMSBytesMessage)message).readUTF();
[...]
I think in my case there is no Solution without changing the Message.我认为就我而言,不更改消息就没有解决方案。 To get JMSByteMessage the Message Format musst be MQ-None, with MQ-String you always get an JMSTextMessage.要获得 JMSByteMessage,消息格式必须是 MQ-None,使用 MQ-String,您总是会获得 JMSTextMessage。 Maybe there is an Way with MQI, but because my Programm is an IMS JMP I'm not allowed to use MQI.也许有 MQI 的方法,但是因为我的程序是 IMS JMP,所以我不允许使用 MQI。 I asked the Producer of the Message to change it.我要求消息的生产者更改它。 Thanks to JoshMC for your Answer感谢 JoshMC 的回答
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.