Bug 709339 - First mostly functional drop of native Sync. a=mobile

This commit is contained in:
Richard Newman
2012-01-14 09:20:31 -08:00
parent 83e8e5d5ed
commit 5fe8ffe843
89 changed files with 5497 additions and 2295 deletions

View File

@@ -19,7 +19,7 @@
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Richard Newman <rnewman@mozilla.com>
* Richard Newman <rnewman@mozilla.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
@@ -70,6 +70,7 @@ import ch.boye.httpclientandroidlib.impl.client.DefaultHttpClient;
import ch.boye.httpclientandroidlib.impl.conn.tsccm.ThreadSafeClientConnManager;
import ch.boye.httpclientandroidlib.params.HttpConnectionParams;
import ch.boye.httpclientandroidlib.params.HttpParams;
import ch.boye.httpclientandroidlib.params.HttpProtocolParams;
import ch.boye.httpclientandroidlib.protocol.BasicHttpContext;
import ch.boye.httpclientandroidlib.protocol.HttpContext;
@@ -80,18 +81,44 @@ import ch.boye.httpclientandroidlib.protocol.HttpContext;
* Exposes simple get/post/put/delete methods.
*/
public class BaseResource implements Resource {
public static boolean rewriteLocalhost = true;
private static final String LOG_TAG = "BaseResource";
protected URI uri;
protected BasicHttpContext context;
protected DefaultHttpClient client;
public ResourceDelegate delegate;
protected HttpRequestBase request;
public String charset = "utf-8";
public BaseResource(String uri) throws URISyntaxException {
this(new URI(uri));
this(uri, rewriteLocalhost);
}
public BaseResource(URI uri) {
this.uri = uri;
this(uri, rewriteLocalhost);
}
public BaseResource(String uri, boolean rewrite) throws URISyntaxException {
this(new URI(uri), rewrite);
}
public BaseResource(URI uri, boolean rewrite) {
if (rewrite && uri.getHost().equals("localhost")) {
// Rewrite localhost URIs to refer to the special Android emulator loopback passthrough interface.
Log.d(LOG_TAG, "Rewriting " + uri + " to point to 10.0.2.2.");
try {
this.uri = new URI(uri.getScheme(), uri.getUserInfo(), "10.0.2.2", uri.getPort(), uri.getPath(), uri.getQuery(), uri.getFragment());
} catch (URISyntaxException e) {
Log.e(LOG_TAG, "Got error rewriting URI for Android emulator.", e);
}
} else {
this.uri = uri;
}
}
public URI getURI() {
return this.uri;
}
/**
@@ -129,6 +156,7 @@ public class BaseResource implements Resource {
HttpParams params = client.getParams();
HttpConnectionParams.setConnectionTimeout(params, delegate.connectionTimeout());
HttpConnectionParams.setSoTimeout(params, delegate.socketTimeout());
HttpProtocolParams.setContentCharset(params, charset);
delegate.addHeaders(request, client);
}