wso2 / product-ei

An open source, a high-performance hybrid integration platform that allows developers quick integration with any application, data, or system.
https://wso2.com/integration/
Apache License 2.0
367 stars 276 forks source link

Log and Enrich mediator xpath behaves differently #3713

Open TomasTokaMrazek opened 5 years ago

TomasTokaMrazek commented 5 years ago

Description:

I have particular DSS:

<data name="FalconDatabase" serviceNamespace="cz.styrax.sodexo.middleware.Falcon" transports="local http https">
    <config id="Falcon">
        <property name="driverClassName">${middleware.database.falcon.driverClassName}</property>
        <property name="url">${middleware.database.falcon.url}</property>
        <property name="username">${middleware.database.falcon.username}</property>
        <property name="password">${middleware.database.falcon.password}</property>
    </config>
    <query id="call_receive" useConfig="Falcon">
        <sql>{call ?:=connector.receive_wrapper(?,?,?,?,?,?,?,?)}</sql>
        <result element="falcon" rowName="">
            <element column="result" name="result"/>
        </result>
        <param name="result" sqlType="STRING" type="OUT"/>
        <param name="sender" sqlType="STRING"/>
        <param name="sender_id" sqlType="STRING"/>
        <param name="entity" sqlType="STRING"/>
        <param name="operation" sqlType="STRING"/>
        <param name="recipient" sqlType="STRING"/>
        <param name="recipient_id" sqlType="STRING"/>
        <param name="output_id" sqlType="INTEGER"/>
        <param name="content" sqlType="STRING"/>
    </query>
    <operation name="callReceive">
        <call-query href="call_receive">
            <with-param name="sender" query-param="sender"/>
            <with-param name="sender_id" query-param="sender_id"/>
            <with-param name="entity" query-param="entity"/>
            <with-param name="operation" query-param="operation"/>
            <with-param name="recipient" query-param="recipient"/>
            <with-param name="recipient_id" query-param="recipient_id"/>
            <with-param name="output_id" query-param="output_id"/>
            <with-param name="content" query-param="content"/>
        </call-query>
    </operation>
</data>

When I call this service from ESB, I correctly get response. Full envelope log (formatted):

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Body>
      <falcon xmlns="cz.styrax.sodexo.middleware.Falcon">
         <result>
            <response result="INPUT">
               <mw caller="FALCON" caller_id="161850" entity="BANKOVNI UCET" operation="ID" partner="SPO" partner_id="146758" />
            </response>
         </result>
      </falcon>
   </soapenv:Body>
</soapenv:Envelope>

I'm trying to enrich element to body, but I have trouble with xpath error, where elements are not found. So I tried several xpath options in Log Mediator.

<log level="full">
   <property xmlns:el1="cz.styrax.sodexo.middleware.Falcon" expression="$body/el1:falcon/result/*" name="1" />
   <property xmlns:el1="cz.styrax.sodexo.middleware.Falcon" expression="$body/el1:falcon/el1:result" name="2" />
   <property xmlns:el1="cz.styrax.sodexo.middleware.Falcon" expression="$body/el1:falcon/el1:result/*" name="3" />
   <property xmlns:el1="cz.styrax.sodexo.middleware.Falcon" expression="$body/falcon/result/*" name="4" />
   <property xmlns:el1="cz.styrax.sodexo.middleware.Falcon" expression="$body/el1:falcon/*" name="5" />
   <property xmlns:el1="cz.styrax.sodexo.middleware.Falcon" expression="$body/falcon/*" name="6" />
</log>

and here's the log result (formatted):

To: http://www.w3.org/2005/08/addressing/anonymous, WSAction: , SOAPAction: , MessageID: urn:uuid:d8aec2de-b1d9-457b-a7f3-638086a1791d, Direction: request, 1 = , 2 = <response result="INPUT"><mw caller="FALCON" caller_id="161850" entity="BANKOVNI UCET" operation="ID" partner="SPO" partner_id="146758"/></response>, 3 = , 4 = , 5 = <response result="INPUT"><mw caller="FALCON" caller_id="161850" entity="BANKOVNI UCET" operation="ID" partner="SPO" partner_id="146758"/></response>, 6 = , Envelope: <?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><falcon xmlns="cz.styrax.sodexo.middleware.Falcon"><result><response result="INPUT"><mw caller="FALCON" caller_id="161850" entity="BANKOVNI UCET" operation="ID" partner="SPO" partner_id="146758"/></response></result></falcon></soapenv:Body></soapenv:Envelope>

1 – correctly fails due to missing el1 namespace prefix in <result> 2 – selects <response> node instead of <result> node 3 – finds nothing instead of <response> node 4 – correctly fails due to missing el1 namespace prefix everywhere 5 – same as 2, should select <result> node instead of <response> 6 – correctly fails due to missing el1 namespace prefix in <falcon>

Strangely enough, right after log mediator I have enrich mediator.

<enrich>
   <source xmlns:el1="cz.styrax.sodexo.middleware.Falcon" clone="true" xpath="$body//el1:falcon/*" />
   <target type="body" />
</enrich>

Log mediator right after enrich mediator correctlly shows body with element.

To: http://www.w3.org/2005/08/addressing/anonymous, WSAction: , SOAPAction: , MessageID: urn:uuid:d8aec2de-b1d9-457b-a7f3-638086a1791d, Direction: request, Envelope: <?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><result xmlns="cz.styrax.sodexo.middleware.Falcon"><response result="INPUT"><mw caller="FALCON" caller_id="161850" entity="BANKOVNI UCET" operation="ID" partner="SPO" partner_id="146758"/></response></result></soapenv:Body></soapenv:Envelope>

But no matter what I put in enrich xpath, I'm unable to select <response> node, that's why I tried every possible outcome in previous log in a first place.

Either I'm missing something, or there is something wrong with xpath and namespaces.

Affected Product Version:

EI: 6.4.0 OS: Win 10 64bit DB: PostgreSQL 11.2

TomasTokaMrazek commented 5 years ago

Ok so after few hours I finally found, what's wrong.

DSS does not have sqlType XML, so it returns xml as escaped string. Log mediator for some reason doesn't reflect, that it's escaped and shows full XML. Proper log of body should look like this:

<falcon xmlns="cz.styrax.sodexo.middleware.Falcon">
   <result>&lt;response result="INPUT"&gt;&lt;mw caller="FALCON" caller_id="161850" entity="BANKOVNI UCET" operation="ID" partner="SPO" partner_id="146758"/&gt;&lt;/response&gt;</result>
</falcon>

The solution is to first use property mediator and store it as type OM, then use this as source in enrich mediator.

Still tho, both log and enrich mediator with given xpath //el1:falcon/el1:result should select <result> node instead of it's contents.