WSO2 API Gateway convert JSON to JSON - json

I need to configure JSON to JSON transformations with API Manager 2.0 very efficiently.
By default, WSO2 API Manager makes transformations JSON-> XML-> and after processing -> XML->JSON
I'd like to know how can I do so directly in JSON to reduce latencies.
Thank you for your help!!

By default, APIM uses PassThrough transport which does not build your message unless it needs to access your message body. So, your json won't be converted to XML in that case.
For example, if you have configured custom mediation and have a content-aware mediator like <log level="full"/>, APIM has to build (i.e. convert to XML) your message body so that it can log the entire message.
If you don't try to access the message body like that, json will be sent to backend as it is.

Related

validate incoming JSON requests in wso2 api manager 2.6.0

I need to validate incoming json requests structure in wso2. I will be able to validate incoming json using default json validator in mediation sequence, but I want to apply json validation only for POST request and not for GET request in an API. It can be achieved by adding custom in flow sequence.
I'm having json validator file for schema validation(like jsonvaldiator.json).
Where should I keep this file in wso2 api manager 2.6.0 and how to mention the validator file path in filter added in the custom in flow sequence?
Any comments would be appreciated.
Yes, you need to add a custom In sequence to the default message mediation flow in order to achieve this. Please have a look at this blog post about validating JSON request payload. This might help to do this for APIM-2.6. Because the blog has been written for an older version but you can get the idea. :)
More about WSO2 Gateway Extensions. https://dinushasblog.blogspot.com/2018/04/wso2-api-manager-gateway-extension.html

How to consume REST Endpoint with wso2 api manager?

I can consume SOAP APIs in my company with wso2 api manager. However when I want to consume REST endpoints I am unable to do so. I keep getting no response.
My endpoints are like such:
GET: http://{server}:{port}/api/broker/{brokerId}
POST: http://{server}:{port}/api/addresscleanse with json payload.
I am not seeing any configuration for the backend point where we can specify that the backend service is expecting json payload or queryparameter. I tried to scan the tutorial section and did not find any thing similar to my need.
Any help would be appreciated.
You can define your resources like below. To specify the message body type of the POST request, you can send Content-Type header.

wso2 esb json to json converting double quotes missing

I have a problem in converting json to json in wso2 esb, actually I'm using payload factory in a proxy and I call the proxy with rest and json content. Here is my integration flow, I call a proxy and the proxy sends the request(with json content) to a jms message store then, I defined a message processor to consume messages from message store and send them to a defined endpoint(.net web api). but the problem is strings with numbers automatically get converted as integer elements: "orderId": 10000 ( I want it to be string "orderId": "10000") , but when I send the request directly from proxy to my end point (without using message broker) it works correctly. Could you please help me solve this problem?
For more details refer to my question with more details on this problem, and looks like this is a bug in wso2 esb 4.9.0
wso2 jira
For your problem need to change a JSON Message Formatters.
please follow the below steps for that.
change your working directory to [ESB Home]/repository/conf/axis2/axis2.xml
then you need to change JSON Message Formatters instead of JsonStreamFormatter use org.apache.axis2.json.JSONMessageFormatter.
<!--messageFormatter contentType="application/json" class="org.apache.synapse.commons.json.JsonStreamFormatter"/-->
<messageFormatter contentType="application/json"
class="org.apache.axis2.json.JSONStreamFormatter"/>
You can use the following builder and formatter in axis2.xml
org.apache.synapse.commons.json.JsonStreamBuilder
org.apache.synapse.commons.json.JsonStreamFormatter
Remove existing builder and formatter for the "application/json" and add the below.
Add under Formaters section
<messageFormatter contentType="application/json"
class="org.apache.synapse.commons.json.JsonStreamFormatter"/>
Add under Builders section
<messageBuilder contentType="application/json"
class="org.apache.synapse.commons.json.JsonStreamBuilder"/>

Call rest service that returns JSON in mule esb?

How to call a rest service that returns JSON in a APIKit based message flow. I want to prepare the request for Rest service and want to extract the JSON message in a message flow.
Can any one help me to do this?
Thanks
The recommended way to invoke/consume REST services in mule is the use of HTTP Request
Do let us know if there is a specific you are facing
The request connector is especially handy when consuming a RESTful API
that is described in a RAML file. If you reference the API's RAML file
in the connector's configuration, it will proactively offer you the
set of available resources and operations contained in the RAML file,
as well as enforce the policies described in the file. It will also
expose the API metadata to Studio, which can then be used by other
elements such as DataWeave to autocomplete fields and make
configuration much easier
Use Rest URI path to invoke the Service and you can also get json response as output based on the type of service you invoke

Binary relay in wso2 api manager

We are using wso2 api manager to manage our REST apis. The default configuration in the api manager comes with org.wso2.carbon.relay.BinaryRelayBuilder for application/json content-type. I expect the whole data treated as binary and added to a payload node in the soap body. But when we try to send a request to the api manager, the whole request is converted into xml and wrapped by SOAP envelope. This was confirmed by logging the request inside the in-sequence of the proxy created by the api manager for this api, we could see the whole json request converted into xml.
Why does the API Gateway convert from json to xml when relay is used? Is there any configuration that we have to do to disable this xml processing in api manager?
Note: One of our APIs is a high throughput API. This json to xml conversion and then xml to json conversion will add extra load to our processing.
In which version of APIManager you see above issue? If you enabled the Binaryrelay message builders, you will only see the binary message content, when you use log mediator inside any sequence.
Did you set the content type of your request properly, when you do POSTing?
Please check the relay module conf is added in your axis2 configuration (axis2.xml)
<module ref="relay"/>
I have found the solution for this. The binary relay happens in the API Manager only if we disable the relay module conf in axis2.xml.
<!--module ref="relay"/-->
By default it is enabled in version 1.3.0 and disabled in 1.3.1. But to make relay work for application/json content-type we have to disable this in addition to using the message builder/formatter of Binary relay. Not sure if this impacts anything else. This may be a bug in the API Manager.