I am trying to create a system variable in ws02 api manager.
The variable contains a special character such as / but the when being read in by the global mediator the / gets converted to a %2F
Any assistance on how I could use special characters in my variable would be greatly appreciated.
wso2 apim v 1.10
Try with URL decoding with script mediator.
<script language="js" description="Query Parameter Decoding Script">
mc.setProperty("DECODED_PARAM", encodeURIComponent(mc.getProperty('ENCODED_PARAM')));
</scrpt>
Reference: http://movingaheadblog.blogspot.com/2015/09/wso2-esb-how-to-url-encode-in-wso2-esb.html
Related
I am creating a postman collection for one of API integration with our Service. Here we are using OAuth1.0 for authentication. I want to set the oauth init response oauth_token, oauth_token_secret into postman environment variables so that I can access them in further requests.
The response is in below format not a JSON.
oauth_token=oauth_token_value&oauth_token_secret=oauth_token_secret_value&oauth_callback_confirmed=true
I tried below script:
var output = require('querystring').parse(Response.text);
postman.setGlobalVariable("oauth_token", output.oauth_token);
postman.setGlobalVariable("oauth_token_secret", output.oauth_token_secret);
Can some one help me to set tokens into postman environment variables please.
Note: I am using chrome plugin Version 5.5.4, not native app.
In the chrome extension you need to use postman.setEnvironmentVariable():
postman.setEnvironmentVariable("oauth_token", output.oauth_token);
postman.setEnvironmentVariable("oauth_token_secret", output.oauth_token_secret);
For that you need to have an environment created and selected (no need to add any variable manually). How to do that is described here: https://learning.postman.com/docs/sending-requests/managing-environments/#creating-environments
I have a use case where create new set of query parameters(Say 4 new query parms) based on a query parameter come from request and send all query parameters(both newly created and old) into target server. How to achieve ? I have created a logic to split that query param come from request using Script Mediator and set into query param function like mc.setProperty("query.param.IndA", IndA);
<script function="restGET"
key="conf:repository/resources/scripts/rest.js" language="js"/>
<header name="To" scope="default" value="http://localhost:8443/res/c/r/cust/0.0.1/e"/>
But this doesn't set in request and reached to end server. Is that anyway better way than this approach ?
You can use REST_URL_POSTFIX property to append values to the target endpoint. Please refer the example which uses that property.
Answer given by #pubci is correct. Here I am adding some additional info on reading query parameter from request- To read the query parameter from the request no need to have script mediator , you can just use synapse xpath variable $url [1]. You can find a sample here[2]
[1] https://docs.wso2.com/display/ESB481/Synapse+XPath+Variables#SynapseXPathVariables-$trp
[2] https://jenananthan.wordpress.com/2015/09/22/how-to-read-dynamic-query-parameter-in-esbapim-synapse/
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.
I have some external URL (restful api) to be integrated.
Those URL have different prefixed URL with different parameter at url, for example:
www.abc.com/books
www.abc.com/book/11
www.abc.com/book/11/authors
When get response from those invocation, esb needs to convert response from one json format to our standard json format.
I plan to use esb javascript mediator to perform convert operation, but I didn't find any way to attach url parameters.
Any one have any idea?
I have used mediator by java code to implement it, but it is too heavy.
I am also looking into connector for another option.
I have got a solution by use url template. By this solution, I can change url according to template defined.
With this solution, I didn't need to write mediator or connector.
I am looking to change the structure of the URL generated by the WSO2 API Manager for a defined service by switching the position of the version number. For example, the default for a service is
http://localhost:8020/some_service/1.0.0
however, I would prefer to have it as
http://localhost:8020/1.0.0/some_service/
My 2cts; you could put Apache with mod-proxy and mod-rewrite module or HAProxy in front of WSO2 AM and user rewrite rules on the URL's.
That URL format is fixed one and generally that is the URL format is followed. If you like to change the format, there is no way, but you can define the version with context and make a preferred url pattern. But again version must be filled.