推拉couchabase服务器端thro' couchbase lite客户端

时间:2016-07-08 05:50:02

标签: couchbase-lite

我试图创建一个小的java代码来处理couchbase lite数据库并进行推拉操作

Senario的深度如下

我做的是我创建了名为sync_gateway的存储桶, 并通过下面的config.json

与couchbase服务器连接
{
"interface":":4984", 
"adminInterface":":4985",
"databases":{ 
"db":{ 
"server":"http://localhost:8091", 
"bucket":"sync_gateway",
"sync":function(doc) {
channel(doc.channels);
}
}
}
}

这已经在服务器上的sync_gateway存储桶中创建了元数据, 我已经为本地数据库CBL编写了示例java代码,并为推拉操作编写了函数... 代码:

package com.Testing_couchbaseLite;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;

import javax.naming.ldap.ManageReferralControl;

import org.apache.http.cookie.Cookie;

import com.couchbase.lite.Context;
import com.couchbase.lite.CouchbaseLiteException;
import com.couchbase.lite.Database;
import com.couchbase.lite.Document;
import com.couchbase.lite.JavaContext;
import com.couchbase.lite.Manager;
import com.couchbase.lite.ManagerOptions;
import com.couchbase.lite.QueryOptions;
import com.couchbase.lite.replicator.Replication;
import com.couchbase.lite.support.HttpClientFactory;

public class Test_syncGateWay {


    private URL createSyncURL(boolean isEncrypted){
        URL syncURL = null;
        String host = "https://localhost";  //sync gateway ip
        String port = "4984";              //sync gateway port
        String dbName = "db";
        try {
            syncURL = new URL(host + ":" + port + "/" + dbName);
        } catch (MalformedURLException me) {
            me.printStackTrace();
        }
        return syncURL;
    }

    private void startReplications() throws CouchbaseLiteException {


        try {

            Map<String, Object> map = new HashMap<String, Object>();
            map.put("id", "1");
            map.put("name","ram");

            Manager man = new Manager(new JavaContext(), Manager.DEFAULT_OPTIONS);
            Database db = man.getDatabase("sync_gateway");
            Document doc = db.createDocument();
            doc.putProperties(map);

            System.out.println("-------------done------------");



            System.out.println(man.getAllDatabaseNames());
            System.out.println(man.getDatabase("sync_gateway").getDocumentCount());

        System.out.println(db.getDocument("1").getCurrentRevisionId());         

            System.out.println(db.exists());


              Replication pull = db.createPullReplication(this.createSyncURL(true));
            Replication push = db.createPushReplication(this.createSyncURL(true));
           pull.setContinuous(true);
            push.setContinuous(true);
           pull.start();
            push.start();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }



    }

    private void createDatabase() throws CouchbaseLiteException, IOException {
        // TODO Auto-generated method stub




    }

    public static void main(String[] args) throws CouchbaseLiteException, IOException {
        new Test_syncGateWay().startReplications();



    }
}

现在我通过该配置文件说明同步网关并运行java代码,通过推拉操作在CBL和CB服务器上创建文档。

它显示错误为

Jul 08, 2016 10:27:21 AM com.couchbase.lite.util.SystemLogger e
SEVERE: RemoteRequest: RemoteRequest{GET, https://localhost:4984/db/_local/2eafda901c4de2fe022af262d5cc7d1c0cb5c2d2}: executeRequest() Exception: javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated. url: https://localhost:4984/db/_local/2eafda901c4de2fe022af262d5cc7d1c0cb5c2d2

所以在我的概念中有任何误解吗?以及如何解决这个问题??

1 个答案:

答案 0 :(得分:1)

您尚未设置SSL的同步网关。您需要将SSLCert and SSLPass keys添加到配置文件中。