During some load testing of one of our REST services, we begin to see these logs for the Spring REST template when the load increases:
With a simultaneous load and after 3-4 hours, the Accept header of the http request becomes
DEBUG: org.springframework.web.client.RestTemplate - Setting request Accept header to [text/plain, application/json, application/*+json, text/plain, text/plain, text/plain, text/plain, text/plain, text/plain, text/plain, text/plain, text/plain, text/plain, text/plain, text/plain, text/plain, text/plain, text/plain, text/plain, text/plain, text/plain, text/plain, text/plain, text/plain, text/plain, text/plain, text/plain, text/plain, text/plain, text/plain,<and so on>, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, <and so on>]
Ultimately, all calls to this service using RestTemplate start with an error with a 400 error (incorrect request)
The called REST service accepts a String input and has the following signature
@RequestMapping(value = "/findRecordById", method = {RequestMethod.POST, RequestMethod.GET }) @ResponseBody public String findRecordById(@RequestBody String id) {
We send a POST request to this service with the contents of the request in the form of "someId", for example. "123"
With a low load, there is no problem calling the service.
What puzzles the text is text / plain, * / * , which is added to the list of accept headers for the REST template. Why is this happening?
The declaration of a REST bean template is as follows:
<bean id="restTemplate" class="org.springframework.web.client.RestTemplate"> <constructor-arg> <bean class="org.springframework.http.client.HttpComponentsClientHttpRequestFactory"> <property name="readTimeout"> <value>90000</value> </property> <property name="httpClient" ref="restHttpClient" /> </bean> </constructor-arg> </bean> <bean id="restHttpClient" class="org.apache.http.impl.client.DefaultHttpClient"> <constructor-arg> <bean class="org.apache.http.impl.conn.PoolingClientConnectionManager"> <property name="defaultMaxPerRoute"> <value>100000</value> </property> <property name="maxTotal"> <value>100000</value> </property> </bean> </constructor-arg> </bean>
How the request is created:
String postParams = "\"" + id + "\""; String postResp = restTemplate.postForObject("findRecordById",postParams, String.class);