/** * Verwijdert memberships op de server die lokaal verwijderd zijn * * @throws SyncException */ private void deleteMemberships() throws SyncException { Cursor c = db.getRemovedMemberships(); if (!c.moveToFirst()) { return; // Dat ging snel. } do { int groupid = c.getInt(0); HttpDelete httpd = new HttpDelete(serverUrl + "membership/id/" + groupid); UsernamePasswordCredentials creds = new UsernamePasswordCredentials(mappUser, mappPass); try { httpd.addHeader(new BasicScheme().authenticate(creds, httpd)); } catch (AuthenticationException e1) { Log.e(Mapp.TAG, e1.getStackTrace().toString()); throw new SyncException("Authentication failed"); } HttpResponse response; try { response = httpclient.execute(httpd); if (response.getStatusLine().getStatusCode() == 418) { throw new SyncException("Unable to synchronize because the server is a teapot."); } else if (response.getStatusLine().getStatusCode() == 401) { throw new SyncException("Not authorized"); } else if (response.getStatusLine().getStatusCode() != 200) { // Er is iets mis gegaan. // Lees de uitvoer InputStream is = response.getEntity().getContent(); BufferedReader r = new BufferedReader(new InputStreamReader(is)); StringBuilder total = new StringBuilder(); String line; while ((line = r.readLine()) != null) { total.append(line); } JSONObject result = null; result = new JSONObject(total.toString()); Log.e(Mapp.TAG, "Sync error: " + result.getString("message")); throw new SyncException(result.getString("message")); } else { db.removeRemovedMembership(groupid); } } catch (ClientProtocolException e) { Log.e(Mapp.TAG, e.getMessage()); throw new SyncException("Epic HTTP failure"); } catch (IOException e) { Log.e(Mapp.TAG, e.getMessage()); throw new SyncException("Exception during server synchronisation"); } catch (JSONException e) { Log.e(Mapp.TAG, "Sync failed. Getting status message from JSON response failed."); throw new SyncException("Invalid server response"); } } while (c.moveToNext()); }