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.
Related
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.
I am getting familiar with both Postman and SoapUI. I already have a doubt. When I make a GET call with from the postman-echo service, I get slightly different responses shown to me in Postman and in SoapUI.
In particular, in Postman I get
"postman-token": "1ef2b330-3a46-4681-a304-d72f020cb194"
This field-value pair is not shown by SoapUI.
Can anyone explain me the apparent difference?
The parameter postman-token being added while you send a request from Postman. So, it's a custom parameter, you cannot expect it to be present with other tools.
If you check Postman doc of General settings They have explained what is that param is for:
This is primarily used to bypass a bug in Chrome. If an XmlHttpRequest
is pending and another request is sent with the same parameters then
Chrome returns the same response for both of them. Sending a random
token avoids this issue. This can also help you distinguish between
request on the server side.
You can disable it from Postman settings. Goto Settings > General > Send Postman Token header.
I am trying to get payload size from both request and response for every kind of content type with custom handler in WSO2 APIM1.10.0
By reference this code, I can get the payload size with 2 ways:
Get header content length (at line 127)
Build message and get the body length (at line 132)
But I think both of these two way might have some problem.
User might give incorrect content length when invoking the API.
The API content type might be unpredictable.
So, how can I get payload size from both request and response?
You can do this by using a script mediator.
The length of the payload of the message can be received by calling mc.getPayloadXML() inside script mediator in both in-sequence and out-sequence.
Please refer this blog for more information and the documentation on usage of mediation extentions in API Manager.
I have published API in WSO2 using swagger JSON. After publish I am trying to call rest api using swagger in APP Console. It says
Response Body no content
Response Code 0
Response Headers {
"error": "no response from server"
}
There is no any error on server which will help me to understand problem.
Here is the request URL which I am using in local server : https://192.168.1.118:8243/api/2.0/questions/1/answers?start=1&end=1&fields=answerId%2CanswerDescription%2CcreateDate
In my API there are some custom header parameter. Because of this custom header parameter it was not working. I have added custom header parameter in api-manager.xml file.
<Access-Control-Allow-Headers>authorization,Access-Control-Allow-Origin,Content-Type,loggedInUserId,accessToken,clientToken</Access-Control-Allow-Headers>
I have faced a similar issue. I have edited the URL(from apicreator login) after it was published for first time and published it again. But the changes were never reflected. WSO2 was pointing to the old URL. Check the logs for error at "WSO2 HOME\repository\logs\wso2-apigw-errors" . Create another version and publish again and it should work.
The error is real, but misleading. In most likelihood, you've set the spec so that it returns a specific content type (say, application/json) but you actually return plain text (like a string or a number). swagger-ui expects it to be a JSON, tries to parse it and fails, giving you the wrong error message. However, it does mean your spec does not match what your API actually does.
I want Play to call a webservice. The webservice accepts application/json and returns this as well. With the following code I'm trying to achieve this. (Note, the headers.put(xxx) are added later in an effort to solve the problem).
WSRequest request = WS.url(targetURL);
request.body = new Gson().toJson(user);
request.headers.put("Content-type","application/json");
request.headers.put("Accept","application/json");
request.post();
The strange thing is that my JBOSS server replies: "Cannot consume content type". If I use my 'Simple REST client' plugin in my Chrome browser, and provide the entire JSON Body GSon created and add the content-type header, I get a valid response. Is this not the way to send JSON to the server? Or am I missing some fundamental piece here?
While checking the API documentation on the WSRequest class i noticed the field mime-type
By setting it as follows JBOSS (resteasy) accepted my request succesfully.
request.mimeType = "application/json";