'ESB WSO2 I want to send a XML Data through Postman and recieve a message based on that XML, based on my MySQL Database using dataservices
So, I want to send a request with a XML data file from Postman to my API and I want the response to be a SELECT statement from my MySQL Database based on that XML file. For example, for the XML file posted below, I want to recieve the response in a json file like so:
JSON File I expect as a response:
{
"utilizator":
{
"id": "3",
"nume": "Mihai",
"varsta(age)": "22"
}
}
XML file from Postman (parenthesis are for translate):
<utilizator(user)>
<nume(name)>Mihai</nume>
</utilizator>
What should I write in payloadFactory mediator in my API:
<resource methods="POST">
<inSequence>
<property expression="//*[local-name()='utilizator']/*[local-name()='nume']/text()" name="nume" scope="default" type="STRING"/>
<log level="custom">
<property name="logNum" expression="$ctx:nume"/>
</log>
<payloadFactory media-type="xml">
<format>
...
</format>
<args>
...
</args>
</payloadFactory>
<call>
<endpoint key="ep.selectUser"/>
</call>
<respond/>
</inSequence>
<outSequence/>
<faultSequence/>
</resource>
This is my dataservice source code:
<config id="default">
<property name="org.wso2.ws.dataservice.driver">com.mysql.jdbc.Driver</property>
<property name="org.wso2.ws.dataservice.protocol">jdbc:mysql://localhost:3306/utilizatori</property>
<property name="org.wso2.ws.dataservice.user">root</property>
<property name="org.wso2.ws.dataservice.password">1234</property>
</config>
<resource method="GET" path="/nume">
<description/>
<call-query href="getName">
<with-param name="nume" query-param="nume"/>
</call-query>
</resource>
<query id="getName" useConfig="default">
<sql>SELECT * FROM utilizatori.test WHERE nume = :nume</sql>
<param type="IN" name="nume" paramType="SCALAR" sqlType="STRING"/>
<result outputType="json">
{
"utilizator":
{
"id": "$id",
"nume": "$nume",
"varsta": "$varsta"
}
}
</result>
</query>
Also my data service from UI:
<body>
<p:_get_nume xmlns:p="http://ws.wso2.org/dataservice/getName">
<!--Exactly 1 occurrence-->
<xs:nume xmlns:xs="http://ws.wso2.org/dataservice/getName">?</xs:nume>
</p:_get_nume>
</body>
Thank you very much!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
