1

我創建了一個運行Couchbase服務器的Ubuntu虛擬機,其中有一個ships數據框,其中加載了大量文檔。Couchbase lite - Android同步問題

我想測試這個數據桶的簡單拉到一個Android模擬器中運行的Couchbase Lite數據庫。不過,我有很多問題!

我已經創建了下面的一個config.json配置同步網關

{ 
    "log":["CRUD+", "REST+", "Changes+", "Attach+"], 
    "verbose" : true, 
    "databases": { 
     "ships": { 
      "server":"http://192.168.0.9:8091", 
      "sync":`function (doc) { channel (doc.channels); }`, 
      "users": { 
       "GUEST": { 
        "disabled": false, 
        "admin_channels": ["*"] 
       } 
      } 
     } 
    } 
} 

當我開始它似乎開始OK

E:\Couchbase>sync_gateway ./data/config.json 
2015-08-23T10:00:43.275+01:00 Enabling logging: [CRUD+ REST+ Changes+ Attach+] 
2015-08-23T10:00:43.276+01:00 ==== Couchbase Sync Gateway/1.1.0(28;86f028c) ==== 

2015-08-23T10:00:43.276+01:00 Configured Go to use all 8 CPUs; setenv GOMAXPROCS 
to override this 
2015-08-23T10:00:43.277+01:00 WARNING: Error setting MaxFileDescriptors to 5000: 
Unsupported on Windows -- rest.setMaxFileDescriptors() at config.go:443 
2015-08-23T10:00:43.277+01:00 Opening db /ships as bucket "ships", pool "default 
", server <http://192.168.0.9:8091> 
2015-08-23T10:00:43.277+01:00 Opening Couchbase database ships on <http://192.16 
8.0.9:8091> 
2015/08/23 10:00:43 Trying with selected node 0 
2015/08/23 10:00:43 Trying with selected node 0 
2015-08-23T10:00:43.374+01:00  Reset guest user to config 
2015-08-23T10:00:43.375+01:00 Starting admin server on 127.0.0.1:4985 
2015-08-23T10:00:43.379+01:00 Starting server on :4984 ... 

在我的MainActivity類別,我有以下同步網關方法來創建同步URL

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

As well as a me的ThOD調用複製過程

private void startReplications() throws CouchbaseLiteException { 
     Replication pull = application.getDatabase().createPullReplication(this.createSyncURL(false)); 
     pull.setContinuous(true); 
     pull.start(); 

     if(!pull.isRunning()) { 
      Log.d(TAG, "Replication is not running due to " +pull.getLastError().getMessage()); 
      Log.d(TAG, "Replication is not running due to " +pull.getLastError().getCause()); 
      Log.d(TAG, "Replication is not running due to " +pull.getLastError().getStackTrace()); 
      Log.d(TAG, "Replication is not running due to " +pull.getLastError().toString()); 
     } 
    } 

當我打電話startReplications()方法我收到以下異常

08-23 09:16:53.034 17976-18002/com.couchbase.examples.couchbaseevents E/RemoteRequest﹕ io exception. url: https://10.0.2.2:4984/ships/_local/74fbb4649e042fdae28537a02b680ad5890703e3 
    javax.net.ssl.SSLPeerUnverifiedException: No peer certificate 
      at com.android.org.conscrypt.SSLNullSession.getPeerCertificates(SSLNullSession.java:104) 
      at org.apache.http.conn.ssl.AbstractVerifier.verify(AbstractVerifier.java:98) 
      at org.apache.http.conn.ssl.SSLSocketFactory.createSocket(SSLSocketFactory.java:393) 
      at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:170) 
      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:365) 
      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:184) 
      at com.couchbase.lite.support.RemoteRequest.run(RemoteRequest.java:103) 
      at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422) 
      at java.util.concurrent.FutureTask.run(FutureTask.java:237) 
      at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:152) 
      at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:265) 
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) 
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 
      at java.lang.Thread.run(Thread.java:818) 

如果我試圖改變URL以http://10.0.2.2然後我得到以下

08-23 09:23:33.012 20702-20702/? E/AndroidRuntime﹕ FATAL EXCEPTION: main 
    Process: com.couchbase.examples.couchbaseevents, PID: 20702 
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.couchbase.examples.couchbaseevents/com.couchbase.examples.couchbaseevents.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.Throwable.getMessage()' on a null object reference 
      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325) 
      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390) 
      at android.app.ActivityThread.access$800(ActivityThread.java:151) 
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) 
      at android.os.Handler.dispatchMessage(Handler.java:102) 
      at android.os.Looper.loop(Looper.java:135) 
      at android.app.ActivityThread.main(ActivityThread.java:5257) 
      at java.lang.reflect.Method.invoke(Native Method) 
      at java.lang.reflect.Method.invoke(Method.java:372) 
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) 
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) 
    Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.Throwable.getMessage()' on a null object reference 
      at com.couchbase.examples.couchbaseevents.MainActivity.startReplications(MainActivity.java:139) 
      at com.couchbase.examples.couchbaseevents.MainActivity.onCreate(MainActivity.java:56) 
      at android.app.Activity.performCreate(Activity.java:5990) 
      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106) 
      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278) 
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390) 
            at android.app.ActivityThread.access$800(ActivityThread.java:151) 
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) 
            at android.os.Handler.dispatchMessage(Handler.java:102) 
            at android.os.Looper.loop(Looper.java:135) 
            at android.app.ActivityThread.main(ActivityThread.java:5257) 
            at java.lang.reflect.Method.invoke(Native Method) 
            at java.lang.reflect.Method.invoke(Method.java:372) 
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) 
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) 

看看同步網關控制檯,我可以看到以下內容

2015-08-23T10:23:38.094+01:00 HTTP: #001: GET /ships/_local/bfdf0950d51e390e054 
bb31f2895d54b286c36a1 
2015-08-23T10:23:38.095+01:00 HTTP: #001:  --> 404 missing (1.0 ms) 
2015-08-23T10:23:38.128+01:00 HTTP: #002: POST /ships/_changes 
2015-08-23T10:23:38.128+01:00 Changes: MultiChangesFeed({*}, {Since:0 Limit:0 Co 
nflicts:true IncludeDocs:false Wait:false Continuous:false Terminator:0xc0820a92 
c0 HeartbeatMs:300000 TimeoutMs:0}) ... 
2015-08-23T10:23:38.129+01:00 Changes+: MultiChangesFeed: channels expand to cha 
nnels.TimedSet{"!":0x1, "*":0x1} ... 
2015-08-23T10:23:38.206+01:00 Changes+: MultiChangesFeed sending &{Seq:1 ID:_use 
r/GUEST Deleted:false Removed:{} Doc:map[] Changes:[] Err:<nil> branched:false} 

2015-08-23T10:23:38.207+01:00 Changes: MultiChangesFeed done 
2015-08-23T10:23:38.229+01:00 HTTP: #003: POST /ships/_changes 
2015-08-23T10:23:38.230+01:00 Changes: MultiChangesFeed({*}, {Since:1 Limit:50 C 
onflicts:true IncludeDocs:false Wait:true Continuous:false Terminator:0xc0822c21 
80 HeartbeatMs:300000 TimeoutMs:0}) ... 
2015-08-23T10:23:38.230+01:00 Changes+: MultiChangesFeed: channels expand to cha 
nnels.TimedSet{"*":0x1, "!":0x1} ... 
2015-08-23T10:23:38.230+01:00 Changes+: MultiChangesFeed waiting... 
2015-08-23T10:23:38.230+01:00 Changes+: Waiting for "ships"'s count to pass 0 

我不明白爲什麼我會得到404響應?如果我用瀏覽器去http://127.0.0.1:4984/ships/_local/ee1ac8f4b732441355817ac7e9446c27e4089efb我得到以下JSON響應

{"error":"not_found","reason":"missing"} 

ships數據桶

回答