【问题标题】:Adding two Soap header tags添加两个 Soap 标头标签
【发布时间】:2017-08-25 19:11:09
【问题描述】:

我正在尝试调用需要 SOAP 标头的 SOAP 1.2 WS。

我正在使用名为 SAP Hana Cloud Integration 的集成设计器,我正在接收完整的 XML 消息,但没有标头,并且接收器系统必须接收 MessageId 才能接受数据。脚本已满,我从online documentation 拿了一个,我已经适应了我的需要:

在启用 WS-A 寻址并使其生成随机 UUID 后,我设法使用 SOAP UI 使其工作

在 SOAP UI 日志中,我发现发送给接收方的消息头如下:

<soap:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">
   <wsa:MessageID>uuid:8122ffc1-62ee-436c-a284-224e49988013</wsa:MessageID>
   <wsa:Action>http://sap.com/xi/AP/HumanCapitalManagementMasterDataReplication/Global/HumanCapitalManagementMasterDataReplicationEmployeeMasterDataReplicationIn/ReplicateCompleteEmployeeMasterDataRequest</wsa:Action>
</soap:Header>

我尝试使用 Groovy 创建相同的标头:

import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.ArrayList;
import java.util.List;
import javax.xml.namespace.QName;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.apache.cxf.binding.soap.SoapHeader;
import org.apache.cxf.headers.Header;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import com.sap.it.api.ITApiFactory;
import com.sap.it.api.securestore.SecureStoreService;
import com.sap.it.api.securestore.UserCredential;


def Message processData(Message message) {
String uuid = "uuid:" + UUID.randomUUID().toString();

String ActionUrl ="http://sap.com/xi/AP/HumanCapitalManagementMasterDataReplication/Global/HumanCapitalManagementMasterDataReplicationEmployeeMasterDataReplicationIn/ReplicateCompleteEmployeeMasterDataRequest";

DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
dbf.setIgnoringElementContentWhitespace(true);
dbf.setValidating(false);
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.newDocument();

//WSA MessageID
Element MessageId = doc.createElementNS("http://www.w3.org/2005/08/addressing", "wsa:MessageID");  
MessageId.setTextContent(uuid);
doc.appendChild(MessageId);

//WSA Action
Element Action = doc.createElementNS("http://www.w3.org/2005/08/addressing", "wsa:Action");  
Action.setTextContent(ActionUrl);
doc.appendChild(Action);

SoapHeader header = new SoapHeader(new QName("http://www.w3.org/2005/08/addressing", MessageId.getLocalName()), MessageId);         
header.setMustUnderstand(true);
List  headersList  = new ArrayList<SoapHeader>();
headersList.add(header);

SoapHeader header2 = new SoapHeader(new QName("http://www.w3.org/2005/08/addressing", Action.getLocalName()), Action);         
headersList.add(header2);
header2.setMustUnderstand(true);
message.setHeader("org.apache.cxf.headers.Header.list", headersList);

return message;
}

但是在header下设置两个根节点是不可能的,错误信息如下: 原因:org.w3c.dom.DOMException:HIERARCHY_REQUEST_ERR:试图插入不允许的节点。

关于如何实现这一目标的任何想法?谢谢 ! BR, 胺。

【问题讨论】:

  • 你的测试用例结构是什么?当 soapui 可以处理这些时,为什么要使用 groovy 呢?如果它有重复的数据,你能检查它的原始请求吗?顺便说一句,上面的脚本似乎并不完整,只是其中的一部分?最后,您是使用 groovy 还是请求测试步骤发送请求?
  • 我正在使用名为 SAP Hana Cloud Integration 的集成设计器,我正在接收完整的 XML 消息,但没有标头,并且接收器系统必须接收 MessageId 才能接受数据。脚本已满,我从在线文档中获取了一个,我已经适应了我的需要:link
  • 你能通过以前的 cmets/问题和更新吗?
  • Groovy 脚本的目标是创建请求吗?
  • 是的,只是为了修改标题。

标签: web-services groovy soapui soapheader


【解决方案1】:

通过 HCI 中的 groovy 脚本:

import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
def Message processData(Message message) {

       //Headers 
       def map = message.getHeaders();
       def value = map.get("oldHeader");
       message.setHeader("oldHeader", value + "modified");
       message.setHeader("newHeader", "yourValue");

       return message;
}

在设计器 Web 应用程序(不是 ECLIPSE)中要简单得多:

内容修饰符 -> 发送请求前的消息头 -> YourHeader |常数 | java.lang.String |你的价值...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-01-20
    • 2012-05-17
    • 1970-01-01
    • 1970-01-01
    • 2020-10-28
    • 2016-04-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多