Skip to content

Commit

Permalink
Merge pull request #59 from OpenSRP/issue58
Browse files Browse the repository at this point in the history
Reinitialize httpclient after connection has changed
  • Loading branch information
Ephraim (Keyman) Muhia authored Mar 5, 2018
2 parents 3c1b05d + 2df778b commit f1a7313
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@

public class HTTPAgent {
private static final String TAG = HTTPAgent.class.getCanonicalName();
private final GZipEncodingHttpClient httpClient;
private GZipEncodingHttpClient httpClient;
private Context context;
private AllSettings settings;
private AllSharedPreferences allSharedPreferences;
Expand All @@ -77,6 +77,10 @@ public HTTPAgent(Context context, AllSettings settings, AllSharedPreferences
this.allSharedPreferences = allSharedPreferences;
this.configuration = configuration;

setupHttpClient();
}

public void setupHttpClient() {
BasicHttpParams basicHttpParams = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(basicHttpParams, 30000);
HttpConnectionParams.setSoTimeout(basicHttpParams, 60000);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

import org.smartregister.CoreLibrary;
import org.smartregister.sync.DrishtiSyncScheduler;

import static org.smartregister.util.Log.logInfo;
Expand All @@ -23,6 +24,12 @@ public void onReceive(final Context context, Intent intent) {
if (isDeviceConnectedToNetwork(intent)) {
logInfo("Device got connected to network. Trying to start Dristhi Sync scheduler.");
DrishtiSyncScheduler.start(context);

//Re-initialize HTTP CLIENT
org.smartregister.Context opensrpContext = CoreLibrary.getInstance().context();
if (opensrpContext != null) {
opensrpContext.getHttpAgent().setupHttpClient();
}
}
}
}
Expand Down

0 comments on commit f1a7313

Please sign in to comment.