diff --git a/src/com/owncloud/android/lib/network/OwnCloudClient.java b/src/com/owncloud/android/lib/network/OwnCloudClient.java index 2e8fb3d2..a974b8d1 100644 --- a/src/com/owncloud/android/lib/network/OwnCloudClient.java +++ b/src/com/owncloud/android/lib/network/OwnCloudClient.java @@ -172,7 +172,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 be76976f..2e8e2338 100644 --- a/src/com/owncloud/android/lib/operations/remote/GetUserNameRemoteOperation.java +++ b/src/com/owncloud/android/lib/operations/remote/GetUserNameRemoteOperation.java @@ -1,28 +1,31 @@ - -/* ownCloud Android client application - * Copyright (C) 2012-2013 ownCloud Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . +/* ownCloud Android Library is available under MIT license + * Copyright (C) 2014 ownCloud (http://www.owncloud.org/) + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. * */ + package com.owncloud.android.lib.operations.remote; -import java.io.IOException; - -import org.apache.commons.httpclient.HttpException; import org.apache.commons.httpclient.methods.GetMethod; import org.apache.http.HttpStatus; -import org.json.JSONException; import org.json.JSONObject; import android.util.Log; @@ -73,21 +76,20 @@ public class GetUserNameRemoteOperation extends RemoteOperation { protected RemoteOperationResult run(OwnCloudClient client) { RemoteOperationResult result = null; int status = -1; - - // Get Method - GetMethod get = new GetMethod(client.getWebdavUri() + OCS_ROUTE); - Log.d(TAG, "URL ------> " + client.getWebdavUri() + OCS_ROUTE); - // Add the Header - get.addRequestHeader(HEADER_OCS_API, HEADER_OCS_API_VALUE); + GetMethod get = null; //Get the user try { + //GetMethod get = new GetMethod(client.getWebdavUri() + OCS_ROUTE); + get = new GetMethod(client.getBaseUri() + OCS_ROUTE); + Log.e(TAG, "Getting OC user information from " + client.getBaseUri() + OCS_ROUTE); + Log.e(TAG, "Getting OC user information from " + client.getWebdavUri() + 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 +100,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(); }