Why I am getting different status code from ocelot? - docker

I have a microservice project with ocelot API Gateway. In one service I have retuned 204(No Content) response. When I run that service directly then I am getting a proper response but when I run that service using ocelot then I am getting 500(Internal Server).
I have verified routing and it's fine because the same API return 200 or 201 then it called from ocelot successfully. But when 204 returns then it returns 500 but it should return 204.
I have checked logs it shows this information:
fail: Microsoft.AspNetCore.Server.Kestrel[13]
Connection id "0HM4G9THO6LV0", Request id "0HM4G9THO6LV0:00000006": An unhandled exception was thrown by the application.
System.InvalidOperationException: Response Content-Length mismatch: too few bytes written (0 of 72).
Can anyone please help me?
Is there any configuration to handle the 204 status code in the ocelot API gateway?

I had the same problem. I checked my controllers and one of them return 204 with a response body. If you have the same issue you need to return 204 only.

Related

Ktor Service Error Response getting error

Could you explain, why is my app denying requests:
{"message":"Access denied","success":true,"code":500} BODY END E/registerEnd: called E/registerEnd: KtorServiceErrorResponse(success=false, message=Fields [accessToken, refreshToken] are required for type with serial name 'KtorServiceLoginResponse', but they were missing) E/registerEnd: is not a valid ktor response
response 200 but code 500
Any ideas?
I'm trying to run my app in production

Jmeter POST call with Form data and application/x-www-form-urlencoded

Need some help with Jmeter .
Environment: Apache Jmeter 5.0 , Java 1.8, Mac OS High Sierra 10.13.6
Problem outline:- Post call not getting 302 response with Location header(redirect) instead get 200 response without Location header
The problem here is in Jmeter but same works in Postman. In a Jmeter thread group I have cookie manager and couple of Get and Post calls. I set to save the cookie in user.properties file.
Scenario:- Login
1) first do GET ( call with some query parameters) / login endpoint will give response cookie and csrf-token with 200 then next
2) next do POST with form data ( in xxxform url encoded with csrf-token from get response ) + Cookie from get response from at / login endpoint should return 302 with token is the expected result but getting 200 instead with no redirection in Jmeter. In Postman able to get the desired results.
When the same is replicated in Jmeter with same setting as performed in Postman results are not as expected
Errors in Jmeter are:- 404 with location header missing or 200 with no Location response header
But not 302 with Location response header
With how many different combinations attempted.
Attached my sample TestPlans and Post request. Have also tried to place form data in Body instead in Parameters tab but have the same result.
Thanking in advance! Appreciate anyone who could share their thoughts and rescue from this current issue.

What's the right HTTP error code if parsing the request fails

If you create a web service which receives an processes some data like XML/JSON and the parsing of the data fails because it's incorrect, what do you do?
Send a HTTP 400 error code: After all it was the client who messed up the data (XML/JSON)
Send a HTTP 500 error code: It's the server who wasn't able to complete its task
If data in the request is malformed, then you'll want to return a 400 level error. Generally 500-level errors mean that something is wrong on the server that has nothing to do with the client or the client's request.
422 code.
422 Unprocessable Entity
The 422 (Unprocessable Entity) status code means the server
understands the content type of the request entity (hence a
415(Unsupported Media Type) status code is inappropriate), and the
syntax of the request entity is correct (thus a 400 (Bad Request)
status code is inappropriate) but was unable to process the contained
instructions. For example, this error condition may occur if an XML
request body contains well-formed (i.e., syntactically correct), but
semantically erroneous, XML instructions
https://www.rfc-editor.org/rfc/rfc4918#section-11

HTTP CODE = 409 errors

We are experiencing HTTP CODE = 409 error when we are trying to push our code to the repository. I tried with different IP address and it still doesn't work.
I wonder if there's something wrong with remote side.
Here is the message we got when pushing:
error: RPC failed; result=22, HTTP code = 409
fatal: The remote end hung up unexpectedly
fatal: recursion detected in die handler
Everything up-to-date
Check the Content-Type, like that one application/json. Attached link have a example:
http://blog.app4domain.com/2016/12/got-409-http-return-code-in-jboss.html
Conflicts are most likely to occur in response to a PUT request. For example, if versioning were being used and the entity being PUT included changes to a resource which conflict with those made by an earlier (third-party) request, the server might use the 409 response to indicate that it can't complete the request. In this case, the response entity would likely contain a list of the differences between the two versions in a format defined by the response Content-Type.
https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html

Bad request on ProcessUserAuthorization (DotNetOpenAuth 4.2.2.13055)

I'm trying to upgrade the DotNetOpenAuth verson to 4.2.2.13055, in the Google dotnet client library.
So I downloaded the latest dlls - DotNetOpenAuth.Core, DotNetOpenAuth.OAuth2, etc. (we still don't work with NuGet).
I made a small change (changed the way I construct NativeApplcationClient with client_id and client_secret) to support the new version.
Then, I tried to run a sample we have in our samples repository (e.g. https://code.google.com/p/google-api-dotnet-client/source/browse/Tasks.SimpleOAuth2/Program.cs?repo=samples), and I got a bad request error, as following:
DotNetOpenAuth.Messaging.ProtocolException: Error occurred while sending a direct message or getting the response. --->
System.Net.WebException: The remote server returned an error: (400) Bad Request.
at System.Net.HttpWebRequest.GetResponse()
at DotNetOpenAuth.Messaging.StandardWebRequestHandler.GetResponse(HttpWebRequest request, DirectWebRequestOptions opt
ions)
--- End of inner exception stack trace ---
at DotNetOpenAuth.Messaging.StandardWebRequestHandler.GetResponse(HttpWebRequest request, DirectWebRequestOptions opt
ions)
at DotNetOpenAuth.Messaging.StandardWebRequestHandler.GetResponse(HttpWebRequest request)
at DotNetOpenAuth.Messaging.Channel.GetDirectResponse(HttpWebRequest webRequest)
at DotNetOpenAuth.Messaging.Channel.RequestCore(IDirectedProtocolMessage request)
at DotNetOpenAuth.Messaging.Channel.Request(IDirectedProtocolMessage requestMessage)
at DotNetOpenAuth.OAuth2.ClientBase.UpdateAuthorizationWithResponse(IAuthorizationState authorizationState, EndUserAu
thorizationSuccessAuthCodeResponse authorizationSuccess)
at DotNetOpenAuth.OAuth2.UserAgentClient.ProcessUserAuthorization(IAuthorizationState authorizationState, IDirectedPr
otocolMessage response)
at DotNetOpenAuth.OAuth2.UserAgentClient.ProcessUserAuthorization(Uri actualRedirectUrl, IAuthorizationState authoriz
ationState)
at Google.Apis.Authentication.OAuth2.DotNetOpenAuth.NativeApplicationClient.ProcessUserAuthorization(String authCode,
IAuthorizationState authorizationState) in c:\code.google.com\google-api-dotnet-client\default_oauth2\Src\GoogleApis.Au
thentication.OAuth2\DotNetOpenAuth\NativeApplicationClient.cs:line 102
at Google.Apis.Samples.TasksOAuth2.Program.GetAuthorization(NativeApplicationClient arg) in c:\code.google.com\google
-api-dotnet-client\samples_oauth2\Tasks.SimpleOAuth2\Program.cs:line 73
at Google.Apis.Authentication.OAuth2.OAuth2Authenticator`1.LoadAccessToken() in c:\code.google.com\google-api-dotnet-
client\default_oauth2\Src\GoogleApis.Authentication.OAuth2\OAuth2Authenticator.cs:line 124
I noticed also that there is a different in the second request (in exchanging the code with a token): Authorization header was added to the request, and the body was missing my client_id and client_secret.
Similar code worked on old version - 4.0.0.11165,
Am I missing something?
I wonder if the problem is that the newer DNOA version supports putting client credentials in the HTTP header by default. If you create your Client class, passing in a different client credential provider into the constructor, it may work for you.
To change the behavior from using the HTTP Authorization header back to passing client credentials in the POST entity, instantiate your ClientBase-derived class passing in this as a parameter to the constructor:
ClientCredentialApplicator.PostParameter(clientSecret)

Resources