How to get All element url in wso2ESB - web-services

I am working on wso2ESB version 4.9.
I have these URL:
http//192.168.0.1/getinfo/id=10&name=alice&from=AU$code=ddddd
http//192.168.0.1/adduser/id=11&name=bob&from=USA&tel=25644&city=newyork$code=ddddd
So i want get all of element of URL and separate code and call web-service without code variable . My URL element is changing but always has code variable.
Thanks

You can read query param string inside a script mediator (javascript). You can read it like this and manipulate as per your need. Then you can append it to the outgoing request.
mc.getProperty('QUERY_PARAMS')

Related

Postman path parameter following = in the request url

One of the requests for the tool I've been asked to update is the delete request which is structured as follows:
http://{{host_ip}}:{{port}}/lists/list_id=76218cb5fc45605cd632c26f5c5568ac/del
where the list ID will be different every time you send a request.
In order to simplify usage for end users, I want to be able to have them enter everything they need as parameters or headers in the postman GUI as they do for the other requests, rather than modifying the request URL, so I tried something like this:
http://{{host_ip}}:{{port}}/lists/list_id=:list_id/del
but if the : is preceded by an equals sign, the postman parameters tab no longer shows list_id as a path parameter.
Is there a way to make this work using a path parameter? Or is the best solution to explain to users that for the delete request, they need to paste the list_id obtained from the other requests into the request URL?
http://{{host_ip}}:{{port}}/lists/list_id={{list_id}}/del?list_id=1
Now users can pass the list id as query parameter.
In pre-request:
pm.environment.set("list_id",pm.request.url.getQueryString("list_id").split("=")[1])
pm.request.removeQueryParams("list_id")
this will update the list_id varaible and remove the query parameter and send the request in the format you want
If you want to achieve what you are saying then there is no solution for your problem.
But I would suggest you change your URL. As Divyang said, your URL should be like http://{{host_ip}}:{{port}}/lists/{{list_id}}/del or http://{{host_ip}}:{{port}}/lists/del?list_id=123 and then you can use params tab assign values to list_id.
But my best suggestion would be to use RESTful design: http://{{host_ip}}:{{port}}/lists/123123 and make a DELETE request to that URL.

How to make a request in Postman

Arabam is an e-commerce site that I am attempting to query. As an example, given the automobile page, you can add query parameters to the page such as days and sort as follows:
https://www.arabam.com/ikinci-el/otomobil?days=30&sort=startedAt.desc
I will be accessing the data via their API, however, which lives at:
https://api.arabam.com/listing/v2/search
And here is the API Key I'm using:
_V85Kref7xGZHc1XRpUmOhDDd07zhZTOvUSIbJe_sSNHSDV79EjODA==
I am able to make the request using Postman:
But whichever query parameters I pass, the total number of keys in the response remains the same. How do I pass parameters correctly? Either I am not passing them correctly, or these are not the correct parameters. How do I find correct parameters?
I'm relatively new to this so need a bit of guidance.
Have you tried posting the params as a json body instead

MD5 of javascript content in WSO2 ESB API

I have to deal with javascript content in API resource in WSO2 ESB. Specifically, I want to get the md5 hash from message which it is a javascript.
When I use messageType = application/javascript I get a binary, no JS message.
Can I do this? If I use binary to get md5, Will it work?
Finally, I solved this question as given below:
At first, I changed in axis2.xml the messageBuldir and messageFormater property to "text/javascript" pointing to "org.apache.axis2.format.PlainTextBuilder" and "org.apache.axis2.format.PlainTextFormatter".
At second I got the message in API with next expression: "s11:Body/child::[fn:position()=1] | s12:Body/child::[fn:position()=1]". With that, I can save the js message in a property.
Finally, I wrote a class mediator to calculate MD5 of property with JS.

how to get the value of special character like #,?,;

I am using Advanced Rest Client plugin in Google Chrome.
URL: http://localhost:6721/bgs/ujh/data# or data? or data;
method: GET
When I pass this data in my controller I am getting data only instead of data# or data? or data;.
You should urlencode the data. # for example would become %23
http://localhost:6721/bgs/ujh/data%23
The # character indicates a fragment. It is not sent as part of a HTTP request. It is only used within the browser to navigate to a part of a page. That's why you are only seeing data; the fragment component of the URL is being stripped.

How to send Queryparam with JSON value using Jersey client in unit test

I am trying to write a test case for a jersey resource using InMemory container provided by Jersey.
As my service method contains many multivalued parameters as filters, I opted to send all of those values as single JSON parameter, so that it will be easy to send a list of values for each filter.
When i send the JSON string using target("path").queryParam("filters", jsonString).request().get(); the call fails die to Jersey clients internal query builder, which is parsing the url and checking for path param templates in the url. Since the url contains my JSON with "{" in it, they are interpreted as path param.
If I try to encode the JSON using URLEncode.encode(jsonStr, "UTF-8"), the path param template issue is solved but white spaces in JSON are received by server as "+" as jersey client encoding URL one more time, but server decoding it only once.
If I make the Queryparam as post param test is working, but i don't want to use POST for just to retrieve data.
I can't post original code due to company policies.
My question is, is there any way to disable path template check in jersey clieny by setting custom builder.
A simpler solution would be to replace the '+' by '%20' as suggested here and here:
URLEncode.encode(jsonStr, "UTF-8").replaceAll("\\+", "%20");