WSO2 ESB - 修改代理服务中的输出消息内容

时间:2016-10-31 07:18:11

标签: wso2 wso2esb

我使用WSO2 ESB(4.8.1)并想知道如何获得输出,如“预期输出”块所示。

提前致谢。

代理服务定义:

    <?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
       name="DATA_WS"
       transports="https,http"
       statistics="disable"
       trace="enable"
       startOnLoad="true">
   <target>
      <inSequence>
         <switch xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
                 source="local-name(/*/*/*[1])">
            <case regex="getSavProducts">
               <payloadFactory media-type="xml">
                  <format>
                     <soapenv:Envelope xmlns:dat="http://ws.wso2.org/dataservice">
                        <soapenv:Header/>
                        <soapenv:Body>
                           <dat:getSavProducts/>
                        </soapenv:Body>
                     </soapenv:Envelope>
                  </format>
                  <args/>
               </payloadFactory>
               <log level="custom">
                  <property name="operation" value="getSavProducts"/>
               </log>
               <send>
                  <endpoint>
                     <address uri="http://dssserver:9783/services/DATA_WS/getSavProducts"/>
                  </endpoint>
               </send>
            </case>
            <default/>
         </switch>
      </inSequence>
      <outSequence>
         <iterate xmlns:m="http://ws.wso2.org/dataservice"
                  id="iter1"
                  expression="//m:Entries/m:Entry">
            <target>
               <sequence>
                  <log level="custom">
                     <property name="output111" expression="//m:PRODUCT_DESC/text()"/>
                  </log>
                  <send/>
               </sequence>
            </target>
         </iterate>
      </outSequence>
   </target>
   <publishWSDL key="gov:/IB/DATA_WS.wsdl"/>
   <parameter name="useOriginalwsdl">true</parameter>
   <parameter name="disableOperationValidation">true</parameter>
   <description/>
</proxy>

这是我在调用服务时得到的输出

    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Body>
      <Entry xmlns="http://ws.wso2.org/dataservice">
         <PRODUCT_CODE>2</PRODUCT_CODE>
         <SUB_PRODUCT_CODE>20</SUB_PRODUCT_CODE>
         <PRODUCT_DESC>TEST SUB PRODUCT</PRODUCT_DESC>
         <STATUS>A</STATUS>
         <PRODUCT_CATEGORY>G</PRODUCT_CATEGORY>
         <PRODUCT_NAME>General</PRODUCT_NAME>
         <CUR_CODE>GBP</CUR_CODE>
         <CHANNEL>USSD</CHANNEL>
      </Entry>
   </soapenv:Body>
</soapenv:Envelope>

日志

TID: [0] [ESB] [2016-10-31 10:39:33,761]  INFO {org.apache.synapse.mediators.builtin.LogMediator} -  output111 = TEST SUB PRODUCT {org.apache.synapse.mediators.builtin.LogMediator}
TID: [0] [ESB] [2016-10-31 10:39:33,761]  INFO {org.apache.synapse.mediators.builtin.LogMediator} -  output111 = TEST SUB PRODUCT 2 {org.apache.synapse.mediators.builtin.LogMediator}
TID: [0] [ESB] [2016-10-31 10:39:33,768]  INFO {org.apache.synapse.mediators.builtin.LogMediator} -  output111 = TEST SUB PRODUCT 3 {org.apache.synapse.mediators.builtin.LogMediator}

预期输出

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   <SOAP-ENV:Body>
      <ns1:getSavProductsResponse SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="DATA_WS">
         <return xsi:type="ns2:dbconncyberfin_DbtSavProdcutTab" xmlns:ns2="http://dbconncyberfin/DATA_WS.xsd">
            <array xsi:type="ns3:Array" ns3:arrayType="ns2:dbconncyberfin_DbtSavProdcutUser[16]" xmlns:ns3="http://schemas.xmlsoap.org/soap/encoding/">
               <item xsi:type="ns2:dbconncyberfin_DbtSavProdcutUser">
                  <channel xsi:type="xsd:string">USSD</channel>
                  <curCode xsi:type="xsd:string">EUR</curCode>
                  <productCategory xsi:type="xsd:string">G</productCategory>
                  <productCode xsi:type="xsd:string">2</productCode>
                  <productDesc xsi:type="xsd:string">TEST SUB PRODUCT</productDesc>
                  <productName xsi:type="xsd:string">General</productName>
                  <status xsi:type="xsd:string">A</status>
                  <subProductCode xsi:type="xsd:string">20</subProductCode>
               </item>
               <item xsi:type="ns2:dbconncyberfin_DbtSavProdcutUser">
                  <channel xsi:type="xsd:string">USSD</channel>
                  <curCode xsi:type="xsd:string">USD</curCode>
                  <productCategory xsi:type="xsd:string">G</productCategory>
                  <productCode xsi:type="xsd:string">2</productCode>
                  <productDesc xsi:type="xsd:string">TEST SUB PRODUCT 2</productDesc>
                  <productName xsi:type="xsd:string">General</productName>
                  <status xsi:type="xsd:string">A</status>
                  <subProductCode xsi:type="xsd:string">54</subProductCode>
               </item>
               <item xsi:type="ns2:dbconncyberfin_DbtSavProdcutUser">
                  <channel xsi:type="xsd:string">USSD</channel>
                  <curCode xsi:type="xsd:string">SLR</curCode>
                  <productCategory xsi:type="xsd:string">G</productCategory>
                  <productCode xsi:type="xsd:string">1</productCode>
                  <productDesc xsi:type="xsd:string">TEST SUB PRODUCT 3</productDesc>
                  <productName xsi:type="xsd:string">General</productName>
                  <status xsi:type="xsd:string">A</status>
                  <subProductCode xsi:type="xsd:string">00</subProductCode>
               </item>
            </array>
         </return>
      </ns1:getSavProductsResponse>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope> 

1 个答案:

答案 0 :(得分:0)

使用xsl和xslt介体解决了它。

<强> item1.xsl

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:fn="http://www.w3.org/2005/02/xpath-functions" 
xmlns:m="http://ws.wso2.org/dataservice" version="2.0" exclude-result-prefixes="m fn"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ns1="DATA_WS"> 
    <xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/> 
    <xsl:template match="/"> 
    <ns1:getSavProductsResponse>
    <return xsi:type="ns2:dbconncyberfin_DbtSavProdcutTab" xmlns:ns2="http://dbconncyberfin/DATA_WS.xsd">
    <array xsi:type="ns3:Array" ns3:arrayType="ns2:dbconncyberfin_DbtSavProdcutUser[16]" xmlns:ns3="http://schemas.xmlsoap.org/soap/encoding/">
            <xsl:for-each select="//m:Entries/m:Entry"> 
             <item  xsi:type="ns2:dbconncyberfin_DbtSavProdcutUser">
              <channel xsi:type="xsd:string"><xsl:value-of select="m:CHANNEL"/></channel>
              <curCode xsi:type="xsd:string"><xsl:value-of select="m:CUR_CODE"/></curCode>
              <productCategory xsi:type="xsd:string"><xsl:value-of select="m:PRODUCT_CATEGORY"/></productCategory>
              <productCode xsi:type="xsd:string"><xsl:value-of select="m:PRODUCT_CODE"/></productCode>
              <productDesc xsi:type="xsd:string"><xsl:value-of select="m:PRODUCT_DESC"/></productDesc>
              <productName xsi:type="xsd:string"><xsl:value-of select="m:PRODUCT_NAME"/></productName>
              <status xsi:type="xsd:string"><xsl:value-of select="m:STATUS"/></status>
              <subProductCode xsi:type="xsd:string"><xsl:value-of select="m:SUB_PRODUCT_CODE"/></subProductCode>
             </item>
        </xsl:for-each> 
    </array>
     </return>
    </ns1:getSavProductsResponse>
    </xsl:template> 

<强> outSequence

      <outSequence>
     <xslt key="gov:/xslt/item1.xsl"/>
     <enrich>
        <source type="body" clone="true"/>
        <target type="property" property="original"/>
     </enrich>
     <payloadFactory media-type="xml">
        <format>
           <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
                              xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
              <SOAP-ENV:Body/>
           </SOAP-ENV:Envelope>
        </format>
        <args/>
     </payloadFactory>
     <enrich>
        <source type="property" clone="true" property="original"/>
        <target type="body"/>
     </enrich>
     <send/>
  </outSequence>