gpt4 book ai didi

java - SoapMessage.writeTo 对带有附件的 SOAPMessage 抛出无内容异常

转载 作者:太空宇宙 更新时间:2023-11-04 14:06:32 26 4
gpt4 key购买 nike

我正在从 SOAP 消息中获取附件并在我的应用程序中使用它们。
我不会从原始消息中删除附件。之后,我尝试使用以下代码将原始 包含附件 (SwA) 的 SOAPMessage 转换为字符串:

ByteArrayOutputStream stream = new ByteArrayOutputStream();
soapMsg.writeTo(stream);
String message = new String(stream.toByteArray(), "utf-8");

它抛出以下异常:

com.sun.xml.internal.messaging.saaj.soap.MessageImpl writeTo
SEVERE: SAAJ0540: Error during saving a multipart message
com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Error during saving a multipart message
at com.sun.xml.internal.messaging.saaj.soap.MessageImpl.writeTo(MessageImpl.java:1233)
at main.SOAPMTOMUtilityTest.main(SOAPMTOMUtilityTest.java:161)
Caused by: com.sun.xml.internal.messaging.saaj.packaging.mime.MessagingException: no content
at com.sun.xml.internal.messaging.saaj.packaging.mime.internet.MimeBodyPart.writeTo(MimeBodyPart.java:905)
at com.sun.xml.internal.messaging.saaj.packaging.mime.internet.MimeMultipart.writeTo(MimeMultipart.java:266)
at com.sun.xml.internal.messaging.saaj.soap.MessageImpl.writeTo(MessageImpl.java:1224)
... 1 more

CAUSE:

com.sun.xml.internal.messaging.saaj.packaging.mime.MessagingException: no content
at com.sun.xml.internal.messaging.saaj.packaging.mime.internet.MimeBodyPart.writeTo(MimeBodyPart.java:905)
at com.sun.xml.internal.messaging.saaj.packaging.mime.internet.MimeMultipart.writeTo(MimeMultipart.java:266)
at com.sun.xml.internal.messaging.saaj.soap.MessageImpl.writeTo(MessageImpl.java:1224)
at main.SOAPMTOMUtilityTest.main(SOAPMTOMUtilityTest.java:161)

有人知道这个吗?

_谢谢,不山

最佳答案

也许尝试使用 StringBuilder 而不是 String?如下所示使用 StringBuilder.append() 对我来说很有效,而我根本无法让新实例化的(如您使用的)String() 工作。

        // This stringbuilder will hold the initial message we sent to SOA
StringBuilder soapMsg = new StringBuilder();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
SOAPMessage message = getSoapMessageFromString(foo);

// Write the initial message to the byte array output string
message.writeTo(baos);

// append the baos data (initial message) to the stringbuilder for
// processing
soapMsg.append(baos.toString());

// Reset the baos for use on the response message
baos.reset();

关于java - SoapMessage.writeTo 对带有附件的 SOAPMessage 抛出无内容异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28806028/

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