在复制期间,在沙发底座精简版的安卓模拟器中获取 http 404 错误



在我的Mac 10.9.2中我安装了沙发基础服务器,它正在运行http://127.0.0.1:8091它有它的默认桶,包括啤酒样品

我启动同步服务器为

./sync_gateway -bucket="beer-sample" 

在控制台中记录以下内容

14:00:55.903306 ==== Couchbase Sync Gateway/0.94 ====
14:00:55.979850 Configured Go to use all 2 CPUs; setenv GOMAXPROCS to override this
14:00:55.979985 Configured MaxFileDescriptors (RLIMIT_NOFILE) to 5000
14:00:56.005329 Opening db /beer-sample as bucket "beer-sample", pool "default", server <walrus:>
14:00:56.019242 Opening Walrus database beer-sample on <walrus:>
14:00:56.057276 Using default sync function 'channel(doc.channels)' for database "beer-sample"
14:00:56.057549 Starting profile server on 
14:00:56.057680 Starting admin server on 127.0.0.1:4985
14:00:56.090556 Starting server on :4984 ...

在安卓中,我的复制代码看起来像

Replication pullReplication = database.createPullReplication("http://10.0.2.2:4984");
pullReplication.start();

然后我在模拟器中运行我的安卓应用程序,并在更改事件侦听器中记录错误

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

记录的

04-04 14:04:18.402    1622-1644/com.couchbase.replicationsample.replicationsample D/HelloWorld﹕ Replication: Puller[http://10.0.2.2:4984] changed.
04-04 14:04:18.432    1622-1644/com.couchbase.replicationsample.replicationsample D/HelloWorld﹕ Replication is not running due to HTTP/1.1 404 Not Found
04-04 14:04:18.454    1622-1644/com.couchbase.replicationsample.replicationsample D/HelloWorld﹕ Replication is not running due to null
04-04 14:04:18.502    1622-1644/com.couchbase.replicationsample.replicationsample D/HelloWorld﹕ Replication is not running due to [Ljava.lang.StackTraceElement;@414efc88
04-04 14:04:18.502    1622-1644/com.couchbase.replicationsample.replicationsample D/HelloWorld﹕ Replication is not running due to com.couchbase.lite.CouchbaseLiteException: HTTP/1.1 404 Not Found
Note: I am using 10.0.2.2 instead of 127.0.0.1 because i read in forum that's how simulator maps the host machine. But i also tried 127.0.0.1 earlier which also gives the same result.

同时我在同步网关控制台日志中看到一个新条目,例如

14:05:13.532393 HTTP:  #006: GET /_changes?feed=normal&heartbeat=300000

我试图在浏览器中重复此查询,例如

> http://127.0.0.1:4984/_changes?feed=normal&heartbeat=300000

正在显示

{"error":"not_found","reason":"unknown URL"}

我在这里犯了什么错误?我是沙发基地的新手。

设法克服了这个错误:

在 https://github.com/couchbaselabs/GrocerySync-Android 找到一个参考项目

对我的原始步骤/代码所做的主要更改是

  1. 已执行同步网关作为./sync_gateway -bucket="beer-sample" -url=“http://localhost:8091/beer-sample" -verbose

  2. 在同步URL中添加了数据库,例如" http://10.0.2.2:4984/beer-sample",即database.createPullReplication("http://10.0.2.2:4984/beer-sample");

  3. 遇到授权错误。通过在终端中执行以下命令来允许匿名访问(暂时)启用GUEST帐户

    curl -X PUT 本地主机:4985/beer-sample/_user/GUEST --data '{"disabled":false, "admin_channels":["public"]}'

或者为sync_gateway创建一个配置(例如config.json),如下所示:

{
   "interface":":4984",
   "adminInterface":":4985",
   "log":["REST"],
   "databases":{
      "registratura7":{
         "server":"http://YOUR_IP:8091",
         "bucket":"registratura7",
         "sync":`function(doc) {channel(doc.channels);}`,
         "users": { "GUEST": {"disabled": false, "admin_channels": ["*"] } }
      }
   }
}

然后像这样运行sync_gateway:sync_gateway config.json。这将在 CouchDB 网关上启用 GUEST 帐户。

最新更新