I've created a wso2 data service to retrieve a list of products from a PostgreSQL database:
<data name="ProductListDS" serviceNamespace="" serviceGroup="" transports="http https">
<description />
<config id="ProductListDB">
<property name="driverClassName">org.postgresql.Driver</property>
<property name="url">jdbc:postgresql://localhost:5432/PRODUCTS</property>
<property name="username">postgres</property>
<property name="password">password123</property>
</config>
<operation name="QueryProductList">
<call-query href="QueryProductList" />
</operation>
<resource method="GET" path="/products">
<description />
<call-query href="QueryProductList" />
</resource>
<query id="QueryProductList" useConfig="ProductListDB">
<sql>SELECT service, name, amount
FROM products;</sql>
<result outputType="json">
{
"Products": {
"Product": [
{
"service": "$service",
"name": "$name",
"amount": "$amount"
}
]
}
}
</result>
</query>
</data>
And I'm calling the data service endpoint inside my API to get JSON data using a call mediator.
<call>
<endpoint key="getProductListEndpoint"/>
</call>
<property expression="$body" name="responsePayload" scope="default" type="STRING"/>
<log level="full">
<property expression="get-property('responsePayload')" name="Response Payload"/>
</log>
But in the logs, I get a xml response:
[2023-09-02 10:15:56,147] INFO {LogMediator} - {api:project_list_api:v1.0.0} To: http://www.w3.org/2005/08/addressing/anonymous, WSAction: , SOAPAction: , MessageID: urn:uuid:542d3384-67e2-4831-bb71-c87bbdc270cc, correlation_id: ff3b8304-2e6a-4718-aca7-a88a8e222853, Direction: request, Response Payload = <soapenv:Body xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"/>, Envelope: <?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><Products xmlns="http://ws.wso2.org/dataservice/QueryProductList"><Product><amount>12000</amount><service>Wireless</service><name>1 MONTH</name></Product><Product><amount>24000</amount><service>Wireless</service><name>2 MONTH</name></Product><Product><amount>36000</amount><service>Wireless</service><name>3 MONTH</name></Product><Product><amount>20000</amount><service>Cable</service><name>1 MONTH</name></Product><Product><amount>40000</amount><service>Cable</service><name>2 MONTH</name></Product><Product><amount>60000</amount><service>Cable</service><name>3 MONTH</name></Product></Products></soapenv:Body></soapenv:Envelope>`
Set the
Acceptheader toapplication/jsonbefore the call mediator.Update Also if you don't want to do soap calls remove the following section from your dataservice.
Then make sure you are doing an HTTP GET to your Dataservice.