java - Spring Rest template - 204 content in response from webservice -
i have rest service , consumed using spring's resttemplate apache httpclient as,
@autowired public clientimpl(@value("${base-uri}") final string baseurl, @qualifier("restoperations") restoperations resttemplate) { serviceurl = baseurl; resttemplate = resttemplate; } private list<responsedetails> processrequest(customrequest request) throws exception { responseentity<responsedetails[]> responseentity = resttemplate.exchange(serviceurl, httpmethod.post, entity, responsedetails[].class); if (responseentity.getstatuscode().value() == 204) { return collections.<responsedetails>emptylist(); } responsedetails[] response = responseentity.getbody(); return response != null ? lists.newarraylist(response) : collections.<responsedetails>emptylist(); }
when webservice returns 204 response, second service call after 204 response, fails read timeout.
spring-web : 4.3.5
i cannot figure out cause. help?
edit: debug logs,
org.apache.http.impl.conn.defaulthttpresponseparser;garbage in response: ÿþ{"id":0}http/1.1 204 not find
response in server logs httpclient:
<204 no content,{cache-control=[no-cache], pragma=[no-cache], content-type=[application/json; charset=utf-16], expires=[-1], server=[some], x-aspnet-version=[someversion], x-powered-by=[asp.net], date=[somedate]}>
http 204 status code "no content", there seems garbage content in response. can seen on logs:
ÿþ{"id":0}
this cause of problems have.
http client not expecting in body content of 204 response not read it, hence response handler not see there garbage. since there garbage not yet consumed connection stays open until read -> next connection, tries reuse connection, gets hit read timeout.
there separate thread similar problem, problem worked around custom http request executor. using such executor, call getbody() obtain garbage response body , next request not have issues.
Comments
Post a Comment