【问题标题】:how to update soap response namespace value with wso2 ei如何使用 wso2 ei 更新肥皂响应命名空间值
【发布时间】:2019-04-02 12:40:08
【问题描述】:

我有一个代理服务来在 wso2 ei 上公开一个肥皂 api,我需要用我的代理服务更新肥皂响应的命名空间值并返回另一个命名空间值。 我已经尝试在外序列中使用丰富的调解器,如下所示。

<property name="namespace"
               scope="default"
               type="STRING"
               value="http://tempuri-updated.org/"/>
      <enrich>
        <source clone="false" property="namespace" type="property"/>
        <target xmlns:ser="http://services.samples"
                xmlns:ns="http://org.apache.synapse/xsd"
                xpath="namespace-uri($body/*)/text()"/>
     </enrich>

我收到此错误。

错误 - EnrichMediator 要丰富的目标对象无效。

我的实际soap响应如下

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   <soap:Body>
      <AddResponse xmlns="http://tempuri.org/">
         <AddResult>12</AddResult>
      </AddResponse>
   </soap:Body>
</soap:Envelope>

我的预期输出如下

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   <soap:Body>
      <AddResponse xmlns="http://tempuri-updated.org/">
         <AddResult>12</AddResult>
      </AddResponse>
   </soap:Body>
</soap:Envelope>

欢迎您的所有反馈

【问题讨论】:

    标签: soap wso2 wso2esb wso2ei


    【解决方案1】:

    这不能通过丰富的中介来完成。因为在与丰富中介目标处理[1] 相关的代码中,xpath 表达式的解析结果应该是 SOAPHeaderImpl、OMElement、OMText 或 OMAttribute 之一。由于 namespace-uri() 只是返回一个字符串值,因此要丰富的目标变得无效。作为此用例的替代方案,我们可以使用 XSLT 中介器进行 XSLT 转换。以下是我尝试过的示例 XSL 样式表。

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:template match="@* | comment() | processing-instruction()">
        <xsl:copy/>
        </xsl:template>
    
       <xsl:template match="*">
           <xsl:element name="{local-name()}"
                 namespace="http://tempuri-updated.org/">
           <xsl:apply-templates select="@* | node()"/>
           </xsl:element>
        </xsl:template>
    

    在从 EI 发送响应之前,我们可以在 XSLT 中介器中引用此样式表。新的命名空间将被添加到正文中。

    【讨论】:

    • 它工作正常,非常感谢@Thishani Lucas
    【解决方案2】:

    试试这个。

    http://codertechblog.com/wso2-change-payload-soap-envelope-namespace/

    <sequence name="seTestChangeNamespace" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
    (...)
    <enrich>
    <source type="body"/>
    <target type="property" property="INPUT_MESSAGE"/>
    </enrich>
    <enrich>
    <source type="inline">
    <myns:Envelope xmlns:myns="http://schemas.xmlsoap.org/soap/envelope/">
    <myns:Body/>
    </myns:Envelope>
    </source>
    <target type="envelope"/>
    </enrich>
    <enrich>
    <source type="property" property="INPUT_MESSAGE"/>
    <target type="body"/>
    </enrich>
    (...)
    </sequence>
    

    【讨论】:

    • 这将改变信封命名空间,并保留正文。然而,需要更改的命名空间在正文中。
    • 是的,这不是确切的答案。您可以对其进行修改以完成您想要完成的工作。
    猜你喜欢
    • 2011-03-20
    • 2013-07-03
    • 2020-01-11
    • 1970-01-01
    • 1970-01-01
    • 2014-11-20
    • 1970-01-01
    • 2019-10-01
    • 1970-01-01
    相关资源
    最近更新 更多