validate incoming JSON requests in wso2 api manager 2.6.0 - json

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

Related

WSO2 API Gateway convert JSON to 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.

how to validate odoo api in postman?

I want to generate a rest api in odoo so that it can be used in other languages. I have used below api's
http://URL_with_PORT/{}/xmlrpc/2/common
http://URL_with_PORT/{}/xmlrpc/2/object
but when I validated it using postman it is giving me error.
You don't need the curly braces in the URL. Just send it to the xmlrpc/2/common endpoint, as per...
http://<server:?port>/xmlrpc/2/common
You need to set the verb to POST, and the body to raw with XML.
Then send in the following XML in the form as per the documentation.
<?xml version='1.0'?>
<methodCall>
<methodName>version</methodName>
</methodCall>
This will return the server version info as per the examples used in the External API documentation in an XML response.
Postman isn't the best client to use XML-RPC calls, take a look at XML RPC GUI for developers in Windows?. You have to create a raw request and then send it. Using SoapUI would be much easier.

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

HTTP request from XQuery code inside MarkLogic pipe

I want to send text using POST method to another HTTP server and receive a JSON file in response from XQuery code of pipe in MarkLogic. The idea is whenever XML or JSON documents are inserted into MarkLogic, it triggers a pipe to read it and sends one element to another web server; in my situation, I want to send to Rosoka server to do natural language processing, after that I want to store the returned data "it is json file" in MarkLogic.
I appreciate if you could help.
marklogic only mentioned that is possible but no further help
There are many ways to do this.
A start is to look at "Triggers"
https://docs.marklogic.com/guide/app-dev/triggers
There is also Content Processing Framework ( "CPF" which is a higher level workflow based on triggers).
https://docs.marklogic.com/guide/cpf
if you read those guides you should be able to ask more specific questions if needed.