One shot replicators intsantiation and authenticators

161 views
Skip to first unread message

Joao Ferreira

unread,
Jun 13, 2014, 6:42:40 AM6/13/14
to mobile-c...@googlegroups.com
I am fairly new to couchbase so this may be a somewhat basic doubt but I can't find proper explanation anywhere in the documentation.

I have an Android app that has a local database that needs to be synced with a remote CouchDB instance. For the push replications I intend to use continuous replicators but for the pulls, as I only need to do them once a day, I thought about using one shot replicators. I tried to create the replicators in a class that has a method that then call the start method of the replicator. The first time the replicator is called everything goes smoothly and everything gets properly synced. The problem happens when I call the replicator once again as the replicator fails to do the replication. So should I instantiate the repicator everytime I call it or is it acceptable to create an instance and then calling start and stop on demand?

Other problem is in setting the authenticator for the replicator. If I set the syncURL as http://user:pass@example:5984/dbname everything works fine, but trying to use the BasicAuthenticor I get an Object not found exception, and I can't make sense of this exception.

Any thoughts are greatly appreciated

Traun Leyden

unread,
Jun 13, 2014, 2:34:55 PM6/13/14
to mobile-c...@googlegroups.com
On Fri, Jun 13, 2014 at 3:42 AM, Joao Ferreira <joao.m.pin...@gmail.com> wrote:
 
The first time the replicator is called everything goes smoothly and everything gets properly synced. The problem happens when I call the replicator once again as the replicator fails to do the replication.

When you say fails, can you be more specific?  Also are you sure there is any changes on the remote CouchDB that need to be sync'd?  If not, then the replication might not have anything to do.

 
So should I instantiate the repicator everytime I call it or is it acceptable to create an instance and then calling start and stop on demand?


There are some known issues with the replicator lifecycle that are still being investigated.  See https://github.com/couchbase/couchbase-lite-java-core/issues/224#issuecomment-45616469

So it might be safer to instantiate the replicator every time.

 
Other problem is in setting the authenticator for the replicator. If I set the syncURL as http://user:pass@example:5984/dbname everything works fine, but trying to use the BasicAuthenticor I get an Object not found exception, and I can't make sense of this exception.

That sounds to me like some sort of packaging problem or maybe a typo in your code.

There's a unit test that uses the BasicAuthenticator.

How are you building -- Android Studio / Eclipse / gradle ?

 

Any thoughts are greatly appreciated

--
You received this message because you are subscribed to the Google Groups "Couchbase Mobile" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mobile-couchba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mobile-couchbase/02b27c12-9301-4354-bd5f-a92756f9795f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Joao Ferreira

unread,
Jun 13, 2014, 8:14:35 PM6/13/14
to mobile-c...@googlegroups.com
Thank you for your reply :)

Fails as it sometimes crashes.. It might have something to do with the issues with the lifecycle you have referred. It's perfectly fine for me to instantiate it every time so if that is the safer way I'll do it that way, it is what I am already doing anyway.

As for the authentication I am doing exactly as it is shown in the unit testing except I am doing:
Authenticator auth = BasicAuthenticator(username, password);
I don't think that might be the problem.

I am using Android Studio with gradle build.

Traun Leyden

unread,
Jun 17, 2014, 10:40:58 AM6/17/14
to mobile-c...@googlegroups.com

Fails as it sometimes crashes..

Can you post a stacktrace?


As for the authentication I am doing exactly as it is shown in the unit testing except I am doing:
Authenticator auth = BasicAuthenticator(username, password);
I don't think that might be the problem.

Ditto - can you post a stacktrace for this too?

 

I am using Android Studio with gradle build.


Sexta-feira, 13 de Junho de 2014 19:34:55 UTC+1, Traun Leyden escreveu:


On Fri, Jun 13, 2014 at 3:42 AM, Joao Ferreira <joao.m.pin...@gmail.com> wrote:
 
The first time the replicator is called everything goes smoothly and everything gets properly synced. The problem happens when I call the replicator once again as the replicator fails to do the replication.

When you say fails, can you be more specific?  Also are you sure there is any changes on the remote CouchDB that need to be sync'd?  If not, then the replication might not have anything to do.

 
So should I instantiate the repicator everytime I call it or is it acceptable to create an instance and then calling start and stop on demand?


There are some known issues with the replicator lifecycle that are still being investigated.  See https://github.com/couchbase/couchbase-lite-java-core/issues/224#issuecomment-45616469

So it might be safer to instantiate the replicator every time.

 
Other problem is in setting the authenticator for the replicator. If I set the syncURL as http://user:pass@example:5984/dbname everything works fine, but trying to use the BasicAuthenticor I get an Object not found exception, and I can't make sense of this exception.

That sounds to me like some sort of packaging problem or maybe a typo in your code.

There's a unit test that uses the BasicAuthenticator.

How are you building -- Android Studio / Eclipse / gradle ?

 

Any thoughts are greatly appreciated

--
You received this message because you are subscribed to the Google Groups "Couchbase Mobile" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mobile-couchba...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Couchbase Mobile" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mobile-couchba...@googlegroups.com.

Joao Ferreira

unread,
Jun 20, 2014, 7:27:35 AM6/20/14
to mobile-c...@googlegroups.com
For the instantiation the problem is solved.

As for the authenticator here is a stack trace. The error given is object not found, what does not make sense to me.

06-20 12:23:17.806    5320-5463/pt.fraunhofer.alznav.debug E/RemoteRequest﹕ Got error status: 404 for org.apache.http.client.methods.HttpGet@41a32b30.  Reason: Object Not Found
06-20 12:23:17.846    5320-5465/pt.fraunhofer.alznav.debug E/RemoteRequest﹕ Got error status: 404 for org.apache.http.client.methods.HttpGet@4198c848.  Reason: Object Not Found
06-20 12:23:17.856    5320-5347/pt.fraunhofer.alznav.debug E/Sync﹕ com.couchbase.lite.replicator.Replication$4@419d2400: Session check failed
    org.apache.http.client.HttpResponseException: Object Not Found
            at com.couchbase.lite.support.RemoteRequest.executeRequest(RemoteRequest.java:228)
            at com.couchbase.lite.support.RemoteRequest.run(RemoteRequest.java:106)
            at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:442)
            at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
            at java.util.concurrent.FutureTask.run(FutureTask.java:137)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
            at java.lang.Thread.run(Thread.java:856)
06-20 12:23:17.856    5320-5347/pt.fraunhofer.alznav.debug E/Sync﹕ Puller@41b12328[http://url/db]: Progress: set error = org.apache.http.client.HttpResponseException: Object Not Found

Traun Leyden

unread,
Jun 20, 2014, 10:36:28 AM6/20/14
to mobile-c...@googlegroups.com
That looks like it's trying to make a request to http://yourserver/yourdb/_session and getting a 404, and then giving up.

Are you connecting to Sync Gateway?  Have you already created yourdb in the sync gateway config?  


Joao Ferreira

unread,
Jun 20, 2014, 10:54:43 AM6/20/14
to mobile-c...@googlegroups.com
I am not using CouchBase as server, I am using CouchDB so  no sync gateway right? I have read it here at least.

It may be possible that authenticators do not work in couchbase <-> couchDb because of lacking the sync gateway?

Traun Leyden

unread,
Jun 20, 2014, 11:17:17 AM6/20/14
to mobile-c...@googlegroups.com
On Fri, Jun 20, 2014 at 7:54 AM, Joao Ferreira <joao.m.pin...@gmail.com> wrote:
I am not using CouchBase as server, I am using CouchDB so  no sync gateway right? I have read it here at least.


Yes, that's correct.
 
It may be possible that authenticators do not work in couchbase <-> couchDb because of lacking the sync gateway?

The only auth I've used with CouchDB is Basic Auth by embedding the username/password into the URL.  Eg, http://user:pass...@iriscouch.com/db/

However, the BasicAuthenticator you are using should also work.  The fact that it's trying to check the /db/_session endpoint seems like it might be a bug in Couchbase Lite.

@Jens -- does this sound right to you?  Should it ever be hitting /db/_session when using BasicAuth?  (the BasicAuthenticator as opposed to embedding the username/password in the URL)

@Joao -- can you try embedding the username and password in the URL and see if it changes the result? 

 

Joao Ferreira

unread,
Jun 20, 2014, 11:38:37 AM6/20/14
to mobile-c...@googlegroups.com
@Joao -- can you try embedding the username and password in the URL and see if it changes the result? 

That way it works with no problem but I would like to avoid it as much as possible. I supposed the BasicAuthenticator should also work, as it is a similar approach just putting the authentication details in the headers.


Sexta-feira, 20 de Junho de 2014 16:17:17 UTC+1, Traun Leyden escreveu:
On Fri, Jun 20, 2014 at 7:54 AM, Joao Ferreira <joao.m.pin...@gmail.com> wrote:
I am not using CouchBase as server, I am using CouchDB so  no sync gateway right? I have read it here at least.


Yes, that's correct.
 
It may be possible that authenticators do not work in couchbase <-> couchDb because of lacking the sync gateway?

The only auth I've used with CouchDB is Basic Auth by embedding the username/password into the URL.  Eg, http://user:password@iriscouch.com/db/

Traun Leyden

unread,
Jun 20, 2014, 12:03:31 PM6/20/14
to mobile-c...@googlegroups.com


On Friday, June 20, 2014 8:38:37 AM UTC-7, Joao Ferreira wrote:
@Joao -- can you try embedding the username and password in the URL and see if it changes the result? 

That way it works with no problem but I would like to avoid it as much as possible. I supposed the BasicAuthenticator should also work, as it is a similar approach just putting the authentication details in the headers.

Yeah, that sounds like a bug then.

Joao Ferreira

unread,
Jun 21, 2014, 6:06:39 AM6/21/14
to mobile-c...@googlegroups.com
Thank you, I'll be sure to follow that.
Reply all
Reply to author
Forward
0 new messages