wso2 esb json to json converting double quotes missing - json

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"/>

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

What is the specific type of the JSON being sent to a Webhook?

I can register a so called webhook in JIRA if I want JIRA to inform an external application about changes. Some JSON is generated when an issue is changed and sent to the webhook.
Is this JSON ...just a Stirng...or is it the representation of a specific Java class? If this would be the case: which class is it?
Or: how to I have to handle this JSON when it is sent to my SpringBoot application (webhook)? Just as a String or can I map this JSON via Jackson to a particular class...and how do I have to do this?
A callback for an issue-related event is structured like this...

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.

WSO2 Amazonsns connector issues publishing json message

I am trying to publish a json message using the Amazonsns connector in WSO2 ESB 4.9. I am able to successfully publish a simple string message however when I set the messagestructure to json in order to send different messages to different platforms and attempting to send json as the value of message it will not work. I am using a simple transaction that looks almost exactly like the documentation sample. My Transaction:
content-type: application/json;charset=UTF-8
{
"region":"us-west-2",
"accessKeyId":"MyAccessKey",
"secretAccessKey":"MySecretAccessKey",
"version":"",
"messageStructure":"json",
"subject":"Test",
"message": {"default":"mess","email":"message"},
"targetArn":"arn:aws:sns:us-west-2:977102061874:endpoint/APNS_SANDBOX/mobile_iOS_Sandbox/34ed4324e6-1119-67sd-b7dd-f413c88e4e25",
"topicArn":""
}
My result is an unexpected error sending message out.
Caused by: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,73]Message: Illegal character: <d>
My service is also like the example:
<amazonsns.init>
<region>{$ctx:region}</region>
<accessKeyId>{$ctx:accessKeyId}</accessKeyId>
<secretAccessKey>{$ctx:secretAccessKey}</secretAccessKey>
<version>{$ctx:version}</version>
</amazonsns.init>
<amazonsns.publish>
<message>{$ctx:message}</message>
<subject>{$ctx:subject}</subject>
<messageStructure>{$ctx:messageStructure}</messageStructure>
<topicArn>{$ctx:topicArn}</topicArn>
<targetArn>{$ctx:targetArn}</targetArn>
</amazonsns.publish>
I did not expect much success but just started trying different things....I attempted xml encoding the json message and get the same message on '&'. Using wire logs I found the content type of the successful messages going to Amazon were application/x-www-form-urlencoded so I also tried url encoding and get same message on the '%'.
I'm running out of ideas. I double checked the connector documentation to make sure I did not miss anything. It does say you can use a JSON transaction for Publish and gives a sample transaction however it does not discuss anything special/different that you would need to set up in order to make this work. Is there something I am missing?
UPDATE: Can see it is using the Builder for application/x-www-form-urlencoded which is stumbling on the json. Have tried setting messageType and ContentType properties to application/json. JSON Builder is enabled. It just seems the connector wants to send it out as application/x-www-form-urlencoded, is there something I am not setting properly to tell the connector this is JSON?
UPDATE: The publish template that comes with the connector is setting the messagetype to applicaiton/x-www-form-urlencoded which is overriding any of the settings I am making in my proxy service. Going to look at changing the template in the connector to use a different messagetype and/or allow me to set it in the proxy dynamically then will be trying again.
Joe
We have created a public JIRA for this issue. Please follow that.
You need to enable message builders for the content types you are sending. make sure following is done.
Enable relevent Message builder for each content-type.
< messageBuilder contentType="application/json"
class="org.apache.synapse.commons.json.JsonStreamBuilder"/>
Make sure Content-Type header property is parsing with the message.
Make sure your Json is wellformed.

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