gpt4 book ai didi

java - 我发送到队列的 SOAP 请求在 IBM MQ 上格式不正确

转载 作者:行者123 更新时间:2023-12-01 18:02:44 27 4
gpt4 key购买 nike

我用 Java 创建了一个实用程序,它可以拾取 XML 文件,并将它们发送到 IBM MQ 上的队列。当我进入 IBM MQ Explorer 时,消息显示为已接收,但如果消息前面有一个 ASCII 字符(如下图中的“消息数据”字段所示),这会导致它不被识别为消息队列可以处理的格式正确的 SOAP 消息。我尝试使用 XML 编辑器来确保我的 XML 文件没有任何非空白字符,但这并没有解决问题。

enter image description here

这是我用来将文件放入队列的代码:

 * 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

Note: The writeUTF() method of MQMessage automatically encodes the length of the string as well as the Unicode bytes it contains. When your message will be read by another Java program (using readUTF()), this is the simplest way to send string information.

您可以将 MQMessage 的字符集设置为 1208(或者根据资源管理器当前消息的 ccsid),然后使用 writeString 方法

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

If you need UTF-8 text in your message, but don't require the two byte length field, set the characterSet field to 1208 (which is the CCSID for UTF-8) and use writeString().

注意,虽然本文讨论的是.net,但对于 Java 来说也是如此: http://www-01.ibm.com/support/docview.wss?uid=swg21267940

关于java - 我发送到队列的 SOAP 请求在 IBM MQ 上格式不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39477945/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com