Spring Rest Service getting 400 Bad Request after running 2-3 minutes - spring

I have a rest client and server which we have developed using spring. The client will send requests to the server for 2-3 minutes and then starts getting org.springframework.web.client.HttpClientErrorException: 400 Bad Request errors.
Once the 400 error starts the client is unable to communicate with the server.
Any suggestions would be appreciated.
I will try to develop a working example that creates this error.
I have resolved this issue. The code was setting the following for every call:
// Add the Gson message converter
restTemplate.getMessageConverters().add(new MappingJacksonHttpMessageConverter());
I moved this code to the constructor and no longer getting the 400 Bad Request error.

Related

JMeter response 504 Gateway time-out?

I am trying to perform a test against an endpoint with 1 thread. I configured a HTTP request with JSON Monk endpoint URL using JMEter.
But when I run the test I get Response code:504 in the Sampler result. The same when I use the URL in a browser I get also 504 Gateway Time-out
Can anyone help me with this issue? - I tried in another pc and I got the same error!
I have installed JMeter correctly and my code is correct too. I am working on a Windows 10.
HTTP Request:
As per HTTP Status Code 504 description
The HyperText Transfer Protocol (HTTP) 504 Gateway Timeout server error response code indicates that the server, while acting as a gateway or proxy, did not get a response in time from the upstream server that it needed in order to complete the request.
Note: A Gateway might refer to different things in networking and a 504 error is usually not something you can fix, but requires a fix by the web server or the proxies you are trying to get access through.
So it indicates the problem with the server you're trying to test, if you own the website - go and fix it, if you know someone who is responsible for it - inform him/her/them.
There is nothing you can do from JMeter perspective. If you know how response should look like you can use a Dummy Sampler to return this response so you could play with the response data
By the way, it's down for me as well:

405 Method is not Allowed exception: "Request Method 'T' not supported" for GET call and "Request Method 'ST' not supported" for POST

I am facing a very strange issue in my project. It is related to rest API call using spring reactive webclient bulider. It is working fine on local and prod as well but abnormally giving below error after 3 or 4 request to same endpoint.
"org.springframework.web.server.MethodNotAllowedException: 405 METHOD_NOT_ALLOWED "Request method 'T' not supported"
This is valid exception as method going to "T" for Get method and "ST" for Post method .I am not able to understand why two starting charcter truncating from method name
Please help me resolve this error.
OP and I must have been the only ones to have ever experienced this and honestly I don't know the root cause but this was my situation and the fix.
For me, I was running 2 services in a docker. One service would make requests to the other. The 1st request always succeeds but the subsequent one always fails. After some time, a new request succeeds again.
I speculated that it must have to do with a persistent connection. I am using OkHttpClient library (3.14.9) to make the request. The service receiving the request was running spring webflux but I don't think the service was the issue. I could make repeated successful requests to it using curl from inside the 1st service's container.
OkHttpClient uses keep-alive connections by default. You can specify for a single request that you don't want to keep connection alive by setting the Connection header to close. Once I did that, all requests were working again.
For whatever reason, the re-use of the keep-alive connections was not sending over over and entire request. It was always truncating the first 2 characters of the method that is why Request method 'T' not supported. Perhaps the 1st request didn't end correctly and eats up the 2nd request's first 2 characters. I don't know the root cause. Probably a bug with OkHttpClient

Rest template exchange method working incorrectly

I am consuming another restful web service that's https inside my rest WS. When I am running my application on localachine the code works fine. But as soon as I deploy it and then access my application through that url, that rest template call written inside my code gives 400 error.
Here is the log trace
400 Bad Request
: org.springframework.web.client.HttpClientErrorException: 400 Bad Request
at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:76)
at org.springframework.web.client.RestTemplate.handleResponseError(RestTemplate.java:524)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:481)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:439)
at org.springframework.web.client.RestTemplate.postForObject(RestTemplate.java:317)
at com.pekam.myandroid.MainActivity$HttpRequestTask.doInBackground(MainActivity.java:106)
at com.pekam.myandroid.MainActivity$HttpRequestTask.doInBackground(MainActivity.java:1)
at android.os.AsyncTask$2.call(AsyncTask.java:288)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)
Probably there should be an issue in your request. Either you are missing mandatory request parameters in your request XML or missing some headers which throw this 400 Bad request exception.
Please follow this Link.It may resolve your issue. Let us know for any issue.

Spring what is between Controller and Interceptor

I have a controller that is doing something, everything seems fine, it logs a success, and then it does this
return new ResponseEntity<>(resp, HttpStatus.OK);
Seems like it should send a 200 OK.
Well, I also have a HandlerInterceptorAdapter with an "afterCompletion" that logs the status:
logger.debug("Response status: {}, URI: {}", response.getStatus(), request.getRequestURI());
This is showing a 500 where there was a success from the controller.
In the stdout logs I see an error
2018-01-12 12:33:59.035 ERROR 18952 --- [pr-8080-exec-14] o.s.boot.web.support.ErrorPageFilter : Cannot forward to error page for request [/ws/path] as the response has already been committed.
As a result, the response may have the wrong status code. If your application is running on WebSphere Application Server you may be able to resolve this problem by setting com.ibm.ws.webcontainer.invokeFlushAfterService to false
and
org.apache.catalina.connector.ClientAbortException: java.io.IOException: APR error: -32
I can't find any doc on what that APR error is and I have no idea why the status code would be wrong. I am using tomcat 8.5.
So. APR -32 is a "Client Abort" error. The client was timing out in waiting. It looks like what was happening was the client made a request and was sitting in queue for a few seconds. It has a short hard timeout limit. The client timed out before the server got to the request. Then the server picked up the request and did everything fine but when trying to write back to the client, it found the socket closed. So it set a 500 and threw that exception.

REST service, always give 404 Context Root Not Found error for the first time request, then work well

In my REST service, once I start or restart my websphere application server and do a request at the first time, the response will return 404 Context Root Not Found error, after this, do requests on this REST service can work well.
The problem is that the 404 error is always return at my first request after my server start.
Could you give some suggestions?

Resources