I have a http service exposed in WSO2. The service address is "http://172.30.60.73:8888/XMPPService/recieveMsg?param=yes", and the response is "notifyresult=000000".But
in WSO2, The log output is : <?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"><soapenv:Body><axis2ns7:binary xmlns:axis2ns7="http://ws.apache.org/commons/ns/payload">bm90aWZ5cmVzdWx0PTAwMDAwMDENCg==</axis2ns7:binary></soapenv:Body></soapenv:Envelope>
I use script mediator:
var symbol=mc.getPayloadXML().toString();
var response=symbol.substring(13,symbol.length)
mc.setPayloadXML(<p:createGroupResponse xmlns:p="http://iag.sdp.coship.com/xmpp/"><notifyresult>{ response }</notifyresult></p:createGroupResponse>);
And the client side is:
<p:createGroupResponse xmlns:p="http://iag.sdp.coship.com/xmpp/">
<notifyresult>Wx0PTAwMDAwMDENCg==</notifyresult>
</p:createGroupResponse>
Seems the response is binary. How to convert this response to "notifyresult=000000". Anyone can help me? Thank you very much.
By default ESB uses the passthrough transport in version 4.6.0.In passthrough we dont build the message..Can you switch to NIO transport and check? Edit the axis2.xml , transport listener, sender fro NIO transport
Related
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"/>
I'm using Twilio with my app and I have sms webhooks with my SMS numbers configured with URL.
Everything is working except that Twilio send me an error in logs for each requests.
I suppose that the response from my app is not well formated but I can't find on documentation how to format using JSON.
Can someone help me ? :)
Thanks,
Gabriel
Twilio developer evangelist here.
When you return a webhook message to Twilio, you need to make sure it's valid TwiML, which in essence is just a set of XML verbs Twilio uses.
If you're responding to an SMS message for example, you would return TwiML as follows:
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Message>Thanks for getting in touch, I'll call you later</Message>
</Response>
You can test the code above by changing the configuration of your number to point to this url and you should stop seeing the errors.
If you generating the TwiML yourself, you need to make sure that the page's MIME type is text/xml.
Hope this helps you out.
I have successfully created my app and now want to connect it to a localhost to check the working of my app. I have been suggested to use restsharp for connecting to the server using php and json to receive data from server.
I have looked at codes for both but do not completely understand how the process works. I have looked into all forums but found could snippets with no explanation as how it works. I have even tried restsharp.org and google search results. Please explain me as to how this works.
RestSharp is a library that helps you invoking REST web services.
You use RestSharp on your client to invoke Rest style Web Services (send and receive data)
Here is an example on the usage of your service:
var client = new RestClient(baseUrl);
var request = new RestRequest("/*rest_resource*/", Method.POST);
// see Rest services
// set the request format - HTTP Content-Type text/xml
request.RequestFormat = DataFormat.Xml;
// add data to the request
request.AddBody("<books><book>RestSharp Book</book></books>");
/* send the request and if your service returns text put the as expected return type; otherwise you will get raw byte array*/
IRestResponse response = client.Execute(request);
//HTTP status code 200-success
Assert.IsTrue(response.StatusCode == HttpStatusCode.OK);
Assert.IsTrue(!string.IsNullOrEmpty(response.Data)); // the response is not empty
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.
I'm very very new to this and need some help writing an ESB script to take an event posted via HTTPS on Port 9090 in WSO2 and transform it into a message to be apended to an XML file on the server:
The HTTPS data will contain : “ID=Servername|Severity=sevtype” (Where Servername is a device name and Sevtype can either be "WARNING" or "OK" depending on whether the server is down or up)
This then needs to be transformed and appended to an existing XML file in the following format:
<event>
<componentID>Servername</componentID>
<timestamp>2012-04-27 01:37:10</timestamp> ***(Date and time the event was received)***
<severity>NORMAL</severity> ***(If original is WARNING then severity = SEVERE else it = NORMAL)***
<eti>NodeStatus</eti><etivalue>Up</etivalue> ***(If original is WARNING then severity = Down else it = Up)***
<\event>
Please could someone assist me i'm really floundering with what seems to be a simple thing
Many Many Thanks
Simon
You can write a simple task to poll your data into the server and can do a xslt transformation to construct that particular xml format message.
Some references to write a task;
http://wso2.org/project/esb/java/4.0.3/docs/configuration_language.html#TaskConcept
http://docs.wso2.org/wiki/display/ESB403/Writing+Tasks
http://wso2.org/library/2900
How do you get the ID and Severity? are they http headers?
Generally you can use payload factory mediator[1] to build the payload messages with some input parameter data.
[1] http://wso2.org/project/esb/java/4.0.3/docs/samples/message_mediation_samples.html#Sample17