【问题标题】:How to change the child element in SOAPBODY如何更改 SOAPBODY 中的子元素
【发布时间】:2014-01-02 15:09:01
【问题描述】:

我有一个soapMessage,我正在写入一个ByteArrayOutputStream 来记录请求 但是我必须在记录之前更改 p803:Credential 子元素值,我该怎么做?

ByteArrayOutputStream out = new ByteArrayOutputStream();
soapMessageCtx.getMessage().writeTo(out);

这里是请求 xml

<soapenv:Body>
<p803:multiple xmlns:p803="http://www.abc.com/model">

<p803:RequestContext>
<p803:Credential>2222222/iuuiiiuuuu</p803:Credential>

【问题讨论】:

  • 你想在你的 SoapHandler 中改变它吗?
  • 也许您可以提供一些上下文?在记录之前处理消息似乎没有意义(至少对我而言)。
  • 我需要更改 的值
  • @bitil 我需要使用任何现有方法更改肥皂正文而不是标题中的 的值@home 我不想使用凭据记录请求,即原始请求在我们操纵之前将保持不变

标签: java web-services soap xml-parsing


【解决方案1】:

试试这个:

SOAPMessage soapMsg = soapMessageCtx.getMessage();
NodeList credentials = soapMsg
                        .getSOAPBody()
                        .getElementsByTagNameNS("http://rsi.chase.com/model", "Credential");

int len = credentials.length();
for(int i = 0; i < len; i++) { 
    credentials.item(i).setTextContent("new credential content goes here...");
}

ByteArrayOutputStream out = new ByteArrayOutputStream();
soapMsg.writeTo(out);

// ...

【讨论】:

  • 我们不能使用任何现有的 SOAPEnvelope 方法吗?
  • @SatishUppalapati soapMessageCtx 的类是什么?
  • 导入 javax.xml.rpc.handler.soap.SOAPMessageContext
  • 非常感谢,这正是我要找的
猜你喜欢
  • 2015-09-30
  • 2022-11-03
  • 1970-01-01
  • 2020-09-13
  • 2011-05-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多