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:
parent
d593474113
commit
ca2eff6647
@ -1 +1 @@
|
|||||||
Subproject commit c73ea80bcbd6fd75379f88f497668eb9412d5490
|
Subproject commit 9b39bb9d05bf27510ceeee105fb6edc2068fe8e2
|
@ -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/>
|
|
@ -24,8 +24,8 @@
|
|||||||
-->
|
-->
|
||||||
|
|
||||||
<resources>
|
<resources>
|
||||||
<string name="server_base_url"></string>
|
<string name="server_base_url">http://docker.oc.solidgear.es:11917/</string>
|
||||||
<string name="username"></string>
|
<string name="username">admin</string>
|
||||||
<string name="password"></string>
|
<string name="password">Password</string>
|
||||||
<string name ="user_agent">Mozilla/5.0 (Android) ownCloud sample </string>
|
<string name ="user_agent">Mozilla/5.0 (Android) ownCloud sample </string>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -84,21 +84,14 @@ public class MainActivity extends Activity implements OnRemoteOperationListener,
|
|||||||
|
|
||||||
mHandler = new Handler();
|
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 = OwnCloudClientFactory.createOwnCloudClient(serverUri, this, true);
|
||||||
// mClient.setCredentials(
|
|
||||||
// OwnCloudCredentialsFactory.newBasicCredentials(
|
|
||||||
// getString(R.string.username),
|
|
||||||
// getString(R.string.password)
|
|
||||||
// )
|
|
||||||
// );
|
|
||||||
|
|
||||||
OCAccount ocAccount = new OCAccount(serverUri,
|
OCAccount ocAccount = new OCAccount(serverUri,
|
||||||
OwnCloudCredentialsFactory.newBasicCredentials(
|
OwnCloudCredentialsFactory.newBasicCredentials(
|
||||||
getString(R.string.username),
|
getString(R.string.username),
|
||||||
getString(R.string.password)
|
getString(R.string.password)));
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
mOCContext = new OCContext(ocAccount);
|
mOCContext = new OCContext(ocAccount);
|
||||||
|
|
||||||
@ -164,9 +157,9 @@ public class MainActivity extends Activity implements OnRemoteOperationListener,
|
|||||||
|
|
||||||
private void startRefresh() {
|
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);
|
// ReadRemoteFolderOperation refreshOperation = new ReadRemoteFolderOperation(FileUtils.PATH_SEPARATOR);
|
||||||
// refreshOperation.execute(mClient, this, mHandler);
|
// refreshOperation.execute(mClient, this, mHandler);
|
||||||
}
|
}
|
||||||
|
@ -1,21 +1,25 @@
|
|||||||
package com.owncloud.android.lib.refactor;
|
package com.owncloud.android.lib.refactor;
|
||||||
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import okhttp3.HttpUrl;
|
||||||
|
import okhttp3.Interceptor;
|
||||||
import okhttp3.OkHttpClient;
|
import okhttp3.OkHttpClient;
|
||||||
import okhttp3.Request;
|
import okhttp3.Request;
|
||||||
|
import okhttp3.Response;
|
||||||
|
|
||||||
public abstract class RemoteOperation {
|
public abstract class RemoteOperation {
|
||||||
private final OCContext mContext;
|
private final OCContext mContext;
|
||||||
private static OkHttpClient httpClient = null;
|
|
||||||
private static final String WEBDAV_PATH_4_0 = "/remote.php/dav";
|
private static final String WEBDAV_PATH_4_0 = "/remote.php/dav";
|
||||||
|
private static OkHttpClient mClient = null;
|
||||||
|
|
||||||
protected RemoteOperation(OCContext context) {
|
protected RemoteOperation(OCContext context) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
|
if(mClient == null) {
|
||||||
if(httpClient == null) {
|
mClient = new OkHttpClient.Builder()
|
||||||
httpClient = new OkHttpClient.Builder()
|
|
||||||
.followRedirects(false)
|
.followRedirects(false)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
@ -28,19 +32,46 @@ public abstract class RemoteOperation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected OkHttpClient getClient() {
|
protected OkHttpClient getClient() {
|
||||||
return httpClient;
|
return mClient.newBuilder()
|
||||||
|
.addInterceptor(chain ->
|
||||||
|
chain.proceed(
|
||||||
|
addRequestCredentials(
|
||||||
|
chain.request())
|
||||||
|
.build()))
|
||||||
|
.followRedirects(false)
|
||||||
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Uri.Builder getBaseUriBuilder() {
|
protected Uri.Builder getBaseUriBuilder() {
|
||||||
return mContext.getOCAccount().getBaseUri().buildUpon();
|
return mContext.getOCAccount().getBaseUri().buildUpon();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Uri.Builder getWebDAVUriBuilder() {
|
protected Uri getWebDavUrl() {
|
||||||
return getBaseUriBuilder().appendEncodedPath(WEBDAV_PATH_4_0);
|
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() {
|
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
|
for(Map.Entry<String, String> header
|
||||||
: mContext.getOCAccount()
|
: mContext.getOCAccount()
|
||||||
@ -55,7 +86,8 @@ public abstract class RemoteOperation {
|
|||||||
.getOCAccount()
|
.getOCAccount()
|
||||||
.getCredentials()
|
.getCredentials()
|
||||||
.getCredentialCookie();
|
.getCredentialCookie();
|
||||||
if(credentialCookie == null) {
|
if(credentialCookie != null) {
|
||||||
|
System.err.println(credentialCookie);
|
||||||
builder.addHeader("Cookie", credentialCookie);
|
builder.addHeader("Cookie", credentialCookie);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,7 +91,11 @@ public class OCAccount {
|
|||||||
}
|
}
|
||||||
mSavedAccount = null;
|
mSavedAccount = null;
|
||||||
mSavedAccountName = 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
|
mCredentials = credentials != null
|
||||||
? credentials
|
? credentials
|
||||||
: new OCAnonymousCredentials();
|
: 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.RemoteOperation;
|
||||||
import com.owncloud.android.lib.refactor.RemoteOperationResult;
|
import com.owncloud.android.lib.refactor.RemoteOperationResult;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import at.bitfire.dav4android.Constants;
|
||||||
import at.bitfire.dav4android.DavResource;
|
import at.bitfire.dav4android.DavResource;
|
||||||
import at.bitfire.dav4android.exception.DavException;
|
import at.bitfire.dav4android.exception.DavException;
|
||||||
import at.bitfire.dav4android.exception.HttpException;
|
import at.bitfire.dav4android.exception.HttpException;
|
||||||
import at.bitfire.dav4android.property.DisplayName;
|
import at.bitfire.dav4android.property.DisplayName;
|
||||||
import okhttp3.HttpUrl;
|
import okhttp3.HttpUrl;
|
||||||
|
import okhttp3.OkHttpClient;
|
||||||
|
|
||||||
public class PropfindOperation extends RemoteOperation {
|
public class PropfindOperation extends RemoteOperation {
|
||||||
|
|
||||||
@ -24,23 +27,17 @@ public class PropfindOperation extends RemoteOperation {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RemoteOperationResult exec() {
|
public RemoteOperationResult exec() {
|
||||||
DavResource davResource = new DavResource(
|
|
||||||
getClient(),
|
|
||||||
HttpUrl.parse(getWebDAVUriBuilder() + WebdavUtils.encodePath(mRemotePath)),
|
|
||||||
null);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
davResource.propfind(1, DisplayName.NAME);
|
HttpUrl location = HttpUrl.parse(getBaseUriBuilder().build().toString());
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
DavResource davResource = new DavResource(getClient(), getWebDavHttpUrl("/"));
|
||||||
} catch (HttpException e) {
|
davResource.propfind(0, DisplayName.NAME);
|
||||||
e.printStackTrace();
|
|
||||||
} catch (DavException e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
davResource.getProperties();
|
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user