X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/8ec6915a58779eb43f1446100cb6fa477c206529..a10efb1229c7200721b19533dde9301d9052ce25:/src/eu/alefzero/webdav/WebdavClient.java diff --git a/src/eu/alefzero/webdav/WebdavClient.java b/src/eu/alefzero/webdav/WebdavClient.java index 722614ee..f03b7a97 100644 --- a/src/eu/alefzero/webdav/WebdavClient.java +++ b/src/eu/alefzero/webdav/WebdavClient.java @@ -18,19 +18,18 @@ package eu.alefzero.webdav; import java.io.BufferedInputStream; -import java.io.BufferedOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; -import java.io.InputStreamReader; -import java.io.OutputStreamWriter; +import org.apache.commons.httpclient.Credentials; +import org.apache.commons.httpclient.HttpClient; +import org.apache.commons.httpclient.UsernamePasswordCredentials; +import org.apache.commons.httpclient.auth.AuthScope; import org.apache.http.HttpHost; import org.apache.http.HttpResponse; import org.apache.http.HttpStatus; import org.apache.http.HttpVersion; -import org.apache.http.auth.AuthScope; -import org.apache.http.auth.UsernamePasswordCredentials; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPut; import org.apache.http.conn.ClientConnectionManager; @@ -41,7 +40,6 @@ import org.apache.http.conn.scheme.Scheme; import org.apache.http.conn.scheme.SchemeRegistry; import org.apache.http.conn.ssl.SSLSocketFactory; import org.apache.http.entity.FileEntity; -import org.apache.http.entity.mime.content.FileBody; import org.apache.http.impl.auth.BasicScheme; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager; @@ -56,12 +54,13 @@ import eu.alefzero.webdav.HttpMkCol; import android.net.Uri; import android.util.Log; -public class WebdavClient { +public class WebdavClient extends HttpClient { private DefaultHttpClient mHttpClient; private BasicHttpContext mHttpContext; private HttpHost mTargetHost; private SchemeRegistry mSchemeRegistry; - private Uri mUri; + private Uri mUri; + private Credentials mCredentials; final private static String TAG = "WebdavClient"; public DefaultHttpClient getHttpClient() { @@ -81,15 +80,17 @@ public class WebdavClient { // determine default port for http or https int targetPort = mTargetHost.getPort() == -1 ? ( mUri.getScheme().equals("https") ? 443 : 80) - : mUri.getPort(); - - mHttpClient.getCredentialsProvider().setCredentials( - new AuthScope(mUri.getHost(), targetPort), - new UsernamePasswordCredentials(username, password)); - BasicScheme basicAuth = new BasicScheme(); - mHttpContext.setAttribute("preemptive-auth", basicAuth); + : mUri.getPort(); + + getParams().setAuthenticationPreemptive(true); + getState().setCredentials(AuthScope.ANY, getCredentials(username, password)); } + private Credentials getCredentials(String username, String password) { + if (mCredentials == null) + mCredentials = new UsernamePasswordCredentials(username, password); + return mCredentials; + } public void allowUnsignedCertificates() { // https mSchemeRegistry.register(new Scheme("https", new EasySSLSocketFactory(), 443)); @@ -129,7 +130,6 @@ public class WebdavClient { method.setHeader("User-Agent", "Android-ownCloud"); try { - FileBody fb = new FileBody(new File(localFile, contentType)); final FileEntity fileEntity = new FileEntity(new File(localFile), contentType); method.setEntity(fileEntity);