spring - RestTemplate postForEntity experiencing java.io.IOException: Premature EOF error -
would appreciate regarding issue on 1 of maven projects.
exception in thread "main" org.springframework.web.client.resourceaccessexception: i/o error on post request "https://test-services.domain.ph/campaign/": premature eof; nested exception java.io.ioexception: premature eof @ org.springframework.web.client.resttemplate.doexecute(resttemplate.java:666) @ org.springframework.web.client.resttemplate.execute(resttemplate.java:613) @ org.springframework.web.client.resttemplate.postforentity(resttemplate.java:407) @ homecredit.ph.campaignconnector.call(campaignconnector.java:46) caused by: java.io.ioexception: premature eof @ sun.net.www.http.chunkedinputstream.readaheadblocking(chunkedinputstream.java:565) @ sun.net.www.http.chunkedinputstream.readahead(chunkedinputstream.java:609) @ sun.net.www.http.chunkedinputstream.read(chunkedinputstream.java:696) @ java.io.filterinputstream.read(filterinputstream.java:133)
origin:
responseentity<apiresponse> response = resttemplate.postforentity(url, entity, apiresponse.class);
destination:
@requestmapping(value="/campaign", method = requestmethod.post, consumes=mediatype.application_json_value) public responseentity<apiresponse> insertcampaignrecord( @valid @requestbody campaignrecordinsertrequest campaignrecordinsertrequest){ loginfo("incoming insert request. " + descriptorutility.converttostring(campaignrecordinsertrequest)); campaigndataservice.insertnewrecord(campaignrecordconverter.converttocampaignrecord(campaignrecordinsertrequest)); return responseutility.defaultresponse(); }
responseutility
public static responseentity<apiresponse> defaultresponse(){ apiresponse apiresponse = new apiresponse(); apiresponse.settimestamp(dateutility.currentdatestring()); apiresponse.setmessage(responsemessages.success); return new responseentity<>(apiresponse, httpstatus.ok); }
campaigndata service
@async("asyncexecutor") public void insertnewrecord(campaignrecord campaignrecord) { try { campaignrecordrepository.save(campaignrecord); } catch (exception e) { logerror(e); } }
server log
2017-09-11 11:11:11 info 18383 [http-nio-8773-exec-10] [campaignrecordcontroller] - incoming insert request. {"datecampaign":1504656000000,"cuid":... 2017-09-11 11:11:11 warn 18383 [http-nio-8773-exec-10] [sqlexceptionhelper] - sql error: 1062, sqlstate: 23000 2017-09-11 11:11:11 error 18383 [http-nio-8773-exec-10] [sqlexceptionhelper] - duplicate entry 'cmp_clx##1208637#20170906' key 'unique_key' 2017-09-11 11:11:11 error 18383 [http-nio-8773-exec-10] [campaigndataservice] - not execute statement; sql [n/a]; constraint [null]; nested exception org.hibernate.exception.constraintviolationexception: not execute statement 2017-09-11 11:11:11 error 18383 [http-nio-8773-exec-10] [campaigndataservice] - not execute statement
ps. server logs normal(return successful response either record saved or not)
issue intermittent. occurs randomly when sending bulk requests.
thanks in advance! :)
based on server logs seems like, server trying save record , failing (due unique key violation).
2017-09-11 11:11:11 warn 18383 [http-nio-8773-exec-10] [sqlexceptionhelper] - sql error: 1062, sqlstate: 23000 2017-09-11 11:11:11 error 18383 [http-nio-8773-exec-10] [sqlexceptionhelper] - duplicate entry 'cmp_clx##1208637#20170906' key 'unique_key' 2017-09-11 11:11:11 error 18383 [http-nio-8773-exec-10] [campaigndataservice] - not execute statement; sql [n/a]; constraint [null]; nested exception org.hibernate.exception.constraintviolationexception: not execute statement 2017-09-11 11:11:11 error 18383 [http-nio-8773-exec-10] [campaigndataservice] - not execute statement
looks server not able handle exception gracefully , whole flow breaks, causing http-500 response code (probably) empty response.
two actions can take:
- handle exception gracefully.
- verify why unique key getting violated , fix if possible.
Comments
Post a Comment