diff --git a/dav4android b/dav4android
index c73ea80b..9b39bb9d 160000
--- a/dav4android
+++ b/dav4android
@@ -1 +1 @@
-Subproject commit c73ea80bcbd6fd75379f88f497668eb9412d5490
+Subproject commit 9b39bb9d05bf27510ceeee105fb6edc2068fe8e2
diff --git a/res/values/empty.xml b/res/values/empty.xml
deleted file mode 100644
index e999cb06..00000000
--- a/res/values/empty.xml
+++ /dev/null
@@ -1,26 +0,0 @@
-
-
-
-
diff --git a/sample_client/res/values/setup.xml b/sample_client/res/values/setup.xml
index b6662b75..02fdda52 100644
--- a/sample_client/res/values/setup.xml
+++ b/sample_client/res/values/setup.xml
@@ -24,8 +24,8 @@
-->
-
-
-
+ http://docker.oc.solidgear.es:11917/
+ admin
+ Password
Mozilla/5.0 (Android) ownCloud sample
diff --git a/sample_client/src/com/owncloud/android/lib/sampleclient/MainActivity.java b/sample_client/src/com/owncloud/android/lib/sampleclient/MainActivity.java
index d63484d1..81777161 100644
--- a/sample_client/src/com/owncloud/android/lib/sampleclient/MainActivity.java
+++ b/sample_client/src/com/owncloud/android/lib/sampleclient/MainActivity.java
@@ -84,21 +84,14 @@ public class MainActivity extends Activity implements OnRemoteOperationListener,
mHandler = new Handler();
- Uri serverUri = Uri.parse(getString(R.string.server_base_url));
+ final Uri serverUri = Uri.parse(getString(R.string.server_base_url));
mClient = OwnCloudClientFactory.createOwnCloudClient(serverUri, this, true);
-// mClient.setCredentials(
-// OwnCloudCredentialsFactory.newBasicCredentials(
-// getString(R.string.username),
-// getString(R.string.password)
-// )
-// );
+
OCAccount ocAccount = new OCAccount(serverUri,
OwnCloudCredentialsFactory.newBasicCredentials(
getString(R.string.username),
- getString(R.string.password)
- )
- );
+ getString(R.string.password)));
mOCContext = new OCContext(ocAccount);
@@ -164,9 +157,9 @@ public class MainActivity extends Activity implements OnRemoteOperationListener,
private void startRefresh() {
- PropfindOperation propfindOperation = new PropfindOperation(mOCContext, FileUtils.PATH_SEPARATOR);
+ final PropfindOperation propfindOperation = new PropfindOperation(mOCContext, FileUtils.PATH_SEPARATOR);
- propfindOperation.exec();
+ Thread tread = new Thread(() -> propfindOperation.exec());
// ReadRemoteFolderOperation refreshOperation = new ReadRemoteFolderOperation(FileUtils.PATH_SEPARATOR);
// refreshOperation.execute(mClient, this, mHandler);
}
diff --git a/src/com/owncloud/android/lib/refactor/RemoteOperation.java b/src/com/owncloud/android/lib/refactor/RemoteOperation.java
index d72b1682..cb53b6e2 100644
--- a/src/com/owncloud/android/lib/refactor/RemoteOperation.java
+++ b/src/com/owncloud/android/lib/refactor/RemoteOperation.java
@@ -1,21 +1,25 @@
package com.owncloud.android.lib.refactor;
import android.net.Uri;
+
+import java.io.IOException;
import java.util.Map;
+import okhttp3.HttpUrl;
+import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.Request;
+import okhttp3.Response;
public abstract class RemoteOperation {
private final OCContext mContext;
- private static OkHttpClient httpClient = null;
private static final String WEBDAV_PATH_4_0 = "/remote.php/dav";
+ private static OkHttpClient mClient = null;
protected RemoteOperation(OCContext context) {
mContext = context;
-
- if(httpClient == null) {
- httpClient = new OkHttpClient.Builder()
+ if(mClient == null) {
+ mClient = new OkHttpClient.Builder()
.followRedirects(false)
.build();
}
@@ -28,19 +32,46 @@ public abstract class RemoteOperation {
}
protected OkHttpClient getClient() {
- return httpClient;
+ return mClient.newBuilder()
+ .addInterceptor(chain ->
+ chain.proceed(
+ addRequestCredentials(
+ chain.request())
+ .build()))
+ .followRedirects(false)
+ .build();
}
protected Uri.Builder getBaseUriBuilder() {
return mContext.getOCAccount().getBaseUri().buildUpon();
}
- protected Uri.Builder getWebDAVUriBuilder() {
- return getBaseUriBuilder().appendEncodedPath(WEBDAV_PATH_4_0);
+ protected Uri getWebDavUrl() {
+ return getBaseUriBuilder().appendEncodedPath(WEBDAV_PATH_4_0).build();
+ }
+
+ protected Uri getWebDavUri(String resourcePath) {
+ return getBaseUriBuilder()
+ .appendEncodedPath(WEBDAV_PATH_4_0)
+ .appendEncodedPath(resourcePath)
+ .build();
+ }
+
+ protected HttpUrl getWebDavHttpUrl(String resourcePath) {
+ return HttpUrl.parse(
+ getBaseUriBuilder()
+ .appendEncodedPath(WEBDAV_PATH_4_0)
+ .appendEncodedPath(resourcePath)
+ .build()
+ .toString());
}
protected Request.Builder getRequestBuilder() {
- Request.Builder builder = new Request.Builder();
+ return new Request.Builder();
+ }
+
+ private Request.Builder addRequestCredentials(Request request) {
+ Request.Builder builder = request.newBuilder();
for(Map.Entry header
: mContext.getOCAccount()
@@ -55,7 +86,8 @@ public abstract class RemoteOperation {
.getOCAccount()
.getCredentials()
.getCredentialCookie();
- if(credentialCookie == null) {
+ if(credentialCookie != null) {
+ System.err.println(credentialCookie);
builder.addHeader("Cookie", credentialCookie);
}
diff --git a/src/com/owncloud/android/lib/refactor/account/OCAccount.java b/src/com/owncloud/android/lib/refactor/account/OCAccount.java
index ab9c2618..007722ec 100644
--- a/src/com/owncloud/android/lib/refactor/account/OCAccount.java
+++ b/src/com/owncloud/android/lib/refactor/account/OCAccount.java
@@ -91,7 +91,11 @@ public class OCAccount {
}
mSavedAccount = null;
mSavedAccountName = null;
- mBaseUri = baseUri;
+ if(baseUri != null && !baseUri.equals("")) {
+ mBaseUri = baseUri;
+ } else {
+ throw new IllegalArgumentException("baseUri can not be null or empty");
+ }
mCredentials = credentials != null
? credentials
: new OCAnonymousCredentials();
diff --git a/src/com/owncloud/android/lib/refactor/operations/PropfindOperation.java b/src/com/owncloud/android/lib/refactor/operations/PropfindOperation.java
index 12de7e93..b245e2d1 100644
--- a/src/com/owncloud/android/lib/refactor/operations/PropfindOperation.java
+++ b/src/com/owncloud/android/lib/refactor/operations/PropfindOperation.java
@@ -5,12 +5,15 @@ import com.owncloud.android.lib.common.network.WebdavUtils;
import com.owncloud.android.lib.refactor.RemoteOperation;
import com.owncloud.android.lib.refactor.RemoteOperationResult;
import java.io.IOException;
+import java.util.logging.Logger;
+import at.bitfire.dav4android.Constants;
import at.bitfire.dav4android.DavResource;
import at.bitfire.dav4android.exception.DavException;
import at.bitfire.dav4android.exception.HttpException;
import at.bitfire.dav4android.property.DisplayName;
import okhttp3.HttpUrl;
+import okhttp3.OkHttpClient;
public class PropfindOperation extends RemoteOperation {
@@ -24,23 +27,17 @@ public class PropfindOperation extends RemoteOperation {
@Override
public RemoteOperationResult exec() {
- DavResource davResource = new DavResource(
- getClient(),
- HttpUrl.parse(getWebDAVUriBuilder() + WebdavUtils.encodePath(mRemotePath)),
- null);
try {
- davResource.propfind(1, DisplayName.NAME);
- } catch (IOException e) {
- e.printStackTrace();
- } catch (HttpException e) {
- e.printStackTrace();
- } catch (DavException e) {
+ HttpUrl location = HttpUrl.parse(getBaseUriBuilder().build().toString());
+
+ DavResource davResource = new DavResource(getClient(), getWebDavHttpUrl("/"));
+ davResource.propfind(0, DisplayName.NAME);
+
+ } catch (Exception e) {
e.printStackTrace();
}
- davResource.getProperties();
-
return null;
}
}
\ No newline at end of file