Couchbase Lite: 'not_found' error when doing PUT/POST using REST API

Hi,

I’m currently developing an app using Couchbase Lite Beta2 for Android and Phonegap.
The Phonegap plugin is creating a database (let’s say ‘dbTest’) and inserting some documents using Couchbase Lite java API:

Manager server = new Manager(directory, Manager.DEFAULT_OPTIONS); Database database = server.getDatabase(DEFAULT_DATABASE_NAME); database.createDocument().putProperties(new java.util.HashMap(){{this.put("a1", "v1"); this.put("a2", "v2");}});

This works fine. I can even retrieve the inserted document from my webapp using the following REST CALL (mocked with curl):

curl -X GET -H 'Content-Type: application/json' http://192.168.2.108:5984/dbTest/_all_docs

{“offset”:0,“total_rows”:1,“rows”:[{“id”:“ab4e87de-8a1d-4b4b-828b-80371068cce4”,“value”:{"_conflicts":[],“rev”:“1-c045e690-e28f-4efb-b04c-9aa0abc05751”},“key”:“ab4e87de-8a1d-4b4b-828b-80371068cce4”}]}

The problem is when I try to PUT or POST a new document using the REST API. No matter what I try, I always end up with the following error:

{"error":"not_found","reason":"Router unable to route request to do_PUT_Documentjava.lang.reflect.InvocationTargetException"}

The easiest way to replicate this error is using curl:

curl -X PUT -H ‘Content-Type: application/json’ http://192.168.2.108:5984/dbTest/abc -d “{‘x’:‘y’}”

My question is: Am I doing something wrong? I think this is a trivial usecase that should be supported by the current api, even if it’s in beta 2 stage. Given that this is my first time working with couchbase I assume I’m missing something obvious here.

Regards,

Looks like you need to change the way you are quoting the fields. This worked for me:

curl -X PUT -H 'Content-Type: application/json' 192.168.56.101:5984/cblite-test/abc -d '{"x":"y"}'

When I tried to use your snippet, I could see the following error in the adb logcat output:

W/Database( 1233): WARNING: Exception parsing body into dictionary W/Database( 1233): org.codehaus.jackson.JsonParseException: Unexpected character (''' (code 39)): was expecting double-quote to start field name W/Database( 1233): at [Source: Acme.Serve.Serve$ServeInputStream@53568f3c; line: 1, column: 3] W/Database( 1233): at org.codehaus.jackson.JsonParser._constructError(JsonParser.java:1432) W/Database( 1233): at org.codehaus.jackson.impl.JsonParserMinimalBase._reportError(JsonParserMinimalBase.java:385) W/Database( 1233): at org.codehaus.jackson.impl.JsonParserMinimalBase._reportUnexpectedChar(JsonParserMinimalBase.java:306) W/Database( 1233): at org.codehaus.jackson.impl.Utf8StreamParser._handleUnusualFieldName(Utf8StreamParser.java:1531) W/Database( 1233): at org.codehaus.jackson.impl.Utf8StreamParser._parseFieldName(Utf8StreamParser.java:1221) W/Database( 1233): at org.codehaus.jackson.impl.Utf8StreamParser.nextToken(Utf8StreamParser.java:489) W/Database( 1233): at org.codehaus.jackson.map.deser.std.MapDeserializer._readAndBind(MapDeserializer.java:299) W/Database( 1233): at org.codehaus.jackson.map.deser.std.MapDeserializer.deserialize(MapDeserializer.java:249) W/Database( 1233): at org.codehaus.jackson.map.deser.std.MapDeserializer.deserialize(MapDeserializer.java:33) W/Database( 1233): at org.codehaus.jackson.map.ObjectMapper._readMapAndClose(ObjectMapper.java:2723) W/Database( 1233): at org.codehaus.jackson.map.ObjectMapper.readValue(ObjectMapper.java:1900) W/Database( 1233): at com.couchbase.lite.router.Router.getBodyAsDictionary(Router.java:161) W/Database( 1233): at com.couchbase.lite.router.Router.do_PUT_Document(Router.java:1534) W/Database( 1233): at java.lang.reflect.Method.invokeNative(Native Method) W/Database( 1233): at java.lang.reflect.Method.invoke(Method.java:511) W/Database( 1233): at com.couchbase.lite.router.Router.start(Router.java:452) W/Database( 1233): at com.couchbase.lite.listener.LiteServlet.service(LiteServlet.java:102) W/Database( 1233): at javax.servlet.http.HttpServlet.service(HttpServlet.java:802) W/Database( 1233): at Acme.Serve.Serve$ServeConnection.runServlet(Serve.java:2251) W/Database( 1233): at Acme.Serve.Serve$ServeConnection.parseRequest(Serve.java:2176) W/Database( 1233): at Acme.Serve.Serve$ServeConnection.run(Serve.java:1988) W/Database( 1233): at Acme.Utils$ThreadPool$PooledThread.run(Utils.java:1223) W/Database( 1233): at java.lang.Thread.run(Thread.java:856) E/Database( 1233): Router unable to route request to do_PUT_Document E/Database( 1233): java.lang.reflect.InvocationTargetException E/Database( 1233): at java.lang.reflect.Method.invokeNative(Native Method) E/Database( 1233): at java.lang.reflect.Method.invoke(Method.java:511) E/Database( 1233): at com.couchbase.lite.router.Router.start(Router.java:452) E/Database( 1233): at com.couchbase.lite.listener.LiteServlet.service(LiteServlet.java:102) E/Database( 1233): at javax.servlet.http.HttpServlet.service(HttpServlet.java:802) E/Database( 1233): at Acme.Serve.Serve$ServeConnection.runServlet(Serve.java:2251) E/Database( 1233): at Acme.Serve.Serve$ServeConnection.parseRequest(Serve.java:2176) E/Database( 1233): at Acme.Serve.Serve$ServeConnection.run(Serve.java:1988) E/Database( 1233): at Acme.Utils$ThreadPool$PooledThread.run(Utils.java:1223) E/Database( 1233): at java.lang.Thread.run(Thread.java:856) E/Database( 1233): Caused by: com.couchbase.lite.CouchbaseLiteException E/Database( 1233): at com.couchbase.lite.router.Router.do_PUT_Document(Router.java:1536) E/Database( 1233): ... 10 more W/ThrottleService( 438): unable to find stats for iface rmnet0

JSON only allows double-quotes, not single quotes.
But the response from CBL should be more informative (at a minimum it should be a 400, not 404.)

I filed https://github.com/couchbase/couchbase-lite-java-listener/issues/41 to improve the CBL Response in that case.

That was it! I knew it was my fault!
Agree with @jens, the error should be more informative than that!

Thanks!