- return 5 * 1000;\r
- }\r
- };\r
- }\r
- \r
- protected HttpPropFind getPropFindQuery() throws OperationCanceledException, AuthenticatorException, IOException {\r
- HttpPropFind query = new HttpPropFind(getUri().toString());\r
- query.setHeader("Content-type", "text/xml");\r
- query.setHeader("User-Agent", "Android-ownCloud");\r
- return query;\r
- }\r
- \r
- protected HttpResponse fireRawRequest(HttpRequest query) throws ClientProtocolException, OperationCanceledException, AuthenticatorException, IOException {\r
- BasicHttpContext httpContext = new BasicHttpContext();\r
- BasicScheme basicAuth = new BasicScheme();\r
- httpContext.setAttribute("preemptive-auth", basicAuth);\r
- \r
- HttpResponse response = getClient().execute(this.host, query, httpContext);\r
- return response;\r
- }\r
- \r
- protected TreeNode fireRequest(HttpRequest query) throws ClientProtocolException, OperationCanceledException, AuthenticatorException, IOException {\r
- HttpResponse response = fireRawRequest(query);\r
- \r
- TreeNode root = new TreeNode();\r
- root.setProperty(TreeNode.NodeProperty.NAME, "/");\r
- this.parseResponse(response, getUri(), getClient(), this.host, root.getChildList());\r
- return root;\r
- }\r
- \r
- protected Uri getUri() {\r
- return Uri.parse(this.getAccountManager().getUserData(getAccount(), AccountAuthenticator.KEY_OC_URL));\r
- }\r
- \r
- private DefaultHttpClient getClient() throws OperationCanceledException, AuthenticatorException, IOException {\r
- if(this.client == null) {\r
- String username = getAccount().name.split("@")[0];\r
- String password = this.getAccountManager().blockingGetAuthToken(getAccount(), AccountAuthenticator.AUTH_TOKEN_TYPE, true);\r
- if (this.getAccountManager().getUserData(getAccount(), AccountAuthenticator.KEY_OC_URL) == null) {\r
- throw new UnknownHostException();\r
- }\r
- Uri uri = getUri();\r
- \r
- int port = (uri.getPort() == -1) ? 80 : uri.getPort();\r
- this.client = new DefaultHttpClient();\r
- this.client.getCredentialsProvider().setCredentials(\r
- new AuthScope(uri.getHost(), port),\r
- new UsernamePasswordCredentials(username, password)\r
- );\r
- this.client.setKeepAliveStrategy(this.getKeepAliveStrategy());\r
- this.host = new HttpHost(uri.getHost(), port, (uri.getScheme() == "https") ? "https" : "http");\r
- }\r
- \r
- return this.client;\r
- }\r
- \r
- private void parseResponse(HttpResponse resp, Uri uri, DefaultHttpClient client, HttpHost targetHost, LinkedList<TreeNode> insertList) throws IOException, OperationCanceledException, AuthenticatorException {\r
- boolean skipFirst = true;\r
+ int statusCode = response.getStatusLine().getStatusCode();\r
+ \r
+ // HTTP 400, 500 Errors as well as HTTP 118 - Connection timed out\r
+ if((statusCode >= 400 && statusCode <= 418) || \r
+ (statusCode >= 421 && statusCode <= 426) ||\r
+ (statusCode >= 500 && statusCode <= 510 ) ||\r
+ statusCode == 118) {\r
+ return 0;\r
+ }\r
+
+ return 5 * 1000;
+ }
+ };
+ }
+
+ protected HttpPropFind getPropFindQuery() throws OperationCanceledException, AuthenticatorException, IOException {
+ HttpPropFind query = new HttpPropFind(getUri().toString());
+ query.setHeader("Content-type", "text/xml");
+ query.setHeader("User-Agent", "Android-ownCloud");
+ return query;
+ }
+
+ protected HttpResponse fireRawRequest(HttpRequest query) throws ClientProtocolException, OperationCanceledException, AuthenticatorException, IOException {
+ BasicHttpContext httpContext = new BasicHttpContext();
+ BasicScheme basicAuth = new BasicScheme();
+ httpContext.setAttribute("preemptive-auth", basicAuth);
+
+ HttpResponse response = getClient().execute(mHost, query, httpContext);
+ return response;
+ }
+
+ protected TreeNode fireRequest(HttpRequest query) throws ClientProtocolException, OperationCanceledException, AuthenticatorException, IOException {
+ HttpResponse response = fireRawRequest(query);
+
+ TreeNode root = new TreeNode();
+ root.setProperty(TreeNode.NodeProperty.NAME, "");
+ this.parseResponse(response, getUri(), getClient(), mHost, root.getChildList(), false, 0);
+ return root;
+ }
+
+ protected Uri getUri() {
+ return Uri.parse(this.getAccountManager().getUserData(getAccount(), AccountAuthenticator.KEY_OC_URL));
+ }
+
+ private DefaultHttpClient getClient() throws OperationCanceledException, AuthenticatorException, IOException {
+ if(mClient == null) {
+ String username = getAccount().name.split("@")[0];
+ String password = this.getAccountManager().blockingGetAuthToken(getAccount(), AccountAuthenticator.AUTH_TOKEN_TYPE, true);
+ if (this.getAccountManager().getUserData(getAccount(), AccountAuthenticator.KEY_OC_URL) == null) {
+ throw new UnknownHostException();
+ }
+ Uri uri = getUri();
+
+ mClient = new WebdavClient(uri);
+ mClient.setCredentials(username, password);
+ mClient.allowUnsignedCertificates();
+ mHost = mClient.getTargetHost();
+ }
+
+ return mClient.getHttpClient();
+ }
+
+ private void parseResponse(HttpResponse resp, Uri uri, DefaultHttpClient client, HttpHost targetHost, LinkedList<TreeNode> insertList, boolean sf, long parent_id) throws IOException, OperationCanceledException, AuthenticatorException {
+ boolean skipFirst = sf, override_parent = !sf;