Java - 如何摆脱 Soap 请求中的名称空间 (ns2)

发布于 2025-01-13 05:59:05 字数 1221 浏览 2 评论 0原文

我正在使用 JAXB 打印出与我的代码生成的 Soap UI 请求相对应的 XML 字符串。无论出于何种原因,JAXB 都会自动将“ns2”名称空间放置在我生成的请求的开始和结束标记中,从而导致 SoapFault 错误。

对于上下文,我生成的请求如下所示:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:com.unsolicited.notifications">
   <soapenv:Header/>
   <soapenv:Body>
      <urn:sendUnsolicitedNotification>
         <ns2:UnsolicitedNotificationRequest xmlns:ns2="urn:com.unsolicited.notifications.bo">
            <otherInfo>
               <key>clientEmail</key>
               <value>[email protected]</value>
            </otherInfo>
            <otherInfo>
               <key>emailBody</key>
               <value>This is my email body</value>
            </otherInfo>
         </ns2:UnsolicitedNotificationRequest xmlns:ns2="urn:com.unsolicited.notifications.bo">
      </urn:sendUnsolicitedNotification>
   </soapenv:Body>
</soapenv:Envelope>

正如您所看到的 UnsolicitedNotificationRequest 的开始和结束标记具有我想摆脱的 ns2 命名空间。

I am using JAXB to print out the XML string that corresponds to the Soap UI request that my code is generating. For whatever reason, JAXB is automatically placing "ns2" namespaces in the opening and closing tags of my generated request, which consequently leads to a SoapFault error.

For context this is how my generated request looks like:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:com.unsolicited.notifications">
   <soapenv:Header/>
   <soapenv:Body>
      <urn:sendUnsolicitedNotification>
         <ns2:UnsolicitedNotificationRequest xmlns:ns2="urn:com.unsolicited.notifications.bo">
            <otherInfo>
               <key>clientEmail</key>
               <value>[email protected]</value>
            </otherInfo>
            <otherInfo>
               <key>emailBody</key>
               <value>This is my email body</value>
            </otherInfo>
         </ns2:UnsolicitedNotificationRequest xmlns:ns2="urn:com.unsolicited.notifications.bo">
      </urn:sendUnsolicitedNotification>
   </soapenv:Body>
</soapenv:Envelope>

As you can see the opening and closing tags for UnsolicitedNotificationRequest has ns2 namespaces which I would like to get rid of.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

狂之美人 2025-01-20 05:59:05

当您说失败时,是否由于命名空间而导致您针对测试步骤的断言失败?如果是这样,断言窗口中有一个名为“忽略命名空间前缀?”的复选框,它正是这样做的。

When you say failing, is it failing an assertion you have against the test step because of the namespace? If so, there is a checkbox in the assertion window named something like "Ignore Namespace Prefixes?", which does exactly that.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文