Source:
<code>@Override public void run() { if (!isRunning.get()) return; try { Uri uri = Uri.parse(mConnectionDetails.getBuendiaApiUrl() + HEALTH_CHECK_ENDPOINT); HttpClient httpClient = new DefaultHttpClient(); HttpGet httpGet = new HttpGet(uri.toString()); if (httpGet.getURI().getHost() == null) { LOG.w("Configured OpenMRS server URL is invalid: %s", uri); reportIssue(HealthIssue.SERVER_CONFIGURATION_INVALID); return; } try { httpGet.addHeader(BasicScheme.authenticate( new UsernamePasswordCredentials( mConnectionDetails.getUser(), mConnectionDetails.getPassword()), "UTF-8", false)); HttpResponse httpResponse = httpClient.execute(httpGet); if (httpResponse.getStatusLine().getStatusCode() != HttpURLConnection.HTTP_OK) { LOG.w("The OpenMRS URL '%1$s' returned unexpected error code: %2$s", uri, httpResponse.getStatusLine().getStatusCode()); switch (httpResponse.getStatusLine().getStatusCode()) { case HttpURLConnection.HTTP_INTERNAL_ERROR: reportIssue(HealthIssue.SERVER_INTERNAL_ISSUE); break; case HttpURLConnection.HTTP_FORBIDDEN: case HttpURLConnection.HTTP_UNAUTHORIZED: reportIssue(HealthIssue.SERVER_AUTHENTICATION_ISSUE); <START> mHandler.getLooper().quit(); <END> break; case HttpURLConnection.HTTP_NOT_FOUND: default: reportIssue(HealthIssue.SERVER_NOT_RESPONDING); break; } return; } } catch (UnknownHostException | IllegalArgumentException e) { LOG.w("OpenMRS server unreachable: %s", uri); reportIssue(HealthIssue.SERVER_HOST_UNREACHABLE); return; } catch (HttpHostConnectException e) { LOG.w("OpenMRS server connection refused: %s", e.getHost()); } catch (IOException e) { LOG.w("OpenMRS server health check failed: %s", uri); return; } resolveAllIssues(); } finally { mHandler.postDelayed(this, getCheckPeriodMillis()); } }</code><technical_language>Nice. call stop() stopImpl() instead of quitting Looper though</technical_language>

Target:
@Override public void run() { if (!isRunning.get()) return; try { Uri uri = Uri.parse(mConnectionDetails.getBuendiaApiUrl() + HEALTH_CHECK_ENDPOINT); HttpClient httpClient = new DefaultHttpClient(); HttpGet httpGet = new HttpGet(uri.toString()); if (httpGet.getURI().getHost() == null) { LOG.w("Configured OpenMRS server URL is invalid: %s", uri); reportIssue(HealthIssue.SERVER_CONFIGURATION_INVALID); return; } try { httpGet.addHeader(BasicScheme.authenticate( new UsernamePasswordCredentials( mConnectionDetails.getUser(), mConnectionDetails.getPassword()), "UTF-8", false)); HttpResponse httpResponse = httpClient.execute(httpGet); if (httpResponse.getStatusLine().getStatusCode() != HttpURLConnection.HTTP_OK) { LOG.w("The OpenMRS URL '%1$s' returned unexpected error code: %2$s", uri, httpResponse.getStatusLine().getStatusCode()); switch (httpResponse.getStatusLine().getStatusCode()) { case HttpURLConnection.HTTP_INTERNAL_ERROR: reportIssue(HealthIssue.SERVER_INTERNAL_ISSUE); break; case HttpURLConnection.HTTP_FORBIDDEN: case HttpURLConnection.HTTP_UNAUTHORIZED: reportIssue(HealthIssue.SERVER_AUTHENTICATION_ISSUE); stopImpl(); break; case HttpURLConnection.HTTP_NOT_FOUND: default: reportIssue(HealthIssue.SERVER_NOT_RESPONDING); break; } return; } } catch (UnknownHostException | IllegalArgumentException e) { LOG.w("OpenMRS server unreachable: %s", uri); reportIssue(HealthIssue.SERVER_HOST_UNREACHABLE); return; } catch (HttpHostConnectException e) { LOG.w("OpenMRS server connection refused: %s", e.getHost()); } catch (IOException e) { LOG.w("OpenMRS server health check failed: %s", uri); return; } resolveAllIssues(); } finally { mHandler.postDelayed(this, getCheckPeriodMillis()); } }