【问题标题】:WSO2 ESB property incorrect scopeWSO2 ESB 属性范围不正确
【发布时间】:2015-12-15 19:39:02
【问题描述】:

我有下一个序列:

<payloadFactory>
    <format>
        <cb:accounts/>
    </format>
    <args/>
</payloadFactory>
<property name="accounts" type="OM" expression="//cb:accounts" />
...
<iterate id="accountIterator" continueParent="true" sequential="true" expression="//cb:accounts/cb:accountId">
    <target>
        <sequence>
            ...
            <property name="accounts" type="OM" expression="//*" />
        </sequence>
    </target>
</iterate> 
<aggregate id="accountIterator">
    <onComplete expression="$body/child::*[fn:position()=1]">
        <log level="custom" />
    </onComplete>
</aggregate>
<enrich>
    <source type="custom" xpath="get-property('accounts')"/>
    <target type="body" />
</enrich>

为什么在“迭代”中介内设置的名为“accounts”的属性在“迭代”中介外有空值?

谢谢

【问题讨论】:

    标签: properties wso2 esb mediator


    【解决方案1】:

    迭代器内部的流程在单独的线程上运行,外部不可见。因此,您无法访问设置在迭代器调解器内部的属性,但也可以在外部访问。

    【讨论】:

    • 那么,没有办法从迭代中介器返回值吗?我需要在循环内累积标注响应,然后将这组响应作为子元素插入正文消息中,我该怎么做?
    • 为此,您无需访问外部迭代器中介内定义的属性。内部迭代器调解器原始消息根据定义的 xpath 分为多条消息。所以在迭代器中介上下文中会有多条消息。
    • 对于您的方案,使用调用中介器并使用聚合器中介器来组合结果。使用 call mediator 会比 callout mediator 更快。
    • 是的,但无论如何我都需要使用迭代调解器,因为我不知道我有多少子元素。第一步,我接收带有元素 ID 列表的 XML,我需要根据元素数量进行多次调用。第二步,我需要团结一致的回应。最后第三步,我需要将一组统一的响应插入到带有 id 的 XML 中。
    • 第一步你可以使用迭代器中介器。在其中,您可以使用定义了接收序列的发送调解器。因此,每个响应都会命中该序列,并在该序列内部丰富 id 并最后插入环回中介。然后响应将被转发到 outSequence 并且在 outSequence 内部具有聚合器调解器。聚合后,您可以使用 xslt 调解器转换为您的格式。
    【解决方案2】:

    在调用每个迭代周期之前,消息上下文将被克隆,并且仅在迭代器目标内的上下文中可用。因此,默认情况下无法在迭代器之外的突触/默认范围内执行操作。如果您想存储全局内容,请使用 operation scope 的属性。

    • 在迭代器将您的属性分配给操作范围之前
    • 内部迭代器 - 进行修改
    • 在迭代器之外 - 将您的属性分配给默认范围(如果您想将其恢复为默认范围)

    例如使用下面的结构:

        <!--assign your property to operation scope-->
        <property name="ITERATOR_DATA_PAYLOAD"
                   expression="get-property('DATA_PAYLOAD')"
                   scope="operation"
                   type="OM"/>
    
    <iterate xmlns:ns="http://org.apache.synapse/xsd"
                  continueParent="true"
                  expression="//bookstore/book"
                  sequential="true">
            <target>
               <sequence>
              <!--if you want to assign the property-->
                  <property name="DATA_PAYLOAD"
                            expression="get-property('operation','ITERATOR_DATA_PAYLOAD')"
                            type="OM"/>
             </sequence>
            </target>
    </iterate>
         <!--Outside the iterator-->
         <property xmlns:ns="http://org.apache.synapse/xsd"
                   name="NEW_DATA_PAYLOAD"
                   expression="get-property('operation','ITERATOR_DATA_PAYLOAD')"
                   type="OM"/>
    

    【讨论】:

      猜你喜欢
      • 2013-06-16
      • 1970-01-01
      • 2015-09-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-24
      • 2012-06-21
      • 2015-03-27
      相关资源
      最近更新 更多