wso2 esb聚合和响应丰富

时间:2016-02-02 14:21:41

标签: wso2esb aggregation

我编写了一个代理来汇总来自不同DSS服务的消息,并将所有内容组合到一个响应中。代理配置如下

<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
       name="AggregateEmpMessageProxy"
       transports="https,http"
       statistics="disable"
       trace="disable"
       startOnLoad="true">
   <target>
      <inSequence>
         <log level="full"/>
         <clone>
            <target>
               <sequence>
                  <payloadFactory media-type="xml">
                     <format>
                        <p:select_with_key_emp_id_operation xmlns:p="http://ws.wso2.org/dataservice">
                           <p:id>$1</p:id>
                        </p:select_with_key_emp_id_operation>
                     </format>
                     <args>
                        <arg xmlns:m="http://ws.wso2.org/dataservice"
                             evaluator="xml"
                             expression="//m:select_with_key_emp_id_operation/m:id"/>
                     </args>
                  </payloadFactory>
                  <header name="Action"
                          scope="default"
                          value="http://ws.wso2.org/dataservice/select_with_key_emp_id_operation"/>
                  <send>
                     <endpoint name="ID_Service">
                        <address uri="http://compute-1.amazonaws.com:9767/services/emp_id_DataService.HTTPEndpoint"/>
                     </endpoint>
                  </send>
               </sequence>
            </target>
            <target>
               <sequence>
                  <payloadFactory media-type="xml">
                     <format>
                        <p:select_with_key_emp_desig_operation xmlns:p="http://ws.wso2.org/dataservice">
                           <p:id>$1</p:id>
                        </p:select_with_key_emp_desig_operation>
                     </format>
                     <args>
                        <arg xmlns:m="http://ws.wso2.org/dataservice"
                             evaluator="xml"
                             expression="//m:select_with_key_emp_id_operation/m:id"/>
                     </args>
                  </payloadFactory>
                  <header name="Action"
                          scope="default"
                          value="http://ws.wso2.org/dataservice/select_with_key_emp_desig_operation"/>
                  <send>
                     <endpoint name="Exp_Service">
                        <address uri="http://compute-1.amazonaws.com:9767/services/emp_desig_DataService.HTTPEndpoint"/>
                     </endpoint>
                  </send>
               </sequence>
            </target>
            <target>
               <sequence>
                  <payloadFactory media-type="xml">
                     <format>
                        <p:select_with_key_emp_exp_operation xmlns:p="http://ws.wso2.org/dataservice">
                           <p:id>$1</p:id>
                        </p:select_with_key_emp_exp_operation>
                     </format>
                     <args>
                        <arg xmlns:m="http://ws.wso2.org/dataservice"
                             evaluator="xml"
                             expression="//m:select_with_key_emp_id_operation/m:id"/>
                     </args>
                  </payloadFactory>
                  <header name="Action"
                          scope="default"
                          value="http://ws.wso2.org/dataservice/select_with_key_emp_exp_operation"/>
                  <send>
                     <endpoint name="Desig_Service">
                        <address uri="http://compute-1.amazonaws.com:9767/services/emp_exp_DataService.HTTPEndpoint"/>
                     </endpoint>
                  </send>
               </sequence>
            </target>
         </clone>
      </inSequence>
      <outSequence>
         <aggregate>
            <completeCondition>
               <messageCount/>
            </completeCondition>
            <onComplete xmlns:s12="http://www.w3.org/2003/05/soap-envelope"
                        xmlns:s11="http://schemas.xmlsoap.org/soap/envelope/"
                        expression="/s11:Envelope/s11:Body/child::*[position()=1] | /s12:Envelope/s12:Body/child::*[position()=1]">
               <send/>
            </onComplete>
         </aggregate>
      </outSequence>
   </target>
   <parameter name="enableMTOM">false</parameter>
   <description/>
</proxy>

我得到的回应是

<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
   <soapenv:Body>
      <result xmlns="http://ws.wso2.org/dataservice">
         <id>1</id>
         <name>meeran</name>
      </result>
      <result xmlns="http://ws.wso2.org/dataservice">
         <designation>engineer</designation>
         <level>B2</level>
      </result>
      <result xmlns="http://ws.wso2.org/dataservice">
         <age>26</age>
         <exp>3</exp>
      </result>
   </soapenv:Body>
</soapenv:Envelope>

但我回答的是

<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
       <soapenv:Body>
          <result xmlns="http://ws.wso2.org/dataservice">
             <id>1</id>
             <name>meeran</name>          
             <designation>engineer</designation>
             <level>B2</level>          
             <age>26</age>
             <exp>3</exp>
          </result>
       </soapenv:Body>
    </soapenv:Envelope>

如何实现上述回应?我应该在聚合调解员之后使用什么调解员。请帮忙。

1 个答案:

答案 0 :(得分:0)

在aggregate / onComplete内部,在发送之前,您可以使用xslt mediatior并在xsl中,在结果节点上定义模板并复制它的所有子项。