import java.io.File;\r
import java.io.FileOutputStream;\r
import java.io.IOException;\r
-import java.util.HashMap;\r
\r
import org.apache.commons.httpclient.Credentials;\r
import org.apache.commons.httpclient.HttpClient;\r
+import org.apache.commons.httpclient.HttpConnectionManager;\r
+import org.apache.commons.httpclient.HttpVersion;\r
+import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;\r
import org.apache.commons.httpclient.UsernamePasswordCredentials;\r
import org.apache.commons.httpclient.auth.AuthScope;\r
import org.apache.commons.httpclient.methods.GetMethod;\r
import org.apache.commons.httpclient.params.HttpMethodParams;\r
import org.apache.commons.httpclient.protocol.Protocol;\r
import org.apache.http.HttpStatus;\r
+import org.apache.http.params.CoreProtocolPNames;\r
import org.apache.jackrabbit.webdav.client.methods.DavMethod;\r
import org.apache.jackrabbit.webdav.client.methods.DeleteMethod;\r
import org.apache.jackrabbit.webdav.client.methods.MkColMethod;\r
final private static String TAG = "WebdavClient";\r
private static final String USER_AGENT = "Android-ownCloud";\r
private OnDatatransferProgressListener mDataTransferListener;\r
- private static HashMap<String, WebdavClient> clients = new HashMap<String, WebdavClient>();\r
+ static private MultiThreadedHttpConnectionManager mConnManager = null;\r
+ \r
+ static public MultiThreadedHttpConnectionManager getMultiThreadedConnManager() {\r
+ if (mConnManager == null) {\r
+ mConnManager = new MultiThreadedHttpConnectionManager();\r
+ mConnManager.setMaxConnectionsPerHost(5);\r
+ mConnManager.setMaxTotalConnections(5);\r
+ }\r
+ return mConnManager;\r
+ }\r
\r
/**\r
* Creates a WebdavClient setup for the current account\r
* @param context The application context\r
* @return\r
*/\r
- public WebdavClient (Account account, Context context){\r
+ public WebdavClient (Account account, Context context) {\r
OwnCloudVersion ownCloudVersion = new OwnCloudVersion(AccountManager.get(context).getUserData(account,\r
AccountAuthenticator.KEY_OC_VERSION));\r
String baseUrl = AccountManager.get(context).getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL);\r
String password = AccountManager.get(context).getPassword(account);\r
\r
mUri = Uri.parse(baseUrl + webDavPath);\r
- getParams().setParameter(HttpMethodParams.USER_AGENT, USER_AGENT);\r
+\r
setCredentials(username, password);\r
- allowSelfsignedCertificates();\r
}\r
\r
- public WebdavClient(){}\r
+ public WebdavClient() {\r
+ super(getMultiThreadedConnManager());\r
+ \r
+ getParams().setParameter(HttpMethodParams.USER_AGENT, USER_AGENT);\r
+ getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);\r
+ allowSelfsignedCertificates();\r
+ }\r
\r
public void setCredentials(String username, String password) {\r
- getParams().setAuthenticationPreemptive(true);\r
+ //getParams().setAuthenticationPreemptive(true);\r
getState().setCredentials(AuthScope.ANY,\r
getCredentials(username, password));\r
}\r
}\r
\r
public boolean downloadFile(String remoteFilepath, File targetPath) {\r
+ boolean ret = false;\r
GetMethod get = new GetMethod(mUri.toString() + remoteFilepath);\r
HttpMethodParams params = get.getParams();\r
params.setSoTimeout(0); // that means "infinite timeout"; it's the default value, but let's make it explicit\r
try {\r
int status = executeMethod(get);\r
Log.e(TAG, "status return: " + status);\r
- if (status != HttpStatus.SC_OK) {\r
- return false;\r
+ if (status == HttpStatus.SC_OK) {\r
+ targetPath.createNewFile();\r
+ BufferedInputStream bis = new BufferedInputStream(\r
+ get.getResponseBodyAsStream());\r
+ FileOutputStream fos = new FileOutputStream(targetPath);\r
+\r
+ byte[] bytes = new byte[4096];\r
+ int readResult;\r
+ while ((readResult = bis.read(bytes)) != -1) {\r
+ if (mDataTransferListener != null)\r
+ mDataTransferListener.transferProgress(readResult);\r
+ fos.write(bytes, 0, readResult);\r
+ }\r
+ \r
}\r
- BufferedInputStream bis = new BufferedInputStream(\r
- get.getResponseBodyAsStream());\r
- FileOutputStream fos = new FileOutputStream(targetPath);\r
-\r
- byte[] bytes = new byte[4096];\r
- int readResult;\r
- while ((readResult = bis.read(bytes)) != -1) {\r
- if (mDataTransferListener != null)\r
- mDataTransferListener.transferProgress(readResult);\r
- fos.write(bytes, 0, readResult);\r
- }\r
-\r
- } catch (IOException e) {\r
+ ret = true;\r
+ } catch (Throwable e) {\r
e.printStackTrace();\r
- return false;\r
+ targetPath.delete();\r
}\r
- return true;\r
+ \r
+ return ret;\r
}\r
\r
/**\r