簡體   English   中英

JMS 讀取消息 MalformedInputException

[英]JMS Read Message MalformedInputException


使用 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

是否可以選擇將消息作為字節 [] 或不進行轉換。
不幸的是,發件人無法更改消息。
還是我應該使用 MQI Api?
非常感謝!
弗洛里安

改用這個:

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

JMS 客戶端消息轉換和編碼

我認為就我而言,不更改消息就沒有解決方案。 要獲得 JMSByteMessage,消息格式必須是 MQ-None,使用 MQ-String,您總是會獲得 JMSTextMessage。 也許有 MQI 的方法,但是因為我的程序是 IMS JMP,所以我不允許使用 MQI。 我要求消息的生產者更改它。 感謝 JoshMC 的回答

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM