X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/d8e29ce30632d71d560fe7640307c37fb0699be6..6a9eaaf9aa6ce01ed788d057c56face20fa88dc3:/src/eu/alefzero/webdav/WebdavClient.java diff --git a/src/eu/alefzero/webdav/WebdavClient.java b/src/eu/alefzero/webdav/WebdavClient.java index 503685a1..1135dafa 100644 --- a/src/eu/alefzero/webdav/WebdavClient.java +++ b/src/eu/alefzero/webdav/WebdavClient.java @@ -142,12 +142,8 @@ public class WebdavClient extends HttpClient { */ public boolean downloadFile(String remoteFilepath, File targetFile) { boolean ret = false; - boolean caughtException = false; GetMethod get = new GetMethod(mUri.toString() + WebdavUtils.encodePath(remoteFilepath)); - // get.setHeader("Host", mUri.getHost()); - // get.setHeader("User-Agent", "Android-ownCloud"); - int status = -1; try { status = executeMethod(get); @@ -169,19 +165,16 @@ public class WebdavClient extends HttpClient { } catch (HttpException e) { Log.e(TAG, "HTTP exception downloading " + remoteFilepath, e); - caughtException = true; } catch (IOException e) { Log.e(TAG, "I/O exception downloading " + remoteFilepath, e); - caughtException = true; } catch (Exception e) { Log.e(TAG, "Unexpected exception downloading " + remoteFilepath, e); - caughtException = true; } finally { if (!ret) { - if (!caughtException) { + if (status >= 0) { Log.e(TAG, "Download of " + remoteFilepath + " to " + targetFile + " failed with HTTP status " + status); } if (targetFile.exists()) { @@ -221,32 +214,34 @@ public class WebdavClient extends HttpClient { * @param contentType MIME type of the file. * @return 'True' then the upload was successfully completed */ - public boolean putFile(String localFile, String remoteTarget, - String contentType) { + public boolean putFile(String localFile, String remoteTarget, String contentType) { boolean result = false; + int status = -1; try { - Log.e("ASD", contentType + ""); File f = new File(localFile); FileRequestEntity entity = new FileRequestEntity(f, contentType); entity.setOnDatatransferProgressListener(mDataTransferListener); - Log.e("ASD", f.exists() + " " + entity.getContentLength()); PutMethod put = new PutMethod(mUri.toString() + WebdavUtils.encodePath(remoteTarget)); put.setRequestEntity(entity); - Log.d(TAG, "" + put.getURI().toString()); - int status = executeMethod(put, 0); - Log.d(TAG, "PUT method return with status " + status); - - if (status == HttpStatus.SC_OK || status == HttpStatus.SC_CREATED || status == HttpStatus.SC_NO_CONTENT) { - result = true; - Log.i(TAG, "Uploading, done"); - } + status = executeMethod(put); - } catch (final Exception e) { - Log.i(TAG, "" + e.getMessage()); - result = false; - } + result = (status == HttpStatus.SC_OK || status == HttpStatus.SC_CREATED || status == HttpStatus.SC_NO_CONTENT); + + Log.d(TAG, "PUT response for " + remoteTarget + " finished with HTTP status " + status); + + } catch (HttpException e) { + Log.e(TAG, "HTTP exception uploading " + localFile + " to " + remoteTarget, e); + + } catch (IOException e) { + Log.e(TAG, "I/O exception uploading " + localFile + " to " + remoteTarget, e); + } catch (Exception e) { + Log.e(TAG, "Unexpected exception uploading " + localFile + " to " + remoteTarget, e); + } + + if (!result && status >= 0) Log.e(TAG, "Upload of " + localFile + " to " + remoteTarget + " FAILED with HTTP status " + status); + return result; } @@ -281,17 +276,29 @@ public class WebdavClient extends HttpClient { * @return 'True' when the directory is successfully created */ public boolean createDirectory(String path) { + boolean result = false; + int status = -1; try { MkColMethod mkcol = new MkColMethod(mUri.toString() + WebdavUtils.encodePath(path)); - int status = executeMethod(mkcol); - Log.d(TAG, "Status returned " + status); - Log.d(TAG, "uri: " + mkcol.getURI().toString()); - Log.i(TAG, "Creating dir completed"); - } catch (final Exception e) { - e.printStackTrace(); - return false; + Log.d(TAG, "Creating directory " + path); + status = executeMethod(mkcol); + Log.d(TAG, "Status returned: " + status); + result = mkcol.succeeded(); + + } catch (HttpException e) { + Log.e(TAG, "HTTP exception creating directory " + path, e); + + } catch (IOException e) { + Log.e(TAG, "I/O exception creating directory " + path, e); + + } catch (Exception e) { + Log.e(TAG, "Unexpected exception creating directory " + path, e); + } - return true; + if (!result && status >= 0) { + Log.e(TAG, "Creation of directory " + path + " failed with HTTP status " + status); + } + return result; }