From 5b4f63ebdb365c6e7e9a3e0148aa18a8d5fb5067 Mon Sep 17 00:00:00 2001 From: "David A. Velasco" Date: Wed, 29 Jan 2014 12:48:14 +0100 Subject: [PATCH] Grant that GetUserNameRemoteOperation always return a non null result --- .../android/lib/network/OwnCloudClient.java | 2 +- .../remote/GetUserNameRemoteOperation.java | 39 ++++++++++--------- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/com/owncloud/android/lib/network/OwnCloudClient.java b/src/com/owncloud/android/lib/network/OwnCloudClient.java index 9ec8867f..cfa474e2 100644 --- a/src/com/owncloud/android/lib/network/OwnCloudClient.java +++ b/src/com/owncloud/android/lib/network/OwnCloudClient.java @@ -171,7 +171,7 @@ public class OwnCloudClient extends HttpClient { customRedirectionNeeded = mFollowRedirects; } if (mSsoSessionCookie != null && mSsoSessionCookie.length() > 0) { - method.setRequestHeader("Cookie", mSsoSessionCookie); + method.addRequestHeader("Cookie", mSsoSessionCookie); } int status = super.executeMethod(method); int redirectionsCount = 0; diff --git a/src/com/owncloud/android/lib/operations/remote/GetUserNameRemoteOperation.java b/src/com/owncloud/android/lib/operations/remote/GetUserNameRemoteOperation.java index 9f5c0ff6..f5f443d6 100644 --- a/src/com/owncloud/android/lib/operations/remote/GetUserNameRemoteOperation.java +++ b/src/com/owncloud/android/lib/operations/remote/GetUserNameRemoteOperation.java @@ -73,21 +73,18 @@ public class GetUserNameRemoteOperation extends RemoteOperation { protected RemoteOperationResult run(OwnCloudClient client) { RemoteOperationResult result = null; int status = -1; - - // Get Method - GetMethod get = new GetMethod(client.getBaseUri() + OCS_ROUTE); - Log.d(TAG, "URL ------> " + client.getBaseUri() + OCS_ROUTE); - // Add the Header - get.addRequestHeader(HEADER_OCS_API, HEADER_OCS_API_VALUE); + GetMethod get = null; //Get the user try { + get = new GetMethod(client.getBaseUri() + OCS_ROUTE); + Log.e(TAG, "Getting OC user information from " + client.getBaseUri() + OCS_ROUTE); + // Add the Header + get.addRequestHeader(HEADER_OCS_API, HEADER_OCS_API_VALUE); status = client.executeMethod(get); if(isSuccess(status)) { - Log.d(TAG, "Obtain RESPONSE"); String response = get.getResponseBodyAsString(); - - Log.d(TAG, "GET RESPONSE.................... " + response); + Log.d(TAG, "Successful response: " + response); // Parse the response JSONObject respJSON = new JSONObject(response); @@ -98,21 +95,25 @@ public class GetUserNameRemoteOperation extends RemoteOperation { String email = respData.getString(NODE_EMAIL); // Result - result = new RemoteOperationResult(isSuccess(status), status, (get != null ? get.getResponseHeaders() : null)); + result = new RemoteOperationResult(true, status, get.getResponseHeaders()); mUserName = displayName; - Log.d(TAG, "Response: " + id + " - " + displayName + " - " + email); + Log.d(TAG, "*** Parsed user information: " + id + " - " + displayName + " - " + email); + } else { + result = new RemoteOperationResult(false, status, get.getResponseHeaders()); + String response = get.getResponseBodyAsString(); + Log.e(TAG, "Failed response while getting user information "); + if (response != null) { + Log.e(TAG, "*** status code: " + status + " ; response message: " + response); + } else { + Log.e(TAG, "*** status code: " + status); + } } - } catch (HttpException e) { + } catch (Exception e) { result = new RemoteOperationResult(e); - e.printStackTrace(); - } catch (IOException e) { - result = new RemoteOperationResult(e); - e.printStackTrace(); - } catch (JSONException e) { - result = new RemoteOperationResult(e); - e.printStackTrace(); + Log.e(TAG, "Exception while getting OC user information", e); + } finally { get.releaseConnection(); }