WS02在结束点呼叫后丰富调解员

时间:2018-02-06 08:22:22

标签: wso2 wso2esb

我尝试使用浓缩介体从端点填充自定义响应

我的序列

<sequence name="GetMySqlData" trace="disable" xmlns="http://ws.apache.org/ns/synapse">

    <enrich description="AddProductData">
        <source clone="true" type="inline">
            <ProductDataMySqlDB xmlns="">
                <code/>
                <name/>
                <description/>
                <qty/>
            </ProductDataMySqlDB>
        </source>
        <target action="child" xpath="//mediate"/>
    </enrich>
    <property expression="$ctx:ProductCode" name="code" scope="default" type="STRING"/>

    <payloadFactory media-type="xml">
        <format>
            <soapenv:Envelope xmlns:dat="http://ws.wso2.org/dataservice" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
                <soapenv:Header/>
                <soapenv:Body>
                    <dat:getInventoryByCode>
                        <dat:code>$1</dat:code>
                    </dat:getInventoryByCode>
                </soapenv:Body>
            </soapenv:Envelope>
        </format>
        <args>
            <arg evaluator="xml" expression="get-property('code')"/>
        </args>
    </payloadFactory>
    <property name="HTTP_METHOD" scope="axis2" type="STRING" value="POST"/>
    <property name="SOAPAction" scope="transport" type="STRING" value="getInventoryByCode"/>
    <call>
        <endpoint key="getInventoryByCode"/>
    </call>

--PROBLEMS STARTS ---
    <enrich description="code">
        <source clone="true" xpath="//Entry/code"/>
        <target xpath="//mediate/ProductDataMySqlDB/code"/>
    </enrich>
    <enrich description="name">
        <source clone="true" xpath="//Body/Entries/Entry/name"/>
        <target xpath="//mediate/ProductDataMySqlDB/name"/>
    </enrich>
    <enrich description="description">
        <source clone="true" xpath="//Entries/Entry/description"    />
        <target xpath="//mediate/ProductDataMySqlDB/description"/>
    </enrich>
    <enrich description="qty">
        <source clone="true" xpath="//m0:Entries/m0:Entry/m0:qty"  xmlns:m0="http://ws.wso2.org/dataservice" />
        <target xpath="//mediate/ProductDataMySqlDB/qty"/>
    </enrich>
    <log level="full">
        <property expression="$body" name="MySQLResponse"/>
    </log>
    <loopback/>
</sequence>

我获得表单端点的响应就像

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Body>
      <Entries xmlns="http://ws.wso2.org/dataservice">
         <Entry>
            <code>PR2</code>
            <name>Product2</name>
            <description>Product stored in MySQL</description>
            <qty>-2</qty>
         </Entry>
      </Entries>
   </soapenv:Body>
</soapenv:Envelope>

并且日志中的错误是: 无法找到xpath指定的节点。 {} org.apache.synapse.mediators.elementary.EnrichMediator 无法从空源中获取消息。 {org.apache.synapse.mediators.elementary.EnrichMediator}

所以看起来我的源的xpath是错误的

<enrich description="code">
        <source clone="true" xpath="WHAT WOULD BE THE CORRECT PATH?"/>
        <target xpath="//mediate/ProductDataMySqlDB/code"/>
    </enrich>

thnks

1 个答案:

答案 0 :(得分:0)

在您的消息中,“Entry”和“code”节点属于命名空间“http://ws.wso2.org/dataservice”(查看“条目”根节点):您应该在源xpath中声明并使用此命名空间: / p>

<source xmlns:ds="http://ws.wso2.org/dataservice" clone="true" xpath="//ds:Entry/ds:code"/>