Mule: forward GET request with query parameters as POST request with json body - mule

My app receive GET requests with URL query parameters. I would like to transfer this request to another app as POST request. I want that the query parameters will appear in the POST request inside the body as json.
Input GET url for example: http://localhost:8081/?name=John&age=30&gender=male
Expected POST json payload: {"name":"John", "age":30, "gender":"male"}
I think that I should use 'Data Mapper' for that, yet I failed to do so.
In the 'input' section I define the source to be - Inbound Property - http.query.params and type Map<String,String>.
In the output section I want the type to be json.
I can't debug/print the result of this mapping so I can't see what is the outcome of my definition. Is this the correct definition?
How do I define the parameters from the URL to be inserted into the map and be transformed into json?

No need to use DataMapper for such a simple transformation. Instead use a MEL expression transformer to create a map out of the query parameters, then add an object-to-json-transformer to serialize this map to JSON.
For example, this creates a map with the 'name' query param in it:
<expression-transformer
expression="#[['name':message.inboundProperties.'http.query.params'.name]]" />
Just add all the params.

Related

How to read a value from a response that comes as an array in Jmeter

I have an api response coming as an array. [{"data1":763,"data2":"jhgf"}] How can i read a single value from this and assign it to a variable in jmeter. This value is required to pass on to the next request.
Which exact value?
You can use JSON Extractor for parsing the response and if you want 763 - use the following JsonPath expression:
$..data1
if you want jhgf - the relevant JsonPath expression will be correspondingly
$..data2
More information: How to Use the JSON Extractor For Testing

How to stop a test after finding specific word in jmeter response?

How can we stop a jmeter test after finding a specific word from json response:
{"code":12345,"data":{"mylist":[{"myid":111,"secId":2,"TypeId":1,"name":"one two three" ,"description":"thats the value"}]}
Put your request under the While Controller
Use the following __jexl3() function as the condition:
${__jexl3("${value}" != "thats the value",)}
Add JSON Extractor as the child of the request and configure it as follows:
Names of created variables: value
JSON Path Expressions: $.data.mylist[0].description
That's it, the While Controller will loop until "description" fields becomes thats the value
Demo:

I want to pass the header value in methods

Scenario : I need to verify the logs response on server on the basis of Tracking-Id.
I had passed the tracking-id using 'header.js' file, here i define metod which get the unique UUID for every request and passed in header.
Now I need that header value to passed in some method to get logs only for specific Tracking-Id
Is there any way to achieve this in karate?
Yes, you can use karate.set('someVarName', uuidValue) in JS and then back in the feature you will be able to: * print someVarName.
EDIT: please see this commit for an example: link

Dojo dStore Rest dGrid sort parameter

When I fetch from a dStore the URL looks something like this
http://localhost/rest/dojo?department=sales
which works fine. If I then click in the header of the dGrid the sent URL looks like this.
http://localhost/rest/dojo?department=sales&sort(+id)&limit(25)
Shouldn't it send &sort=+id&limit=25? I am using Java and Spring for the backend and it expects the parameters to be formatted this way. Right now I can not receive the extra parameters. Is there a way to get it to send the parameters the way Spring is expecting them?
sort(...) and limit(...) are the default behaviors of dstore/Request (which Rest extends), but these can be customized via sortParam for sort, and useRangeHeaders or rangeStartParam and rangeCountParam for range.
For example, to result in &sort=+id&limit=25 as you requested, you could set up your store as follows:
var store = new Rest({
target: '...',
sortParam: 'sort',
rangeStartParam: 'offset',
rangeCountParam: 'limit'
});
I've additionally assumed above that offset is the GET parameter you'd want to use to indicate what record to start at when requesting ranges. Generally if you're not using range headers (useRangeHeaders defaults to false) and you want to set a count GET parameter, you'll also need to set a start GET parameter.
These properties are listed in the Request Store documentation.

Ushahidi GET request with multiple parameters

I'm working on an application that uses Ushahidi to return an array of JSON objects using a HTTP GET request. I would like to use two parameters in the request. These parameters are category id and max id. In the URL below the first parameter is &by=catid&id=2 and the second is &by=maxid&id=499. The example below will only read the last parameter entered. So the catid parameter would be ignored.
http://fixyourstreet.ie/api?task=incidents&by=catid&id=2&by=maxid&id=499
Why will this request only return JSON objects by the last parameter entered rather than both parameters?
Any help would be much appreciated.
Those requests typically get parsed as key-value dictionaries by web servers.
This means the "by" parameter can only have one value when your request is processed and responded to. You will have to make 2 subsequent requests if you need all these values :
http://fixyourstreet.ie/api?task=incidents&by=catid&id=2
http://fixyourstreet.ie/api?task=incidents&by=maxid&id=499