java - JMS 读取消息 MalformedInputException

标签 java jms ibm-mq


当使用 JMS 读取队列消息时,我总是收到 MalformedInputException。
我的代码是:

Message message = mqMessageConsumer.receiveNoWait();
while (message != null) {
   if (message instanceof TextMessage) {
        String inputTmp = ((TextMessage) message).getText();
[...]

我认为问题在于消息,它以长度为 x'02A8' 的十六进制表示形式开头,并且他无法转换它:

.y<?xml version="1.0" encoding="UTF-8"?><Document xmlns:xsi=...

堆栈跟踪是:

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

是否可以选择以 byte[] 形式获取消息或不进行转换。
不幸的是,发件人无法更改消息。
或者我应该使用 MQI Api?
非常感谢!
弗洛里安

最佳答案

改用这个:

Message message = mqMessageConsumer.receiveNoWait();
while (message != null) {
   if (message instanceofJMSBytesMessage) {
        String inputTmp = ((JMSBytesMessage)message).readUTF();
[...]

JMS client message conversion and encoding

关于java - JMS 读取消息 MalformedInputException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59176871/

相关文章:

java - 错误类型错误 : Cannot read property 'testName' of undefined at Object. eval

delphi - 如何在没有 HTTP 的情况下在 Delphi 中创建和处理 SOAP 请求?

jms - 多个进程为单个订阅提供服务会导致 MQRC_SUBSCRIPTION_IN_USE

ibm-mq - 强制结束和删除队列管理器

python - IBM MQ python3 模块?

message-queue - 消息 channel 和消息队列本身有什么区别?

java - 尝试使用 Spring Boots 的 RestTemplate 来使用内容类型 [text/json]

java - 应用程序在 android 中意外停止

java - 所以这是代码 : But it never considers the first string i write? 即使它仅以第一个单词结尾,它也不会计算在内

java - 使用 java 和 activemq-all 库进行 STOMP 心跳跟踪