when attempting to perform a single replication from CouchDB to cbl the following occurs. The same code functions normally in iOS
using:
couch base-lite 1.1.0
cordova-android 4.1.1
- the _replicate request is made to and from the remote db
- both _replicate requests will stall for 30 seconds before returning a 200 response containing the sessionId but not the “ok” key as mentioned in the _replicate API doc. iOS does include the “ok” key and returns true.
- the local doc count never increases.
This is how I am constructing the _replicate requests
`replicateFrom(bodyRequest?:cbl.IPostReplicateParams, otherDB?:string) {
return new Promise((resolve, reject)=> {
if (!otherDB && !this.syncUrl) reject(new Error('no sync url available to replicate from: ' + this.dbName));
bodyRequest = {source: this.dbName, target: otherDB ? otherDB : this.syncUrl, continuous: false};
var uri = new URI(this.localServerUrl).segment('_replicate');
return this.processRequest('POST', uri.toString(), bodyRequest, null,
(err, response)=> {
if (err) reject(this.buildError('Error From replicate from Request', err));
else resolve(response);
});
});
}
replicateTo(bodyRequest?:cbl.IPostReplicateParams, otherDB?:string) {
return new Promise((resolve, reject)=> {
if (!otherDB && !this.syncUrl) reject(new Error('no sync url available to replicate to: ' + this.dbName));
bodyRequest = {source: otherDB ? otherDB : this.syncUrl, target: this.dbName, continuous: false};
var uri = new URI(this.localServerUrl).segment('_replicate');
this.processRequest('POST', uri.toString(), bodyRequest, null,
(err, response)=> {
if (err) reject(this.buildError('Error From replicate to Request', err));
else resolve(response);
});
});
}
processRequest(verb:string, url:string, data:Object, headers:Object, cb:Function, isAttach?:boolean):void {
var http = new XMLHttpRequest();
http.open(verb, url, true);
if (headers) _.forOwn(headers, (value:any, key)=> { http.setRequestHeader(key, value); });
if (isAttach)http.responseType = 'blob'; //options "arraybuffer", "blob", "document", "json", and "text"
//state change callback
http.onreadystatechange = () => {
if (http.readyState == 4 && http.status >= 200 && http.status <= 299) {
if (isAttach) cb(false, http.response);
else cb(false, JSON.parse(http.responseText));
}
else if (http.readyState == 4 && http.status >= 300) cb({status: http.status, response: http.responseText});
};
//send request variations
if (verb === 'PUT' && isAttach) http.send(data);
else if (verb === 'GET' || verb === 'DELETE')http.send();
else if (verb === 'POST' || verb === 'PUT' && !_.isNull(data))http.send(JSON.stringify(data));
else http.send();
}
I have posted this as github issue #708 in the couchbase-lite-android repo