mirror of
https://github.com/owncloud/android-library.git
synced 2026-08-12 00:42:58 +00:00
make propfind operation run without errors
This commit is contained in:
@@ -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<String, String> 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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user