Search code examples
wso2wso2-micro-integrator

How do i send json payload to endpoint and fill in header variable "key" in wso2 MI?


In WSO2 MI i have sequence that every 5 minutes reads from DB and logs what it got , i need send these data (in JSON format) and fill in header with "key" (some text and numbers) to endpoint. After successful sending (POST) i need to update what i sent so it will not be sent again (updating column sent from null to 1)

i use integration studio for this project

i am unsure how call mediator works (i am junior in wso2 mi), i am pretty sure that call is the way how to achieve it but in almost every example i saw there was no sending payload just calling GET and working with response


Solution

  • You can use the PayloadFactory Mediator to create the payload. Then use the property mediator or the Header Mediator to set a Transport Header. Finally, use a Call Mediator to send to message to the Endpoint. After the call mediator, you can check the response and do whatever you need.

    
    <property name="Authorization" expression="$ctx:something" scope="transport" />
    

    OR

    <header name="Accept" value="image/jpeg" scope="transport"/>
    

    PL Factory

    <payloadFactory media-type="json">
        <format>{"newValue" : "$1"}</format>
        <args>
           <arg evaluator="xml" expression="$ctx:someProperty">
        </args>
     </payloadFactory>
    

    Call Mediator

    <call>
        <endpoint>
           <http method="post" uri-template="http://localhost:8080/MockService1"/>
        </endpoint>
    </call>