通过wso2esb中介累积SOAP响应和SOAP请求

时间:2017-05-22 17:38:24

标签: soap wso2 wso2esb aggregation

我有一个SOAP Web服务,可以像以下一样访问:

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
    xmlns:sys="system">
  <soap:Body>
    <sys:getAccountInfo>
        <account id="132456"/>
    </sys:getAccountInfo>
  </soap:Body>
</soap:Envelope>

此Web服务将提供以下响应:

<S:Envelope xmlns:S="http://www.w3.org/2003/05/soap-envelope">
  <S:Body>
    <ns1:getAccountInfoResponse xmlns:ns1="system">
      <balance value="555">
    </ns1:getAccountInfoResponse>
  </S:Body>
</S:Envelope>

我的挑战是提供一个代理服务,它可以接受多个帐户作为输入,并为每个帐户做出平衡响应,如下所示: 请求代理:

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
    xmlns:sys="systemProxy" xmlns:inner="innerProxyNamespace">
  <soap:Body>
    <sys:getAccountInfo>
      <inner:account id="123456"/>
      <inner:account id="123457"/>
      <inner:account id="123458"/>
    </sys:getAccountInfo>
  </soap:Body>
</soap:Envelope>

代理响应:

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
    xmlns:sys="systemProxy" xmlns:inner="innerProxyNamespace">
  <soap:Body>
    <sys:getAccountInfoResponse>

      <inner:account id="123456">
        <inner:balance value="555"/>
      </inner:account>

      <inner:account id="123457">
        <inner:balance value="666"/>
      </inner:account>

      <inner:account id="123458">
        <inner:balance value="777"/>
      </inner:account>

    </sys:getAccountInfoResponse>
  </soap:Body>
<soap:Envelope>

我正在使用迭代聚合介体将传入请求拆分为多个请求以后端并将后端的响应累积到单个邮件中。问题是,即使使用 Enrich 中介,我也无法找到将account id纳入代理响应的正确方法。

我做这样的迭代序列:

<!-- it is correct proxy incoming message format -->
<iterate attachPath="soap:Body/sys:getAccountInfo"
    expression="$body/sys:getAccountInfo/account"
    preservePayload="true"
    xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:sys="systemProxy">
  <target>
    <sequence>
      <payloadFactory>
        <!-- payloadFactory configuration skipped -->
      </payloadFactory>
      <enrich>
        <source clone="true" type="body"/>
        <target property="originalRequest" type="property"/>
      </enrich>
      <send>
        <endpoint key="BackendEndpoint"/>
      </send>
    </sequence>
  </target>
</iterate>

所以问题是 - 将来自后端的所有响应消息聚合成原始请求中的一个保留数据的正确方法是什么?

1 个答案:

答案 0 :(得分:0)

聚合中介之前使用了 Propetry PayloadFactory 调解器。它允许我在聚合之前将请求包括在响应中。然后我将它们汇总在一起。