Adobe Flex 3 : Fault Event doesnt return XML Feed sent from Server - ruby-on-rails

I am working on a flex application which communicates with a Rails backened.
When i request for some data, It sends back xml feed.
In some cases, if given parameters are not valid, then rails return an error feed with status code = 422 as following
email is wrong
But I dont get this feed in FaultEvent of Flex, How could i read error feed?
Thanks

Are you getting the result in ResultEvent in such cases? I am not sure for what all HTTP error codes FaultEvent will get invoke(I know only it goes for 404 and 500). May be its still going to ResultEvent as a valid result!

You can use HTTPService instead of URLLoader.

Flex HTTP results will not include the actual underlying HTTP response codes. It just doesn't work. (TM)

Related

Swashbuckle refuses to show response example for HTTP 500

I'm using Swashbuckle for a web api app in .Net Core 3.1. I want response examples for various response codes. I can get all of them working except HTTP 500. These are the attributes on the a particular method:
[SwaggerRequestExample(typeof(GroupInfoRequest), typeof(GroupInfoRequestExample))]
[SwaggerResponseExample(Status200OK, typeof(GroupInfo200Example))]
[SwaggerResponseExample(Status400BadRequest, typeof(GroupInfo400Example))]
[SwaggerResponseExample(Status403Forbidden, typeof(GroupInfo403Example))]
[SwaggerResponseExample(Status404NotFound, typeof(GroupInfo404Example))]
[SwaggerResponseExample(Status500InternalServerError, typeof(GroupInfo500Example))]
[ProducesResponseType(Status200OK)]
[ProducesResponseType(Status400BadRequest)]
[ProducesResponseType(Status403Forbidden)]
[ProducesResponseType(Status404NotFound)]
[ProducesResponseType(Status500InternalServerError)]
I can get all of them to render except the GroupInfo500Example. The application only returns an HTTP 500 to indicate an internal exception that isn't caught by other exception handlers. It is intended to return a body that contains, among other things, a GUID that can be passed in to our support organization to help them look up the exception in the application logs. I can not get the example to render for any 5xx error. If I change it to another status code, it renders, so it's specifically the 5xx result that doesn't render. I've checked the openapi json produced and it's not produced as part of the generated JSON. Is there a filter in place that keeps 5xx response docs from showing response examples?
Finally figured it out. I was missing part of the 'ProducesResponseType' attribute. It needs to have the return type as well as the HTTP status code. This works:
[ProducesResponseType(typeof(ADServiceOperationMultipleResult<GroupActionRequestForUsers, UserQuery>), Status200OK)]
[ProducesResponseType(typeof(ADServiceOperationMultipleResult<GroupActionRequestForUsers, UserQuery>), Status400BadRequest)]
[ProducesResponseType(typeof(ADServiceOperationMultipleResult<GroupActionRequestForUsers, UserQuery>), Status403Forbidden)]
[ProducesResponseType(typeof(ADServiceOperationMultipleResult<GroupActionRequestForUsers, UserQuery>), Status404NotFound)]
[ProducesResponseType(typeof(ADServiceOperationMultipleResult<GroupActionRequestForUsers, UserQuery>), Status422UnprocessableEntity)]
[ProducesResponseType(typeof(ADServiceOperationMultipleResult<GroupActionRequestForUsers, UserQuery>), Status500InternalServerError)]
Oddly enough, some status codes were including the example without it, but now the examples appear consistently as long as I include the method return type in the attribute.

Postman gives right response,but restassured returns empty for same request?

As you can see that postman returns expected result
but res.asString() gives [] in the blow code,can you tell me why?
def "simple test"(){
String url="http://xxx.xxx.xxx/assessment/api/Test.html"
when:""
io.restassured.response.Response res=RestAssured.given().header("Content-Type", "application/x-www-form-urlencoded").formParam("Action", "getDiagnosisList").formParam("Data", "[{\"subject\":\"冠心病\",\"option\":\"是\"}]").post(url)
then:""
res.prettyPrint()=="[\"身体健康状态不良\",\"医疗处置\"]"
}
It turns out that Chinese characters can't be encoded correctedly by default,after adding blow code,everything worked as expected:
RestAssured.given().config(RestAssured.config().encoderConfig(EncoderConfig.encoderConfig().defaultContentCharset("UTF-8")))
Maybe the request did via postman has not been cached, and on the other hand the same request via restassured is using some kind of cache. Recently I was having a similar issue because of it was hitting the varnish server. I'd recommend you to take a look at the response headers from both postman and restassured.

Are all elements in a POST requests body mandatory?

If a POST request requires that i send four data elements in the body, like:
{
"name":abc,
"surname":xyz,
"contact_no":1234,
"address":random_value
}
What will happen if I miss out some of the elements, for example if I call the web service with elements like,
{
"name":abc,
"surname":xyz,
}
What error is the server likely to throw ? I am having this issue because I am making a API call and it's giving me a HTTP error 500, so I guess it's not an error on my part, but this is one doubt i wanted to clear. Thanks in advance.
Its depends on the service structure (if all fields are mandatory or not),
and HTTP error (500) returns to server error or (server or link) not found .

ServiceStack request giving 500 for large request

I am using ServiceStack with MVC4 and getting 500 error when request parameters are long. I am posting ProductIds seperated by commas to controller via AJAX. In controller I have following call to servicestack API to retrieve data.
ResponseDTO res = restClient.Get(new RequestDTO { ProductIDs = ids});
//ResponseDTO res = restClient.Get(new RequestDTO { ProductIDs = "1234,1235,1236"});
If i submit small parameters in above, it works fine with no error. But when parameter string is in range of 1800 characters, it simply fails on above line and gives 500 Internal Server Error:
NetworkError: 500 Internal Server Error - http://localhost/Products/GetProducts
Exception Details: ServiceStack.ServiceClient.Web.WebServiceException: Not Found
is there a limit on GET method for posting large parameter request? Why does it fail for large request when for small parameters it successfully calls API, retrieves data via SQL procedure and sends to view correctly. What can I look into to solve this? Thank you!
p.s. when i debug via VS2012, i see exception details I see Message:Not Found and StatusCode: 404.
As Scott mentioned above, we tried POST for all methods and it fixed issue. I knew GET had limit on browser URL length but didnt think it matters as we had ServiceStack framework and all of their examples were using GET. Thanks again Scott.

Gzip decompress JSON POST body in Rails/Passenger/Nginx

We have a function in our Rails code that accepts a JSON POST body:
contacts = ActiveSupport::JSON.decode(request.raw_post.gsub("+", ""))
(I'm aware that I can get this from params["_json"] as well, but we have extremely large (MBs) POST bodies that do not get put into params["_json"] for some reason (and + throws errors too).
Since the JSON is usually sent from a mobile client, it's important to us to optimize the upload size. We want to switch to having the POST body gzipped.
However, no matter what we do, we get the same error with no line number:
MultiJson::DecodeError (743: unexpected token at ''):
We have tried:
gzipped_contacts = Zlib::GzipReader.new(StringIO.new(request.raw_post)).read
contacts = ActiveSupport::JSON.decode(gzipped_contacts.gsub("+", ""))
This:
gzipped_contacts = ActiveSupport::Gzip.decompress(request.raw_post)
contacts = ActiveSupport::JSON.decode(gzipped_contacts.gsub("+", ""))
And the solution found here: Rails: how to unzip a compressed xml request body?
I'm pretty sure this is not occurring at the controller level because I can't log anything there, so it needs to be done in the middleware or at the server (but I can't find anything for Nginx that lets us deflate). Please assist!
Ok, turns out the iPhone client was sending the wrong headers. So the solution for anyone encountering this is to see the advice here:
Rails: how to unzip a compressed xml request body?
And verify that you are sending Content-Type: gzip/json.

Resources