Search code examples
wso2wso2-esbwso2-enterprise-integratorwso2-micro-integrator

Enrich mediator add payload wso2


I used the enrich mediator to add a payload containing the name and totalnote of students my problem that i want to replace the values ​​with the property

here is my code

  <property expression="get-property('uri.var.nom')" name="uri.var.nom" scope="default" type="STRING"/>
  <property expression="get-property('totalnote')" name="totalnote" scope="default" type="STRING"/>
        <enrich>
            <source clone="true" type="inline">
                {"nom":"" ,
                "note":""}
            </source>
            <target action="child" xpath="json-eval($)"/>
        </enrich>
        <enrich>
            <source clone="true" property="uri.var.nom" type="property"/>
            <target action="replace" xpath="json-eval($.etudiants.nom)"/>
        </enrich>
        <enrich>
            <source clone="true" property="totalnote" type="property"/>
            <target action="replace" xpath="json-eval($.etudiants.note)"/>
        </enrich>
        <respond/>

it doesn't work I always receive empty

{ "etudiants": { "nom": "", "note": "" }


Solution

  • You are placing the JSON structure at the root. As a child of $. But your structure does not contain etudiants, therefore the json-eval of $.etudiants.nom won't work.

    The enrich itself works, as shown by @ycr but the message structure you assume to have is incorrect. Try logging the body after the first enrich to see what your payload looks like at that point.

    Depending on your payload before the enrich try something like:

    <enrich>
                <source clone="true" type="inline">
                    {"etudiants": {
                    "nom":"" ,
                    "note":""
                    }
                </source>
                <target action="replace" type="body"/>
            </enrich>
    

    Or if you already have the 'etudiants' object maybe try adjusting the json-eval:

    <enrich>
                <source clone="true" type="inline">
                    {"nom":"" ,
                    "note":""}
                </source>
                <target action="child" xpath="json-eval($.etudiants)"/>
            </enrich>
    

    Hope this helps to clarify the situation.