gwt - RequestFactory and offline clients -


i'm trying create application able work when network down. idea store data returned requestfactory on localstorage, , use localstorage when network isn't available. problem - i'm not sure how differentiate between server errors(5xx, 4xx, ...) , network errors. (i assume on both cases receiver.onfailure() called, still don't know how identify situation)

any appreciated,

thanks, gilad.

the response code when there no internet connection 0.

with requestfactory identify request unsuccessful because of network response code has accessed. requesttransport seems best place.

here rough implementation of offlineawarerequesttransport.

   public class offlineawarerequesttransport extends defaultrequesttransport {    private final eventbus eventbus;   private boolean online = true;    public offlineawarerequesttransport(eventbus eventbus) {     this.eventbus = eventbus;   }    @override   public void send(final string payload, final transportreceiver receiver) {      // super.send(payload, proxy);     requestbuilder builder = createrequestbuilder();     configurerequestbuilder(builder);      builder.setrequestdata(payload);     builder.setcallback(createrequestcallback(receiver, payload));     try {       builder.send();     } catch (requestexception e) {     }   }    protected static final int sc_offline = 0;    protected requestcallback createrequestcallback(final transportreceiver receiver,       final string payload) {      return new requestcallback() {        public void onerror(request request, throwable exception) {         receiver.ontransportfailure(new serverfailure(exception.getmessage()));       }        public void onresponsereceived(request request, response response) {         if (response.sc_ok == response.getstatuscode()) {           string text = response.gettext();           setonline(true);           receiver.ontransportsuccess(text);         } else if (response.getstatuscode() == sc_offline) {           setonline(false);           boolean processedok = processpayload(payload);           receiver.ontransportfailure(new serverfailure("you offline!", offlinereceiver.name,               "", !processedok));         } else {           setonline(true);           string message = "server error " + response.getstatuscode() + " " + response.gettext();           receiver.ontransportfailure(new serverfailure(message));         }       }      };   } 

Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -