Skip to content

Commit efbbb16

Browse files
Merge pull request #21 from nextcloud/userInfoRouteUpdate
Fix user info route
2 parents 11695f0 + 380bf75 commit efbbb16

File tree

2 files changed

+26
-28
lines changed

2 files changed

+26
-28
lines changed

src/com/owncloud/android/lib/resources/status/GetRemoteStatusOperation.java

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,6 @@
2424

2525
package com.owncloud.android.lib.resources.status;
2626

27-
import java.util.ArrayList;
28-
29-
import org.apache.commons.httpclient.HttpStatus;
30-
import org.apache.commons.httpclient.methods.GetMethod;
31-
import org.apache.commons.httpclient.params.HttpMethodParams;
32-
import org.apache.commons.httpclient.params.HttpParams;
33-
import org.json.JSONException;
34-
import org.json.JSONObject;
35-
3627
import android.content.Context;
3728
import android.net.ConnectivityManager;
3829
import android.net.Uri;
@@ -44,27 +35,35 @@
4435
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
4536
import com.owncloud.android.lib.common.utils.Log_OC;
4637

38+
import org.apache.commons.httpclient.HttpStatus;
39+
import org.apache.commons.httpclient.methods.GetMethod;
40+
import org.apache.commons.httpclient.params.HttpMethodParams;
41+
import org.apache.commons.httpclient.params.HttpParams;
42+
import org.json.JSONException;
43+
import org.json.JSONObject;
44+
45+
import java.util.ArrayList;
46+
4747
/**
4848
* Checks if the server is valid and if the server supports the Share API
4949
*
5050
* @author David A. Velasco
5151
* @author masensio
52-
*
5352
*/
54-
5553
public class GetRemoteStatusOperation extends RemoteOperation {
5654

5755
/**
58-
* Maximum time to wait for a response from the server when the connection is being tested,
59-
* in MILLISECONDs.
56+
* Maximum time to wait for a response from the server when the connection is being tested, in MILLISECONDs.
6057
*/
61-
public static final int TRY_CONNECTION_TIMEOUT = 5000;
62-
58+
private static final int TRY_CONNECTION_TIMEOUT = 5000;
59+
6360
private static final String TAG = GetRemoteStatusOperation.class.getSimpleName();
6461

6562
private static final String NODE_INSTALLED = "installed";
6663
private static final String NODE_VERSION = "version";
67-
64+
private static final String PROTOCOL_HTTPS = "https://";
65+
private static final String PROTOCOL_HTTP = "http://";
66+
6867
private RemoteOperationResult mLatestResult;
6968
private Context mContext;
7069

@@ -79,9 +78,8 @@ private boolean tryConnection(OwnCloudClient client) {
7978
try {
8079
get = new GetMethod(baseUrlSt + AccountUtils.STATUS_PATH);
8180

82-
HttpParams params = get.getParams().getDefaultParams();
83-
params.setParameter(HttpMethodParams.USER_AGENT,
84-
OwnCloudClientManagerFactory.getUserAgent());
81+
HttpParams params = HttpMethodParams.getDefaultParams();
82+
params.setParameter(HttpMethodParams.USER_AGENT, OwnCloudClientManagerFactory.getUserAgent());
8583
get.getParams().setDefaults(params);
8684

8785
client.setFollowRedirects(false);
@@ -98,8 +96,8 @@ private boolean tryConnection(OwnCloudClient client) {
9896
&& !mLatestResult.isSuccess()) {
9997

10098
isRedirectToNonSecureConnection |= (
101-
baseUrlSt.startsWith("https://") &&
102-
redirectedLocation.startsWith("http://")
99+
baseUrlSt.startsWith(PROTOCOL_HTTPS) &&
100+
redirectedLocation.startsWith(PROTOCOL_HTTP)
103101
);
104102
get.releaseConnection();
105103
get = new GetMethod(redirectedLocation);
@@ -134,13 +132,13 @@ private boolean tryConnection(OwnCloudClient client) {
134132
);
135133
} else {
136134
mLatestResult = new RemoteOperationResult(
137-
baseUrlSt.startsWith("https://") ?
135+
baseUrlSt.startsWith(PROTOCOL_HTTPS) ?
138136
RemoteOperationResult.ResultCode.OK_SSL :
139137
RemoteOperationResult.ResultCode.OK_NO_SSL
140138
);
141139
}
142140

143-
ArrayList<Object> data = new ArrayList<Object>();
141+
ArrayList<Object> data = new ArrayList<>();
144142
data.add(ocVersion);
145143
mLatestResult.setData(data);
146144
retval = true;
@@ -190,15 +188,15 @@ protected RemoteOperationResult run(OwnCloudClient client) {
190188
return new RemoteOperationResult(RemoteOperationResult.ResultCode.NO_NETWORK_CONNECTION);
191189
}
192190
String baseUriStr = client.getBaseUri().toString();
193-
if (baseUriStr.startsWith("http://") || baseUriStr.startsWith("https://")) {
191+
if (baseUriStr.startsWith(PROTOCOL_HTTP) || baseUriStr.startsWith(PROTOCOL_HTTPS)) {
194192
tryConnection(client);
195193

196194
} else {
197-
client.setBaseUri(Uri.parse("https://" + baseUriStr));
195+
client.setBaseUri(Uri.parse(PROTOCOL_HTTPS + baseUriStr));
198196
boolean httpsSuccess = tryConnection(client);
199197
if (!httpsSuccess && !mLatestResult.isSslRecoverableException()) {
200198
Log_OC.d(TAG, "establishing secure connection failed, trying non secure connection");
201-
client.setBaseUri(Uri.parse("http://" + baseUriStr));
199+
client.setBaseUri(Uri.parse(PROTOCOL_HTTP + baseUriStr));
202200
tryConnection(client);
203201
}
204202
}

src/com/owncloud/android/lib/resources/users/GetRemoteUserInfoOperation.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public class GetRemoteUserInfoOperation extends RemoteOperation {
4646
private static final String TAG = GetRemoteUserInfoOperation.class.getSimpleName();
4747

4848
// OCS Route
49-
private static final String OCS_ROUTE = "/index.php/ocs/cloud/user?format=json";
49+
private static final String OCS_ROUTE = "/ocs/v1.php/cloud/user?format=json";
5050

5151
// JSON Node names
5252
private static final String NODE_OCS = "ocs";
@@ -86,7 +86,7 @@ protected RemoteOperationResult run(OwnCloudClient client) {
8686
// Result
8787
result = new RemoteOperationResult(true, status, get.getResponseHeaders());
8888
// Username in result.data
89-
ArrayList<Object> data = new ArrayList<Object>();
89+
ArrayList<Object> data = new ArrayList<>();
9090
data.add(userInfo);
9191
result.setData(data);
9292
} else {

0 commit comments

Comments
 (0)