簡體   English   中英

我發送到隊列的SOAP請求在IBM MQ上變得格式錯誤

[英]The SOAP requests I am sending to the queue are becoming malformed on IBM MQ

我已經用Java創建了一個實用程序,該實用程序可以拾取XML文件,並將其發送到IBM MQ上的隊列。 當我進入IBM MQ Explorer時,該消息顯示為已接收,但如果它前面有一個ASCII字符(如下圖的“ Message Data”字段中所示),導致該消息未被識別為隊列可以處理的格式正確的SOAP消息。 我嘗試使用XML編輯器來確保我的XML文件沒有任何非空白字符,但這並不能解決問題。

在此處輸入圖片說明

這是我用來將文件放入隊列的代碼:

 * sending message to MQ
 * 
 * @param file
 * @return messageId
 * @throws UnsupportedEncodingException
 * @throws IOException
 */
private byte[] sendMessageToMQ(File file) throws UnsupportedEncodingException, IOException {

    int openOptions = MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_OUTPUT;
    try {
        defaultLocalQueue = qManager.accessQueue(queueName, openOptions);

        MQMessage putMessage = new MQMessage();

        String msg = readFile(file);
        putMessage.writeUTF(msg);

        // specify the message options...
        MQPutMessageOptions pmo = new MQPutMessageOptions();
        // accept
        // put the message on the queue
        defaultLocalQueue.put(putMessage, pmo);

        System.out.println("Message is put on MQ.");

        return putMessage.messageId;

    } catch (MQException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}

文檔記錄writeUTF帶有長度前綴

https://www.ibm.com/support/knowledgecenter/en/SSFKSJ_9.0.0/com.ibm.mq.dev.doc/q030840_.htm

注意:MQMessage的writeUTF()方法自動對字符串的長度及其包含的Unicode字節進行編碼。 當您的消息將被另一個Java程序(使用readUTF())讀取時,這是發送字符串信息的最簡單方法。

您可以將MQMessage的characterSet設置為1208(或根據資源管理器,當前該消息的ccsid是什么),然后使用writeString方法

https://www.ibm.com/developerworks/community/forums/html/topic?id=77777777-0000-0000-0000-000000023465

如果您的消息中需要UTF-8文本,但是不需要兩個字節的長度字段,請將characterSet字段設置為1208(這是UTF-8的CCSID),然后使用writeString()。

請注意,盡管本文討論的是.net,但對於Java也是如此: http : //www-01.ibm.com/support/docview.wss? uid= swg21267940

暫無
暫無

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

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