在复制期间在沙发基础精简版的android模拟器中获取http 404错误

时间:2014-04-04 08:50:12

标签: android couchbase couchbase-lite

在我的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 ...

在android中我的复制代码看起来像

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

然后我在模拟器中运行我的Android应用程序,我在changeEventListener中记录错误

        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"}

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

2 个答案:

答案 0 :(得分:1)

管理以解决此错误:

https://github.com/couchbaselabs/GrocerySync-Android

中找到参考项目

对原始步骤/代码进行的主要更改

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

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

  3. 进入授权错误。通过在终端

    中执行以下命令,允许匿名访问(暂时)启用GUEST帐户

    curl -X PUT localhost:4985 / beer-sample / _user / GUEST --data&#39; {&#34;禁用&#34;:false,&#34; admin_channels&#34;:[&#34 ;公共&#34;]}&#39;

答案 1 :(得分:0)

或为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帐户。