Developing a simple message using WSO2 Payload Factory Mediator

Isuru Uyanage
Think Integration
Published in
2 min readApr 6, 2020

We can build messages via sending parameters in the URL or as a payload as a POST request. In both ways, we can build a customized message using Payload Factory.

Prerequisites

  • Start the SimpleStockQuote Service since we use this as our backend.

Starting SimpleStockQuote Service

  1. Download WSO2 EI 6.6.0 Distribution from here.
  2. Go to <PRODUCT-HOME>/samples/axis2Server and run the following command to start the axis2Server.
./axis2Server.sh

3. Go to <PRODUCT-HOME>/samples/axis2Server/src/SimpleStockQuoteService folder and build it using the following command.

ant

Sending as the Payload as a POST request

Let’s move to our first scenario.

Below will be the payload that the user needs to send.

{
"companyName":"WSO2"
}

Below is the API. You can build the API using the WSO2 Integration Studio.

Here, we are reading the companyName from the payload and get it saved to a property called companyName. In the Payload Factory, we define our first argument as companyName, and it is used in the inline format as $1.

Then the message will be sent to the SimpleStockQuote endpoint.

Calling this using the Postman

URL: http://localhost:8280/sqs/send 
Resorce Type: POST
Payload:
{
"companyName":"WSO2"
}

Sending it in URL Path

In the second scenario as a GET request we can send this value simply in the URL as below.

http://localhost:8280/sqs/send/WSO2

The API will be as below.

In both scenarios, you should get the following response.

--

--