1
0
mirror of https://github.com/owncloud/android-library.git synced 2025-06-08 00:16:09 +00:00

make propfind operation run without errors

This commit is contained in:
DerSchabi 2018-05-22 09:36:30 +02:00 committed by davigonz
parent d593474113
commit ca2eff6647
7 changed files with 64 additions and 64 deletions

@ -1 +1 @@
Subproject commit c73ea80bcbd6fd75379f88f497668eb9412d5490
Subproject commit 9b39bb9d05bf27510ceeee105fb6edc2068fe8e2

View File

@ -1,26 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- ownCloud Android Library is available under MIT license
Copyright (C) 2016 ownCloud GmbH.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->
<resources/>

View File

@ -24,8 +24,8 @@
-->
<resources>
<string name="server_base_url"></string>
<string name="username"></string>
<string name="password"></string>
<string name="server_base_url">http://docker.oc.solidgear.es:11917/</string>
<string name="username">admin</string>
<string name="password">Password</string>
<string name ="user_agent">Mozilla/5.0 (Android) ownCloud sample </string>
</resources>

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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();

View File

@ -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;
}
}