gpt4 book ai didi

java.lang.IllegalArgumentException : local part cannot be "null" when creating a QName

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

将以下 xml 转换为文档后,我尝试将其添加到我的 SOAP 体中

<ns2:OSSRequest xmlns:ns2="http://www.someurl">
<requestBody>
<property>
<address>
<addressId>someValue</addressId>
<municipality>someValue</municipality>
<postalCode>someValue</postalCode>
<province>someValue</province>
<streetNumber>someValue</streetNumber>
</address>
</property>
<requestedProducts>
<products>someValue</products>
<products>someValue</products>
</requestedProducts>
</requestBody>
<requestHeader/>

但我收到错误

java.lang.IllegalArgumentException: local part cannot be "null" when creating a QName

这是我用来将 xml 转换为 SOAP 体的代码

MessageFactory factory = MessageFactory.newInstance();
SOAPMessage message = factory.createMessage();
SOAPHeader header_soap = message.getSOAPHeader();
SOAPBody body = message.getSOAPBody();
Document document = convertStringToDocument(xml);
body.addDocument(document); // getting error on this line

以下是将xml转换为文档的代码

private Document convertStringToDocument(String xmlStr) {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder;
try {
builder = factory.newDocumentBuilder();
Document doc = builder.parse(new InputSource(new StringReader(xmlStr)));
return doc;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}

我的 xml 无效吗?或者我在将其添加到文档时丢失了任何配置?

最佳答案

看看这篇文章,看起来您需要向 header 添加一个元素,指定 QName 和 localPart。

SOAP call fails when deployed on websphere but works fine on tomcat

关于java.lang.IllegalArgumentException : local part cannot be "null" when creating a QName,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60414545/

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