【问题标题】:WSO2 ESB adding prefix to headerWSO2 ESB 向标头添加前缀
【发布时间】:2020-12-19 04:14:16
【问题描述】:

我尝试将 WSO2 ESB 与 SAP 解决方案管理器 Web 服务一起用作端点。 为了向 Web 服务发送消息,我需要修改 SOAP 标头。 在用谷歌搜索时,我发现我可以使用 Enrich Mediator。但我找不到如何将前缀添加到标题的示例。

我拥有的是这样的:

<?xml version='1.0' encoding='utf-8'?>
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<soapenv:Body>
<urn:ReadCompleteIncident>
<IncidentGuid>xxxxx</IncidentGuid>
<SystemGuid>xxx</SystemGuid>
</urn:ReadCompleteIncident>
</soapenv:Body>
</soapenv:Envelope>

但我收到一个错误,因为 ESB 不知道前缀“urn:”。所以我必须在标题中添加“xmlns:urn="urn:sap-com:document:sap:soap:functions:mc-style"" 以获得这个:

<?xml version='1.0' encoding='utf-8'?>
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope" xmlns:urn="urn:sap-com:document:sap:soap:functions:mc-style">
<soapenv:Body>
<urn:ReadCompleteIncident>
<IncidentGuid>xxxxx</IncidentGuid>
<SystemGuid>xxx</SystemGuid>
</urn:ReadCompleteIncident>
</soapenv:Body>
</soapenv:Envelope>

如何使用 Enrich Mediator 执行此操作?还是有其他解决方案?

谢谢你:)

【问题讨论】:

    标签: soap header wso2 esb sap-solution-manager


    【解决方案1】:

    您可以使用 WSO2 ESB 的 Header mediator 来实现您的要求。

    <header name="Action" value="urn:ReadCompleteIncident"/>
    

    您可以参考此链接了解更多信息。

    http://docs.wso2.org/wiki/display/ESB460/Header+Mediator

    【讨论】:

    • 如果我尝试这个,我会得到:[2013-06-12 12:57:46,341] INFO - LogMediator To: /services/Atestproxy, WSAction: urn:ReadCompleteIncident, SOAPAction: urn :ReadCompleteIncident, MessageID: urn:uuid:79a11ebf-fee6-434e-a4ea-591a45b29d3a, 方向: request, Envelope: w3.org/2003/05/soap-envelope"><soapenv:Body > 这不是我需要的。我需要获取文本 "xmlns:urn="urn:sap-com:document:sap:soap:functions :mc-style"" 进入 SOAP Envelope Header,就像您在上面的第二个 sn-p 中看到的那样。
    【解决方案2】:

    我使用 Enrich Mediator 解决了这个问题。例如,这是我的代理。

    向 ESB 输入消息:

    <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
       <soap:Header/>
       <soap:Body>
          <content>Message content</content>
       </soap:Body>
    </soap:Envelope>
    

    SAP PI 的必需输入消息:

    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:xxxx">
       <soapenv:Header/>
       <soapenv:Body>
          <urn:xxxx>
             <content>Message content</content>
          </urn:xxxx>
       </soapenv:Body>
    </soapenv:Envelope>
    

    解决方案:

    <proxy xmlns="http://ws.apache.org/ns/synapse"
           name="WSO2toSAP"
           transports="https,http"
           statistics="disable"
           trace="disable"
           startOnLoad="true">
       <target>
          <inSequence>
             <property name="OUT_ONLY" value="true" scope="default" type="STRING"/>
             <property name="FORCE_SC_ACCEPTED"
                       value="true"
                       scope="axis2"
                       type="STRING"/>
             <log level="full"/>
             <enrich>
                <source type="body" clone="true"/>
                <target type="property" property="INPUT_MESSAGE"/>
             </enrich>
             <enrich>
                <source type="inline" clone="true">
                   <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
                      <soapenv:Body/>
                   </soapenv:Envelope>
                </source>
                <target type="envelope"/>
             </enrich>
             <enrich>
                <source type="inline" clone="true">
                   <urn:xxxx xmlns:urn="urn:xxxx"/>
                </source>
                <target type="body"/>
             </enrich>
             <enrich>
                <source type="property" clone="true" property="INPUT_MESSAGE"/>
                <target type="body" action="child"/>
             </enrich>
             <log level="full"/>
             <send>
                <endpoint key="WSO2toSAP_endpoint"/>
             </send>
          </inSequence>
       </target>
       <description/>
    </proxy>
    

    希望能帮到你:)

    【讨论】:

      【解决方案3】:

      我认为有多种方法可以解决这个问题 -

      1. payloadFactory 调解器来操纵请求或响应。​​

      2. 使用脚本调解器 - 查看此页面 http://abeykoon.blogspot.com/2013/03/encoding-and-decoding-xml-using-wso2-esb.html#comment-form 了解有关如何使用脚本的更多详细信息。如您所见,博主正在使用payloadFactory生成请求,然后使用脚本对其进行操作以获得所需的效果。

      如果我有时间,我会尝试使用脚本为您构建一个快速的解决方案。

      一切顺利..

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-06-24
        • 2023-01-26
        • 2019-06-30
        • 2012-04-12
        • 2017-12-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多