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
Related
I was trying to use the package pid (http://wiki.ros.org/pid) to control the stability of a drone (Parrot AR drone 2.0).
I created a launch that use one controller for each axis (x,y and z):
<node name="controller" pkg="pid" type="controller" ns="pid_x" output="screen" >
<param name="node_name" value="pid_x" />
<param name="Kp" value="-0.0887" />
<param name="Ki" value="0.0" /> <!-- Arranca en cero pero es 0.16597 -->
<param name="Kd" value="0.0" />
<param name="max_loop_frequency" value="105.0" />
<param name="min_loop_frequency" value="95.0" />
<remap from="setpoint" to="/setpoint_x" />
<remap from="state" to="/ardrone/odometry/pose/pose/position/x" />
<remap from="/pid_x/control_effort" to="/publicador_intermedio_x" />
</node>
<node name="controller" pkg="pid" type="controller" ns="pid_y" output="screen" >
<param name="node_name" value="pid_y" />
<param name="Kp" value="0.0763" />
<param name="Ki" value="0.0" /> <!-- Arranca en cero pero es 0.11037 -->
<param name="Kd" value="0.0" />
<param name="max_loop_frequency" value="105.0" />
<param name="min_loop_frequency" value="95.0" />
<remap from="setpoint" to="/pid_y/setpoint_y" />
<remap from="state" to="/pid_y/state" />
<remap from="/pid_y/control_effort" to="/publicador_intermedio_y" />
</node>
<node name="controller" pkg="pid" type="controller" ns="pid_z" output="screen" >
<param name="node_name" value="pid_z" />
<param name="Kp" value="0.9827" />
<param name="Ki" value="0.0" />
<param name="Kd" value="0.0" />
<param name="max_loop_frequency" value="105.0" />
<param name="min_loop_frequency" value="95.0" />
<remap from="setpoint" to="/setpoint_z" />
<remap from="state" to="/ardrone/odometry/pose/pose/position/z" />
<remap from="/pid_z/control_effort" to="/publicador_intermedio_z" />
</node>
</launch>
I was just checking how it works using just the second controller, so please don't mind the other ones. The state takes information from the topic pid_y/state that reads the /ardrone/odometry/pose/pose/position and publishes the value of y (if u want to see the node I can post it). Then, pid_controller is publishing in /publicador_intermedio_x that it's a node that works like a conection betweeen the outcome of the controller and the topic /cdm_vel of the drone (i mean, the topic where you need to publish in order to controlling the drone). Finally the last one is the big problem: setpoint. In the pid package we can find an example in order to understand how it works. So I copied the node that publishes the setpoint values in order to make a test. It looks like this:
#include <ros/ros.h>
#include <std_msgs/Float64.h>
int main(int argc, char** argv)
{
//inicio comunicacion con sistema ROS
ros::init(argc, argv, "publicador");
ROS_INFO("Starting setpoint publisher");
ros::NodeHandle nh;
while (ros::ok() && ros::Time(0) == ros::Time::now())
{
ROS_INFO("Setpoint_node spinning, waiting for time to become non-zero");
sleep(1);
}
std_msgs::Float64 contador;
contador.data = 1.0;
//creamos un objeto publicador
ros::Publisher pub = nh.advertise<std_msgs::Float64>("/pid_y/setpoint_y", 1000);
ros::Rate loop_rate(10); // acomodar a frecuencia que no sature, pero q sea mas rapida que publicacion odometria
while (ros::ok())
{
ros::spinOnce();
pub.publish(contador);
contador.data = contador.data + 1;
pub.publish(contador);
ROS_INFO("Valor publicado: [%f]", contador);
loop_rate.sleep(); //duermo hasta proxima iteracion
}
Now that I already explained the code, this is what isn’t working: I run the pid with the nodes that it needs. The launch reads correctly the setpoint and the state (the odometry) but it doesn't publish because:
prev_time is 0, doing nothing
If i understood the code correctly, It’s because prev time uses the time between two consecutive values to calculate the error. That's ok. But when the launch must to read the second setpoint value it never does it. It stays in
Waiting first setpoint value
and never read it, even when the node is publishing the new value. I can't understand what I'm doing wrong.
Can anyone help me?
I'm having a few problems in understanding how to pass a query param to a payload factory that creates a json, and then passing its data to a data service.
What I thought would be the correct config is
<payloadFactory media-type="json">
<format>{"cod_uo" : "$1"}</format>
<args>
<arg evaluator="xml" expression="get-property('query.param.id')"/>
</args>
</payloadFactory>
<log>
<property expression="json-eval($.cod_uo)" name="string"/>
</log>
<dataServiceCall description="GET operation" serviceName="MyService">
<operations type="single">
<operation name="MyOperationName">
---> <param evaluator="xml" expression="json-eval('$.cod_uo')" name="cod_uo"/> <-- This Line
</operation>
</operations>
<source type="inline"/>
<target type="body"/>
</dataServiceCall>
but the system doesn't recognize the json-eval function here.
I tried also a direct json evaluation with
<param evaluator="json" name="id" expression="$.cod_uo"/>
but i get a DataServiceCallMediator
Current Request Name: MyOperationName
Current Params: {cod_uo=}
Nested Exception:-
java.lang.NumberFormatException: For input string: ""
What is the correct method to use the 'cod_uo' property of the payload factory payload in a subsequent data service call?
I'm using the latest Integration Studio (8.0.0.202104161647)
The log ALWAYS returns
{api:MyApi:v1.0.0} To: /my/path?id=123, MessageID: urn:uuid:[uuid], correlation_id: [correlation_id], Direction: request, string = 123
All combinations + errors:
<param evaluator="xml" expression="json-eval('$.cod_uo')" name="cod_uo"/>
[2021-07-30 08:50:41,179] ERROR {SynapseXPath} - Evaluation of the XPath expression json-eval('$.cod_uo') resulted in an error org.jaxen.UnresolvableException: No Such Function json-eval
<param evaluator="xml" expression="json-eval($.cod_uo)" name="cod_uo"/>
(doesn't compile: "Invalid XPath expression for attribute expression : json-eval($.cod_uo)"
<param evaluator="json" expression="json-eval('$.cod_uo')" name="cod_uo"/>
<param evaluator="json" expression="json-eval($.cod_uo)" name="cod_uo"/>
<param evaluator="json" expression="$.cod_uo" name="cod_uo"/>
Current Request Name: MyOperationName
Current Params: {cod_uo=}
Nested Exception:-
org.postgresql.util.PSQLException: ERROR: invalid input syntax for integer: ""
<param evaluator="xml" expression="$.cod_uo" name="cod_uo"/>
(doesn't compile: Invalid XPath expression for attribute expression : $.cod_uo)
Since both Payload Factory mediator and the Data Service Call mediator is in the same sequence, you can make use of the get-property() function to retrieve the value and assign it.
For example,
<param evaluator="json" name="id" expression="get-property('query.param.id')"/>
Furthermore, if you wanted to access the property through json-eval(), I think there has been a typo that is causing the empty value behavior. Please remove the quotes around the key and try the scenario
Update Note: The json-eval() approach didn't solve the problem. But, keeping the following segment as a reference. Look at the Update section to access the payload using XPath expression.
<!-- without single quotes around the $.myId -->
<param evaluator="json" name="id" expression="json-eval($.myId)"/>
Update
You can also try accessing the Payload using XPath expression as following
<param evaluator="xml" name="id" expression="$body//myId"/>
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
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.
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.