spring - Handle Connection and Read Timeouts for RestClient calls in android -


i have restservice interface many rest calls using throughout application.

i setting timeouts handling connection , read-timeouts

clienthttprequestfactory httpfactory = myrestservice.getresttemplate().getrequestfactory();     if(httpfactory!=null)     {         if(httpfactory instanceof simpleclienthttprequestfactory)         {             ((simpleclienthttprequestfactory)httpfactory).setconnecttimeout(10*1000);             ((simpleclienthttprequestfactory)httpfactory).setreadtimeout(30*1000);         }         else if(httpfactory instanceof httpcomponentsclienthttprequestfactory)         {             ((httpcomponentsclienthttprequestfactory)httpfactory).setconnecttimeout(10*1000);             ((httpcomponentsclienthttprequestfactory)httpfactory).setreadtimeout(30*1000);         }     } 

but stuck handling timeout situation. thought of using method not coming loop when rest call fails.

myrestservice.getresttemplate().seterrorhandler(new responseerrorhandler()      {         @override         public boolean haserror(clienthttpresponse paramclienthttpresponse) throws ioexception          {             log.e(tag, paramclienthttpresponse==null?"null response" : ("has error : " + paramclienthttpresponse.getstatustext()+" , status code : "+paramclienthttpresponse.getstatuscode()));              return false;         }         @override         public void handleerror(clienthttpresponse paramclienthttpresponse) throws ioexception          {             log.e(tag, paramclienthttpresponse==null?"null response":("handle error : " + paramclienthttpresponse.getstatustext()+" , status code : "+paramclienthttpresponse.getstatuscode()));         }     }); 

can me this..!?

timeout, bad gateway, host not found , other socket exceptions can not covered errorhandlers. target of errorhandlers errors in existing response stated in responseerrorhandler's method signature.

all socket exceptions throw restclientexception , must caught every resttemplate operation such getforobject() in try...catch block.

try {     repr = myrestservice.getresttemplate().getforobject(url, responsetype, vars); } catch (restclientexception e) {     //further exception processing, forming negative response should here } 

check out reference.

hope, helps.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -