Cordova plugin 1.1.0 replication problems - Android

#1

Hi,
I have switched to 1.1.0 and I am having the following replication problems (which actually were present also in the previous 1.0.4). The same app on iOS works flawlessly, but only with 1.0.4 installed (with 1.1.0 is crashes).

1- I see many of these infos:

W/Listener﹕ authHeader is null
W/Listener﹕ Unauthorized -- requestCredentials not given or do not match allowed credentials

2- many of these errors:

W/Sync﹕ com.couchbase.lite.replicator.PullerInternal@a298339: failed to write {C0EB0388-4130-43EE-9D9C-E9C2B5032145 #1-ed202b9bba0ccb7e1a4076efffc5e854}: status=500
E/Sync﹕ com.couchbase.lite.replicator.PullerInternal@a298339: Progress: set error = org.apache.http.client.HttpResponseException
E/SQLiteDatabase﹕ Error inserting doc_id=431 revid=1-68c79ef9bbb5cdbd53fc22db98f9d8c6 no_attachments=true deleted=false current=true json=[B@50aa6ba
            android.database.sqlite.SQLiteConstraintException: UNIQUE constraint failed: revs.doc_id, revs.revid (code 2067)

3- several of these:

 W/Sync﹕ com.couchbase.lite.replicator.PullerInternal@a298339 no new remote revisions to fetch.  add lastInboxSequence (1762) to pendingSequences (com.couchbase.lite.support.SequenceMap@ae422e6)

As a consequence to all these errors, the database is not properly replicated and some items result missing. One thing to notice is that the missing items are always the same.

I have also upgraded the server to 3.1.0 and sync_gateway to 1.1.0, just to be sure that the problem was not there, but no solution there.

Anybody can suggest what to do?

Thanks
Luca

#2

Hi @lucapale,

Item 1: How do you set credential for replicator from javascript? Sync-Gateway Cookie needs to be set in request header. Please refer Example section of REST API _replicate
http://developer.couchbase.com/documentation/mobile/1.1.0/develop/references/couchbase-lite/rest-api/server/post-replicate/index.html

Item 2: It seems trying to insert Revision record with same revision ID multiple times. It seems there is bug in CBL Java/Android code.

Item 3: This is not issue. We should use other Logging Level. https://github.com/couchbase/couchbase-lite-java-core/blob/2952fd26659ae9390f4664ef4373e07c98ba425e/src/main/java/com/couchbase/lite/replicator/PullerInternal.java#L197

Thanks,
hdieki

#3

My code for replication comes straight from the original ToDoList example and I ave adapted it to my Ionic app.
I have now tried to follow the new tutorial for Ionic (http://developer.couchbase.com/documentation/mobile/1.1.0/develop/references/couchbase-lite/rest-api/server/post-replicate/index.html) using my server as a main replication server.
It seems to work fine on both Android and iOS, so I suppose something changed and I did not track it down.
I will try to upgrade my app using the ionic template example.
Thank you for your support.
Luca

#4

Hey @lucapale,

If you need to compare any of the Ionic logic to your own JavaScript implementation, you can see all the heavy lifting in this AngularJS wrapper file:

It essentially just wraps the RESTful API into functions. Might help you to figure out the differences between the two replication logics.

Best,

#5

Hi. I have moved to ng-couchbase-lite.js functions for the replications, but I am struggling to get the correct replication with Facebook login.
I manage to login into sync_gateway for the replication, since I changed the remote url to :

remote = {
        url : _this.REMOTE_URL
        auth : {facebook : {email : _this.user.email}}
}

and in the sync_gateway log I see this:

2015-09-24T09:11:53.511+02:00 HTTP:  #016: POST /diveplanapp/_bulk_docs  (as luca.palezza@gmail.com)

But after this all the bulk_get are executed as GUEST user:

2015-09-24T09:11:53.647+02:00 HTTP:  #017: POST /diveplanapp/_bulk_get?revs=true&attachments=true

while they should be like this:

2015-09-24T09:11:53.647+02:00 HTTP:  #017: POST /diveplanapp/_bulk_get?revs=true&attachments=true  (as luca.palezza@gmail.com)

Any idea of what I should change in the ngCouchbaseLite?
Is there any complete tutorial around for FB Login into CouchBase using REST API?
Thanks
Luca

#6

I have moved this to a separate Topic.

#7

Cross linking to the new topic for reference: