I am very new to couchbase , I have set up couchbase server , sync_gate and a android app using coucbase mobile lite.
I am trying to sync the local remote on android app to sync_gateway but I am not able to sync it.
my json file is as
{
“log”:[“CRUD+”, “REST+”, “Changes+”, “Attach+”],
“databases”: {
“sync_gateway”: {
“server”:“http://localhost:8091”,
“bucket”:“sync_gateway”,
“sync”:function (doc) { channel (doc.channels); }
,
“users”: {
“GUEST”: {
“disabled”: false,
“admin_channels”: ["*"]
}
}
}
}
}
and this is what what my sync_gate looks like …
C:\Program Files (x86)\Couchbase>sync_gateway.exe config.json
2016-01-18T12:45:38.493-05:00 Enabling logging: [CRUD+ REST+ Changes+ Attach+]
2016-01-18T12:45:38.496-05:00 ==== Couchbase Sync Gateway/1.1.1(10;2fff9eb) ====
2016-01-18T12:45:38.498-05:00 Configured Go to use all 4 CPUs; setenv GOMAXPROCS to override this
2016-01-18T12:45:38.501-05:00 Opening db /sync_gateway as bucket “sync_gateway”, pool “default”, server http://localhost:8091
2016-01-18T12:45:38.506-05:00 Opening Couchbase database sync_gateway on http://localhost:8091
2016/01/18 12:45:38 Trying with http://127.0.0.1:8091/pools/default/bucketsStreaming/sync_gateway
2016/01/18 12:45:38 Trying with selected node 0
2016/01/18 12:45:38 Got new configuration for bucket sync_gateway
2016/01/18 12:45:39 Trying with selected node 0
2016-01-18T12:45:39.518-05:00 NOTE: “sync_gateway”'s sync function has changed. The new function may assign different channels to documents, or permissions to users. You may want to re-sync the database to update these.
2016/01/18 12:45:41 go-couchbase: call to ViewCustom(“sync_gateway”, “access”) in github.com/couchbase/sync_gateway/db.(*DatabaseContext).ComputeChannelsForPrincipal took 1.6873498s
2016-01-18T12:45:41.338-05:00 Reset guest user to config
2016-01-18T12:45:41.363-05:00 Starting admin server on 127.0.0.1:4985
2016-01-18T12:45:41.371-05:00 Starting server on :4984 …
2016-01-18T12:45:42.681-05:00 Changes+: Notifying that “sync_gateway” changed (keys="{_sync:user:}") count=2
I am trying to push and pull the data from sync_gateway . Android code looks like -
protected void onCreate(Bundle savedInstanceState) {
Log.d("starting ", " |----------->");
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
try{
String DatabaseName = "couchbaseevents";
Manager manager = new Manager( new AndroidContext(getApplicationContext()),Manager.DEFAULT_OPTIONS);
Database database = manager.getDatabase(DatabaseName);
android.util.Log.d("Message", "Database created");
Document document = database.getDocument("1379");
Log.i("Message", "Document with ID : " + document.getId());
HashMap<String,Object> mymap = new HashMap<String, Object>();
mymap.put("Name", "pandey");
mymap.put("Address", "India");
document.putProperties(mymap);
Document doc1 = database.getExistingDocument("1377");
Map<String, Object > result = doc1.getProperties();
Log.i("Name", result.get("Name").toString());
Log.i("Adress", result.get("Address").toString());
String dns = "http://localhost";
String port = "4984";
String database1 = "sync_gateway";
URL syncUrl = new URL("http://localhost:4984/sync_gateway/");
Log.i("----", "URL created");
Replication pull= database.createPullReplication(syncUrl);
Log.i("----", "Repliation");
pull.start();
Log.i("----", "Push start");
Document doc = database.getExistingDocument("ping");
Map<String, Object > result = doc.getProperties();
Log.i("Name", result.get("name").toString());
Log.i("Adress", result.get("address").toString());
}
catch (Exception e)
{
android.util.Log.e("CouchbaseEvents","error nconnectiong to DB"+e.getMessage()+", "+e.getStackTrace());
}
I am getting below error -
s I/art: Not late-enabling -Xcheck:jni (already on)
01-18 13:35:08.963 19582-19582/com.example.sujee.couchbaseevents D/starting: |----------->
01-18 13:35:09.464 19582-19588/com.example.sujee.couchbaseevents W/art: Suspending all threads took: 39.050ms
01-18 13:35:09.522 19582-19592/com.example.sujee.couchbaseevents I/art: Background sticky concurrent mark sweep GC freed 23355(1365KB) AllocSpace objects, 5(160KB) LOS objects, 49% free, 1866KB/3MB, paused 5.249ms total 110.747ms
01-18 13:35:09.544 19582-19582/com.example.sujee.couchbaseevents V/TDCollateJSON: SQLite3 handle is -1274527616
01-18 13:35:09.547 19582-19582/com.example.sujee.couchbaseevents I/----: URL created
01-18 13:35:09.557 19582-19582/com.example.sujee.couchbaseevents I/----: Repliation
01-18 13:35:09.559 19582-19582/com.example.sujee.couchbaseevents I/----: Pull start
01-18 13:35:09.597 19582-19616/com.example.sujee.couchbaseevents E/RemoteRequest: io exception. url: http://localhost:4984/sync_gateway/_local/8751eaea00a525de709b3c356d4fd78ac3cb8619
org.apache.http.conn.HttpHostConnectException: Connection to http://localhost:4984 refused
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:193)
at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:169)
at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:124)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:366)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:560)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:492)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:470)
at com.couchbase.lite.support.RemoteRequest.executeRequest(RemoteRequest.java:201)
at com.couchbase.lite.support.RemoteRequest.run(RemoteRequest.java:104)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:423)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:269)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
Caused by: java.net.ConnectException: failed to connect to /127.0.0.1 (port 4984) after 60000ms: isConnected failed: ECONNREFUSED (Connection refused)
at libcore.io.IoBridge.isConnected(IoBridge.java:234)
at libcore.io.IoBridge.connectErrno(IoBridge.java:171)
at libcore.io.IoBridge.connect(IoBridge.java:122)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:183)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:452)
at java.net.Socket.connect(Socket.java:884)
I am not sure what I am doing wrong here . Can anyone please help on this.