How to set an error message out in wso2? - wso2

I have a service in wso2.
For example,the endpoint is http://localhost:9000/services/SimpleStockQuoteService, and the request message is:
<m:getQuote xmlns:m="http://services.samples">
<m:request>
<m:symbol></m:symbol>
</m:request>
</m:getQuote>
If the symbol value is null. I do not want to send this request to the endpoint. I can use request message as response or send an error message out. I try to set property RESPONSE=true,but no use. How to do this in wso2? Someone can help me? Best regards.

You can use filter mediator to filterout the messages..Check the sample here[1] If particular filed is empty, then drop the message/execute fault sequence else allow it..
[1]http://wso2.org/project/esb/java/4.0.3/docs/mediators/filter.html

Use makefault mediator in your fault sequence.. Check the following post
http://techfeast-hiranya.blogspot.com/2010/04/wso2-esb-tips-tricks-05-error-handling.html

Related

How to send message to rabbitmq correctly from wso2?

Hi there I am trying to publish a message from WSO2 to rabbitmq but when I call the API it show me this error The system cannot infer the transport information from the -> url to rabbit with the credentials
Anybody knows what I am doing wrong? Thanks in advance.
This is the xml of my api.
enter image description here
Just in case someone have the same error, I found out that the deployment.toml file should be have a property like this sender_enable = true by default it is in the file but is comment all you have to do is uncomment it by removing the # character

How to read request's body in WSO2 ESB?

Hi everyone I am new using WSO2 ESB, here is the issue I made a integration project to learn but I have not been able to read the body of my request when I try I see this warning "Json Payload is empty"
enter image description here
Here is how I am trying to read the body <filter regex="[1-9]" source="json-eval($.test)">
enter image description here
And finally here is my request, I already set the header application/json
enter image description here
If anyone could help me, I would be very grateful. Thanks in advance
The request needs to be a POST to see the payload hit the ESB.
With GET it will just do a GET request without it.
Technically you can do GET with body but it's not a very common scenario.[1]
[1]https://docs.wso2.com/display/EI611/Unusual+Scenarios+for+HTTP+Methods+in+REST#UnusualScenariosforHTTPMethodsinREST-UsingGETwithaBody
That is because the GET method in wso2 does not allow the body payload. You can read in wso2 documentation:
Typically, a GET request does not contain a body, and the ESB profile does not support these types of requests. When it receives a GET request that contains a body, it drops the message body (...)
From doc: Using GET with a Body
Additional it is not good practice to do that, refer to this question: HTTP GET with request body
So you should use POST request.

How can I mediate a multipart message in WSO2 ESB 4.8.1?

I have to mediate a multipart message in a API resource, so that, at first I have to call virus scan service and depending on the response:
If the response is 200 OK continue.
Else, the response is 401 Unauthorized drop message and return 401 response.
I have tired drop message (due to limitations in measuring multipart messages) if I get 401 in mediation, but the original message always go on.
Is there any solutions for that? Is possible mediate message with Java class mediator?
Is there any way to drop parent message by messageID?
If you use a simple <drop/> in your sequence, the message shouldn't be processed further. How does your API/Proxy look like?
You can also process your message inside your custom Java class. See the following link for an example.
https://docs.wso2.com/display/ESB481/Sample+380%3A+Writing+your+own+Custom+Mediation+in+Java

blank Json request body in wso2 esb

I am getting the Blank JSON body in request. due to that ESB is given the below error.
org.apache.axis2.AxisFault: No JSON payload provided.
I am using the wso2 esb 4.9.0 version.
request is POST.
Can you please help in that .
This is a limitation of ESB, you can either send an empty json payload as {} or you can set the Content-Type as application/xml in the request.
According to the HTTP spec "The Content-Type entity-header field indicates the media type of the entity-body sent to the recipient or, in the case of the HEAD method, the media type that would have been sent had the request been a GET"
[1] https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
So if you are defining the media type as "application/json", then there should be a matching entity body for POST. That is why you need to send at-least empty JSON body. If you don't have a body then change the resource to GET rather POST.
But the I found the issue. yes you are right but in Wso2 ESB 4.8.1 if we pass any message with without body as post then we got the error to avoid that we had created the blank payload to call that API. as soon as I removed that blank payload issue resolved. I agreed that post need that body but I had to consume the message of other system that will provide the same (Post with body).
one more thing. if any one put log as full then also you will get the same error.

Forwarding a customized string through class mediator

I am trying to forward a customized string which i have in my class mediator to the client who have invoked the process and i'm unable to figure out how that is done.
So please help me to solve the issue.
you need to set your string to the payload message. Then this can send as the response. Please have a look at here[1]
[1] http://wso2.org/library/knowledge-base/generating-simple-response-using-wso2-enterprise-service-bus
Class mediator can modify the message and append custom data into the message. This sample shows how to add a string to the message using a class mediator.