Couchbase-lite replication error

working with pure java and couchbase-lite.
running following code:

Manager manager = new Manager(new JavaContext(“data”), Manager.DEFAULT_OPTIONS);
Manager.enableLogging(“Sync”, Log.VERBOSE);
final Database db = manager.getDatabase(“sync_gateway”);

URL url = new URL(“http://localhost:4984/sync_gateway/”);
Replication push = db.createPushReplication(url);
Replication pull = db.createPullReplication(url);
pull.setContinuous(true);
push.setContinuous(true);
com.couchbase.lite.auth.Authenticator auth = AuthenticatorFactory.createBasicAuthenticator(“GUEST”, “”);
push.setAuthenticator(auth);
push.setAuthenticator(auth);
pull.setAuthenticator(auth);
push.start();
pull.start();

on line push.start()
it through exception:
Jun 11, 2015 8:46:23 PM com.couchbase.lite.util.SystemLogger e
SEVERE: Sync: RemoteRequest.run() exception: %s
java.lang.ArrayIndexOutOfBoundsException: 1
at com.couchbase.lite.support.RemoteRequest.preemptivelySetAuthCredentials(RemoteRequest.java:281)
at com.couchbase.lite.support.RemoteRequest.run(RemoteRequest.java:96)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:178)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:292)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)

Jun 11, 2015 8:48:02 PM com.couchbase.lite.util.SystemLogger e
SEVERE: Sync: RemoteRequest.run() exception: %s
java.lang.ArrayIndexOutOfBoundsException: 1
at com.couchbase.lite.support.RemoteRequest.preemptivelySetAuthCredentials(RemoteRequest.java:281)
at com.couchbase.lite.support.RemoteRequest.run(RemoteRequest.java:96)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:178)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:292)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)

Jun 11, 2015 8:48:11 PM com.couchbase.lite.util.SystemLogger e
SEVERE: Sync: RemoteRequest.run() exception: %s
java.lang.ArrayIndexOutOfBoundsException: 1
at com.couchbase.lite.support.RemoteRequest.preemptivelySetAuthCredentials(RemoteRequest.java:281)
at com.couchbase.lite.support.RemoteRequest.run(RemoteRequest.java:96)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:178)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:292)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)

I started my sync_gateway, and I want to sync my couchbase lite to couchbase full node.
I started sync_gateway with ip of couchbase full node. now as I know, I only need to run this couchbase lite replication code and my data of couchbase lite will be copied to couchbase full node.
kindly help.

Hi @zeeshan_niazi,

Which version of Couchbase Lite are you using? 1.0.4?

Hi @zeeshan_niazi

This is Couchbase Lite bug. In the your code, you set empty string for password.
At Line 279, “GUEST:”.split(“:”) returns [“GUEST”]
At Line 281, userInfoElements[1] causes ArrayIndexOutOfBoundsException.

As temporary solution, can you use non-empty string for password?

I filed ticket for this issue. https://github.com/couchbase/couchbase-lite-java-core/issues/661

Thanks!
Hideki

One additional note - the GUEST user in Sync Gateway is used for anonymous authentication. I wouldn’t expect it to be used when authenticating via basic auth.

Hi @zeeshan_niazi

If you plan to use GUEST account of sync_gateway, you don’t need to set Authenticator. Simplest solution is just comment out push.setAuthenticator(auth) and pull.setAuthenticator(pull).

@adamf Thank you for your comment.

my couchbase server full node is running on localhost:8091. containing a bucket with name "sync_gateway"
I run my sync_gateway like : sync_gateway -url http://localhost:8091
it started on port 4984.

as you directed me to comment push.setAuthenticator(auth) and pull.setAuthenticator(pull).
I did in the same way . that’s good that there is no exception at this time.

my netbeans console the following output:

Jun 11, 2015 11:29:37 PM com.couchbase.lite.util.SystemLogger w
WARNING: Sync: com.couchbase.lite.replicator.ReplicationInternal$9@16818376: error getting remote checkpoint
Jun 11, 2015 11:29:37 PM com.couchbase.lite.util.SystemLogger e
SEVERE: Sync: com.couchbase.lite.replicator.PusherInternal@7ee19158: Progress: set error = org.apache.http.client.HttpResponseException: Unauthorized
Jun 11, 2015 11:29:37 PM com.couchbase.lite.util.SystemLogger e
SEVERE: Sync: PusherInternal stopGraceful.run() finished

but there replication did not take place there is no data in sync_gateway bucket in couchase server full node.

23:38:07.959483 HTTP: #001: GET /sync_gateway/_local/910375c0b9e421dffb8ca4672b
624be4f6cbf7d8
23:38:07.959483 HTTP: #001: --> 401 Login required (1.0 ms)

What version of Sync Gateway are you running? If you’re running 1.1.0, things should work for you as-is. If you’re running an earlier build, though, starting sync gateway as described doesn’t enable the GUEST user by default, which would explain the ‘unauthorized’ message.

If you’re on something earlier than 1.1.0, the ‘cb_admin_party.json’ config file included in the /examples folder in the Sync Gateway distribution would work for your scenario.

I download sync gateway from : http://www.couchbase.com/nosql-databases/downloads
this link contains sync gateway`s version 1.0.4.

Right - the default config used by 1.0.4 (used if you don’t specify a config file at startup) doesn’t include anonymous access. If you want to enable anonymous access, you’ll need to add the GUEST user to your config. Since you’re targeting a local Couchbase Server, I think you could use the config file from https://github.com/couchbase/sync_gateway/blob/master/examples/basic-couchbase-bucket.json as a starting point, and just update the db and/or bucket name to match the Couchbase Server bucket you’re targeting.

running sync_gateway through config.json file, as it started with no error. I run code, code run correctly with no error. and shows following output in netbeans console :
Jun 12, 2015 11:52:31 AM com.couchbase.lite.util.SystemLogger w
WARNING: Sync: Error converting lastSequence: null to long. Using 0
Jun 12, 2015 11:52:31 AM com.couchbase.lite.util.SystemLogger e
SEVERE: RemoteRequest: Got error status: 404 for http://localhost:4984/sync_gateway/_revs_diff. Reason: Not Found
Jun 12, 2015 11:52:31 AM com.couchbase.lite.util.SystemLogger e
SEVERE: Sync: com.couchbase.lite.replicator.PusherInternal@144745: Progress: set error = org.apache.http.client.HttpResponseException: Not Found

and sync gateway shows following output:

11:54:53.834411 HTTP: #004: GET /sync_gateway/
11:54:53.835412 HTTP: #004: --> 404 no such database “sync_gateway” (11.1 m
s)

I have already created bucket with name sync_gateway on couchbase full node.
why sync_gateway is showing this error?
Is I have to create database on sync_gateway like that ?

Your database name in your config file needs to match the database name you’re targeting.

Did you change ‘db’ and ‘default’ from basic-couchbase-bucket.json to ‘sync_gateway’ in the config file you’re using?

yes I have changed it to “sync_gateway”.
after changing it I am facing the above issue.
I am working on it, for last 1 month, and getting a lot of issues.
I hope, after solving this issue, I will be able to sync my couchbase lite with coushbase full node.

one other thing, when I run sync gateway , with command “sync_gateway” and I check url “http://localhost:4985/sync_gateway/_user/GUEST” this shows me following output :
{“name”:“GUEST”,“all_channels”:[],“disabled”:true}

and when I run sync gateway with “sync_gateway config.json"
and check url: http://localhost:4985/sync_gateway/_user/GUEST” this shows me following output :
{“error”:“not_found”,“reason”:“no such database “sync_gateway””}

@adamf I am waiting for your reply

The ‘not found - no such database’ means that you don’t have the database naming correct in the config file you’re using. If you can post the config file you’re using to a gist, I’ll take a look.

@adamf thanks for your help.
I resolved my issue.
I was putting wrong name of database in config file.
thanks