2424
2525package 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-
3627import android .content .Context ;
3728import android .net .ConnectivityManager ;
3829import android .net .Uri ;
4435import com .owncloud .android .lib .common .operations .RemoteOperationResult ;
4536import 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-
5553public 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 }
0 commit comments