I'm using WSO2 Enterprise Integrator 6.5.0 's DataService,
I want to input nested parameters,
i did not find any tutorials about that,
it is my input :
{
"getBankCodes": {
"SOURCE" : "12",
"FUNCTION": "james",
"REQUESTER" : "bond",
"SECURITYCODE" : "bond#gmail.com"
}
}
Desired input is :
{
"source" : "123",
"userId" : "test",
"Request": {
"SOURCE" : "12",
"FUNCTION": "james",
"REQUESTER" : "bond",
"SECURITYCODE" : "bond#gmail.com"
}
}
Source code :
<query id="getBankCodes" useConfig="Datasource">
<sql>Select BankCode, BankName From XAC_BANKCODES Where Substr(BankCode, Length(BankCode) - 3) = '0000'</sql>
<result outputType="json">
{ "Response":
{"Banks":[
{
"Details": {
"BankCode":"$BankCode",
"BankName":"$BankName"
}
}
]
}
}</result>
<param name="SOURCE" ordinal="1" sqlType="STRING"/>
<param name="FUNCTION" ordinal="1" sqlType="STRING"/>
<param name="REQUESTER" ordinal="1" sqlType="STRING"/>
<param name="SECURITYCODE" ordinal="1" sqlType="STRING"/>
</query>
<operation name="getBankCode">
<call-query href="getBankCodes">
<with-param name="SOURCE" query-param="SOURCE"/>
<with-param name="FUNCTION" query-param="FUNCTION"/>
<with-param name="REQUESTER" query-param="REQUESTER"/>
<with-param name="SECURITYCODE" query-param="SECURITYCODE"/>
</call-query>
</operation>
<resource method="POST" path="/getBankCodes">
<call-query href="getBankCodes">
<with-param name="SOURCE" query-param="SOURCE"/>
<with-param name="FUNCTION" query-param="FUNCTION"/>
<with-param name="REQUESTER" query-param="REQUESTER"/>
<with-param name="SECURITYCODE" query-param="SECURITYCODE"/>
</call-query>
</resource>
Please refer below questions
How to send grouped complex nested input parameters
How to get input parameters as response(return What i sent as input) on this situation.
Regards,
Thanks
How to send grouped complex nested input parameters
Extracting the corresponding parameter is a mediation logic. Therefore, you have to write a proxy service/API in EI to extract inner param set from the request and call the dataservice.
How to get input parameters as response(return What i sent as input) on this situation.
You can do the same when you are writing a mediation logic.
Related
I created a API in WSO2 integrator studio contain the below body to receive the application requests.
{"count": "2000",
"Name": "22312312"
},
For responding to above request, I have to send the following JSON body toward the endpoint:
{"count": "2000",
"Name": "BANK"
},
As you can see, the difference between to bodies is about "NAME" value. In this scenario, each client send its own unique number in "Name" parameter, and I have to translate it into a String Name (in WSO2 Enterprise integrator) and send it to the endpoint.
How can I manage this in Integrator studio?
Here is how you can do it. You can have the mappings in a LocalEntry and then use a combination of Property mediators and Enrich mediator to select the Name and replace the Code. Check the following.
Local Entry
<?xml version="1.0" encoding="UTF-8"?>
<localEntry key="Mappings" xmlns="http://ws.apache.org/ns/synapse">
<Mappings xmlns="">
<bank>
<code>22312312</code>
<name>bank</name>
</bank>
<bank>
<code>22312313</code>
<name>bank2</name>
</bank>
<bank>
<code>22312314</code>
<name>bank3</name>
</bank>
</Mappings>
</localEntry>
API
<?xml version="1.0" encoding="UTF-8"?>
<api context="/bank" name="BankAPI" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="POST" url-mapping="/code">
<inSequence>
<property expression="get-property('Mappings')" name="localEntry" scope="default" type="OM"/>
<property expression="json-eval($.Name)" name="BankCode" scope="default"/>
<property expression="$ctx:localEntry//bank[code = $ctx:BankCode]/name/text()" name="BankName"/>
<enrich>
<source type="property" clone="true" property="BankName"/>
<target xpath="json-eval($.Name)"/>
</enrich>
<respond/>
</inSequence>
<outSequence/>
<faultSequence/>
</resource>
</api>
Request and Response
{
"count": "2000",
"Name": "22312313"
}
{
"count": "2000",
"Name": "bank2"
}
If your mapping is dynamic, for example, if you need to pass the code to another API and get the Name, you can still use the same logic above with the Enrich mediator. Instead of reading from the LocalEntry you can get the data from the API.
I'm trying to use Call Template Mediator in WSO2 and I'm trying to get a dynamic value inside function, but I don't find the way to get it.
For example:
<property expression="$ctx:variable" name="test" type="STRING"/>
<call-template target="HelloWorld_Logger">
<with-param name="message" value="VARIABLE: " expression="$ctx:test" />
</call-template>
I'm not able to get the property "test", if i remove value field the IDE reports an error.
There is some way to get a property inside <call-template> function?
The Call Template Mediator doesn't have a parameter called expression to pass dynamic values. You must pass the XPath expression within {} to the value parameter itself. In your case, the call-template will be as follows,
<call-template target="HelloWorld_Logger">
<with-param name="message" value="{$ctx:test}"/>
</call-template>
Please refer to the Call Template Mediator for more information.
How to pass multiple parameters into WSO2 MI dataService, nested queries
I search far and wide,
Here how its done:
</query>
<query id="getCampaigns" useConfig="MySQLConnection">
<sql>SELECT NULL</sql>
<param name="param1" sqlType="STRING" />
<param name="param2" sqlType="QUERY_STRING" />
<param name="param3" sqlType="QUERY_STRING" />
<result outputType="json">{
"Campaigns": {
"CampaignsByBanks": {
"SearchedCampaigns": {
"#getCampaignBbank": "$param1->param1, $param2->param2, $param3->param3",
"#getCampaignAbank": "$param1->param1, $param2->param2, $param3->param3"
},
"OtherCampaigns": {
"#getOtherCampaignBbank": "$param1->param1, $param2->param2, $param3->param3",
"#getOtherCampaignAbank": "$param1->param1, $param2->param2, $param3->param3"
}
}
}
}
</result>
</query>
how to pass single parameter into WSO2 MI dataService, nested query
https://docs.wso2.com/display/EI630/Defining+Nested+Queries
I have problem with I think format when I get temperature value. When I call for this parameter I always got it with "d0" f.e. "-0,39d0". How can I fix it? My code:
<category>
<pattern>PADANIE</pattern>
<template>
<think>
<set name="weather_t">
<callapi>
<url>http://api.openweathermap.org/data/2.5/weather</url>
<method>GET</method>
<query name="appid"><secret name="openweathermap_secret_appid"/></query>
<query name="q">zyrardow</query>
<query name="units">metric</query>
<query name="lang">pl</query>
<filter type="jsonpath">$.main.temp</filter>
</callapi>
</set>
</think>
<get name="weather_t"/>.
</template>
</category>
If I use jsonpath instead filter the result is the same.
<category>
<pattern>PADANIE</pattern>
<template>
<think>
<set var="weather_t">
<callapi>
<url>http://api.openweathermap.org/data/2.5/weather</url>
<method>GET</method>
<query name="appid"><secret name="openweathermap_secret_appid"/></query>
<query name="q">zyrardow</query>
<query name="units">metric</query>
<query name="lang">pl</query>
</callapi>
</set>
</think>
<jsonpath><path>$.main.temp</path><get var="weather_t"/></jsonpath>
</template>
</category>
bot answer example
This is how the openweathermap API presents the results. The easiest way to get rid of the d0 part is to denormalize the output.
Add this to your denormal substitution file:
["0d0", "0"],
["1d0", "1"],
["2d0", "2"],
["3d0", "3"],
["4d0", "4"],
["5d0", "5"],
["6d0", "6"],
["7d0", "7"],
["8d0", "8"],
["9d0", "9"],
In your first category, replace:
<get name="weather_t"/>
with
<denormalize><get name="weather_t"/></denormalize>
It should now work
This is regarding xml transformation within BPEL.
In my bpel process, data is coming from two separate sources (partnerLinks).
Data from both sources is in the same xml format.
I need to combine the data from the two XML documents into one xml document and then pass it back to the ESB.
I was trying with bpel:doXslTransform()).
I am not sure how to pass the two responses from the partnerLinks to this function in a single call.
I tried concatenating the two responses into a string within a message type variable and then pass this to the bpel:doXslTransform(). Is this the right approach to merge the data?
Yes, you can do a bpel:doXslTransform here.
This involves receiving an XML document from one service, converting it to a different Schema to form a new request message, and sending the new request to another service. Such documentation conversion can be accomplished using XSLT via the bpel:doXslTransform function.
<variables>
<variable name="A" element="foo:AElement" />
<variable name="B" element="bar:BElement" />
</variables>
...
<sequence>
<invoke ... inputVariable="..." outputVariable="A" />
<assign>
<copy>
<from>
bpel:doXslTransform("urn:stylesheets:A2B.xsl", $A)
</from>
<to variable="B" />
</copy>
</assign>
<invoke ... inputVariable="B" ... />
</sequence>
Please refer http://docs.oasis-open.org/wsbpel/2.0/OS/wsbpel-v2.0-OS.html for further information.