Skip to content
Snippets Groups Projects
Commit fdaefc31 authored by Dustin Jenkins's avatar Dustin Jenkins
Browse files

Fixes #27 - Make use of HttpDelete

parent b07078f8
No related branches found
No related tags found
No related merge requests found
...@@ -629,46 +629,30 @@ public class GMSClient implements TransferListener ...@@ -629,46 +629,30 @@ public class GMSClient implements TransferListener
// reset the state of the cache // reset the state of the cache
clearCache(); clearCache();
HttpURLConnection conn = HttpDelete delete = new HttpDelete(removeGroupMemberURL, true);
(HttpURLConnection) removeGroupMemberURL.openConnection(); delete.setSSLSocketFactory(getSSLSocketFactory());
conn.setRequestMethod("DELETE"); delete.run();
SSLSocketFactory sf = getSSLSocketFactory();
if ((sf != null) && ((conn instanceof HttpsURLConnection)))
{
((HttpsURLConnection) conn)
.setSSLSocketFactory(getSSLSocketFactory());
}
// Try to handle anonymous access and throw AccessControlException
int responseCode = -1;
try
{
responseCode = conn.getResponseCode();
}
catch (Exception ignore) {}
if (responseCode != 200) Throwable error = delete.getThrowable();
if (error != null)
{ {
String errMessage = NetUtil.getErrorBody(conn); // transfer returns a -1 code for anonymous access.
log.debug("removeGroupMember response " + responseCode + ": " + if ((delete.getResponseCode() == -1) ||
errMessage); (delete.getResponseCode() == 401) ||
(delete.getResponseCode() == 403))
if ((responseCode == -1) ||
(responseCode == 401) ||
(responseCode == 403))
{ {
throw new AccessControlException(errMessage); throw new AccessControlException(error.getMessage());
} }
if (responseCode == 400) if (delete.getResponseCode() == 400)
{ {
throw new IllegalArgumentException(errMessage); throw new IllegalArgumentException(error.getMessage());
} }
if (responseCode == 404) if (delete.getResponseCode() == 404)
{ {
throw new GroupNotFoundException(errMessage); throw new GroupNotFoundException(error.getMessage());
} }
throw new IOException(errMessage);
throw new IOException(error);
} }
} }
...@@ -698,49 +682,34 @@ public class GMSClient implements TransferListener ...@@ -698,49 +682,34 @@ public class GMSClient implements TransferListener
// reset the state of the cache // reset the state of the cache
clearCache(); clearCache();
HttpURLConnection conn = HttpDelete delete = new HttpDelete(removeUserMemberURL, true);
(HttpURLConnection) removeUserMemberURL.openConnection(); delete.setSSLSocketFactory(getSSLSocketFactory());
conn.setRequestMethod("DELETE"); delete.run();
SSLSocketFactory sf = getSSLSocketFactory();
if ((sf != null) && ((conn instanceof HttpsURLConnection)))
{
((HttpsURLConnection) conn)
.setSSLSocketFactory(getSSLSocketFactory());
}
// Try to handle anonymous access and throw AccessControlException
int responseCode = -1;
try
{
responseCode = conn.getResponseCode();
}
catch (Exception ignore) {}
if (responseCode != 200) Throwable error = delete.getThrowable();
if (error != null)
{ {
String errMessage = NetUtil.getErrorBody(conn); // transfer returns a -1 code for anonymous access.
log.debug("removeUserMember response " + responseCode + ": " + if ((delete.getResponseCode() == -1) ||
errMessage); (delete.getResponseCode() == 401) ||
(delete.getResponseCode() == 403))
if ((responseCode == -1) ||
(responseCode == 401) ||
(responseCode == 403))
{ {
throw new AccessControlException(errMessage); throw new AccessControlException(error.getMessage());
} }
if (responseCode == 400) if (delete.getResponseCode() == 400)
{ {
throw new IllegalArgumentException(errMessage); throw new IllegalArgumentException(error.getMessage());
} }
if (responseCode == 404) if (delete.getResponseCode() == 404)
{ {
String errMessage = error.getMessage();
if (errMessage != null && errMessage.toLowerCase().contains("user")) if (errMessage != null && errMessage.toLowerCase().contains("user"))
throw new UserNotFoundException(errMessage); throw new UserNotFoundException(errMessage);
else else
throw new GroupNotFoundException(errMessage); throw new GroupNotFoundException(errMessage);
} }
throw new IOException(errMessage);
throw new IOException(error);
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment