2016-07-08 4 views
0

ich versucht habe einen kleinen Java-Code erstellen Couchbase lite Datenbank zu handhaben und Push-Pull-BetriebPush-Pull auf couchabase Server-Seite thro‘Couchbase lite Client-Seite

senario in der Tiefe zu tun ist, wie folgt

was ich habe ist, ich habe Eimer als sync_gateway genannt erstellt, und mit Couchbase Server conected von unten config.json

{ 
"interface":":4984", 
"adminInterface":":4985", 
"databases":{ 
"db":{ 
"server":"http://localhost:8091", 
"bucket":"sync_gateway", 
"sync":function(doc) { 
channel(doc.channels); 
} 
} 
} 
} 

diese Metadaten in sync_gateway Eimer auf dem Server erstellt hatte, die ni have geschrieben Beispiel Java-Code für die lokale Datenbank CBL und schrieb Funktionen für Push-Pull-Operationen ... Code:

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(); 



    } 
} 

jetzt i-Sync-Gateway durch diese Konfigurationsdatei an Angabe und Java-Code ausgeführt Dokument auf CBL und CB erstellen Server per Push-Pull-Betrieb.

bt es zeigt Fehler als

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 

so ist es ein Missverständnis in meinem Konzept ??? und wie löse ich dieses Problem?

Antwort