mirror of
https://github.com/owncloud/android-library.git
synced 2025-06-07 16:06:08 +00:00
Merge pull request #2 from owncloud/bug_null_result_in_GetUserNameRemoteOperation_when_unsucessful
Granted that GetUserNameRemoteOperation always return a non null result
This commit is contained in:
commit
4ab2c9ac66
@ -172,7 +172,7 @@ public class OwnCloudClient extends HttpClient {
|
|||||||
customRedirectionNeeded = mFollowRedirects;
|
customRedirectionNeeded = mFollowRedirects;
|
||||||
}
|
}
|
||||||
if (mSsoSessionCookie != null && mSsoSessionCookie.length() > 0) {
|
if (mSsoSessionCookie != null && mSsoSessionCookie.length() > 0) {
|
||||||
method.setRequestHeader("Cookie", mSsoSessionCookie);
|
method.addRequestHeader("Cookie", mSsoSessionCookie);
|
||||||
}
|
}
|
||||||
int status = super.executeMethod(method);
|
int status = super.executeMethod(method);
|
||||||
int redirectionsCount = 0;
|
int redirectionsCount = 0;
|
||||||
|
@ -1,28 +1,31 @@
|
|||||||
|
/* ownCloud Android Library is available under MIT license
|
||||||
/* ownCloud Android client application
|
* Copyright (C) 2014 ownCloud (http://www.owncloud.org/)
|
||||||
* Copyright (C) 2012-2013 ownCloud Inc.
|
*
|
||||||
*
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
* it under the terms of the GNU General Public License version 2,
|
* in the Software without restriction, including without limitation the rights
|
||||||
* as published by the Free Software Foundation.
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
*
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
* This program is distributed in the hope that it will be useful,
|
* furnished to do so, subject to the following conditions:
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
*
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* GNU General Public License for more details.
|
* all copies or substantial portions of the Software.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* 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;
|
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.commons.httpclient.methods.GetMethod;
|
||||||
import org.apache.http.HttpStatus;
|
import org.apache.http.HttpStatus;
|
||||||
import org.json.JSONException;
|
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
@ -73,21 +76,20 @@ public class GetUserNameRemoteOperation extends RemoteOperation {
|
|||||||
protected RemoteOperationResult run(OwnCloudClient client) {
|
protected RemoteOperationResult run(OwnCloudClient client) {
|
||||||
RemoteOperationResult result = null;
|
RemoteOperationResult result = null;
|
||||||
int status = -1;
|
int status = -1;
|
||||||
|
GetMethod get = null;
|
||||||
// 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);
|
|
||||||
|
|
||||||
//Get the user
|
//Get the user
|
||||||
try {
|
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);
|
status = client.executeMethod(get);
|
||||||
if(isSuccess(status)) {
|
if(isSuccess(status)) {
|
||||||
Log.d(TAG, "Obtain RESPONSE");
|
|
||||||
String response = get.getResponseBodyAsString();
|
String response = get.getResponseBodyAsString();
|
||||||
|
Log.d(TAG, "Successful response: " + response);
|
||||||
Log.d(TAG, "GET RESPONSE.................... " + response);
|
|
||||||
|
|
||||||
// Parse the response
|
// Parse the response
|
||||||
JSONObject respJSON = new JSONObject(response);
|
JSONObject respJSON = new JSONObject(response);
|
||||||
@ -98,21 +100,25 @@ public class GetUserNameRemoteOperation extends RemoteOperation {
|
|||||||
String email = respData.getString(NODE_EMAIL);
|
String email = respData.getString(NODE_EMAIL);
|
||||||
|
|
||||||
// Result
|
// Result
|
||||||
result = new RemoteOperationResult(isSuccess(status), status, (get != null ? get.getResponseHeaders() : null));
|
result = new RemoteOperationResult(true, status, get.getResponseHeaders());
|
||||||
mUserName = displayName;
|
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);
|
result = new RemoteOperationResult(e);
|
||||||
e.printStackTrace();
|
Log.e(TAG, "Exception while getting OC user information", e);
|
||||||
} catch (IOException e) {
|
|
||||||
result = new RemoteOperationResult(e);
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (JSONException e) {
|
|
||||||
result = new RemoteOperationResult(e);
|
|
||||||
e.printStackTrace();
|
|
||||||
} finally {
|
} finally {
|
||||||
get.releaseConnection();
|
get.releaseConnection();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user