5

I created a default GWT project and trying to create a document in the database with a simple entry using CouchDB as my database. Previously we were using CouchDB 1.6 i.e futon as UI. Now, recently trying to use CouchDB 2.0 i.e Fauxton as UI.

PROBLEM:-

Unable to create a document in CouchDB 2.0.

SERVER SIDE CODE:-

public String greetServer(String input) throws IllegalArgumentException {
        // Verify that the input is valid. 
        System.out.println(input);

        Session session=new Session("192.168.1.48",5984);
        Database db=session.getDatabase("testing");
        Document doc=new Document();
        doc.put("name", input);
        db.saveDocument(doc);

        return "Hello, " + input;
    }

EXCEPTION:-

2017-02-22 17:23:41.147:WARN:/:qtp10750155-45: Exception while dispatching incoming RPC call
com.google.gwt.user.server.rpc.UnexpectedException: Service method 'public abstract java.lang.String com.dbconnect.client.GreetingService.greetServer(java.lang.String) throws java.lang.IllegalArgumentException' threw an unexpected exception: net.sf.json.JSONException: JSONObject["update_seq"] is not a number.
    at com.google.gwt.user.server.rpc.RPC.encodeResponseForFailure(RPC.java:416)
    at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:605)
    at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:333)
    at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:303)
    at com.google.gwt.user.server.rpc.RemoteServiceServlet.processPost(RemoteServiceServlet.java:373)
    at com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet.doPost(AbstractRemoteServiceServlet.java:62)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:812)
    at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:587)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
    at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:577)
    at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:223)
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1127)
    at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515)
    at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1061)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
    at org.eclipse.jetty.server.handler.RequestLogHandler.handle(RequestLogHandler.java:95)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
    at org.eclipse.jetty.server.Server.handle(Server.java:499)
    at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:311)
    at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:257)
    at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:544)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555)
    at java.lang.Thread.run(Unknown Source)
Caused by: 
net.sf.json.JSONException: JSONObject["update_seq"] is not a number.
    at net.sf.json.JSONObject.getDouble(JSONObject.java:2090)
    at net.sf.json.JSONObject.getInt(JSONObject.java:2109)
    at com.fourspaces.couchdb.Database.<init>(Database.java:50)
    at com.fourspaces.couchdb.Session.getDatabase(Session.java:185)
    at com.dbconnect.server.GreetingServiceImpl.greetServer(GreetingServiceImpl.java:22)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:587)
    at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:333)
    at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:303)
    at com.google.gwt.user.server.rpc.RemoteServiceServlet.processPost(RemoteServiceServlet.java:373)
    at com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet.doPost(AbstractRemoteServiceServlet.java:62)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:812)
    at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:587)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
    at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:577)
    at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:223)
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1127)
    at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515)
    at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1061)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
    at org.eclipse.jetty.server.handler.RequestLogHandler.handle(RequestLogHandler.java:95)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
    at org.eclipse.jetty.server.Server.handle(Server.java:499)
    at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:311)
    at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:257)
    at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:544)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555)
    at java.lang.Thread.run(Unknown Source)

/**********************************EDIT 1************************/ Link where mentioned about update_seq

  • The thing is we are not updating update_seq through our code its auto has done at the time of creation document in the database. So, don't know whats the issue.

  • Forgot to write that database is been created through java easily on CouchDB 2.0.

  • Do WE HAVE TO USE NEW VERSIONS OF JAR FILES>?COUCHDB JARS(USED AT TIME OF 1\COUCHDB 1.6

BehrouzMoslem
  • 9,053
  • 3
  • 27
  • 34
Vartika
  • 1,085
  • 3
  • 17
  • 43
  • I think the error pretty much says what the problem is. The updated UI is sending `update_seq` as string and the server which is still on 1.x server expecting long value. So updating the server to 2.x would be a good start. – s7vr Feb 25 '17 at 06:16
  • Sir, Already shifted to 2.0 and trying to do basic functions over there but unsuccessfull.We are not doing anything with the update_seq field its an auto generated field. value of update_seq field in the official doc of couchdb 2.0 is still showing int. I have posted the link. – Vartika Feb 25 '17 at 07:44
  • Did you update the server libraries to 2.0 too ? The jars in the screenshot you share – s7vr Feb 25 '17 at 07:45
  • I tried to update the couchdb4j jar but its still the same – Vartika Feb 25 '17 at 07:46

2 Answers2

2

The problem has to do with couchdb4j being old (last commit on github was nearly 5 years ago).

This post also states this an suggests using a client-library that's more actively worked on e.g. Ektorp (see CouchDB Java client).

Background on the couchbd4j-problem you are facing

The migration documentation you linked (https://blog.couchdb.org/2016/08/17/migrating-to-couchdb-2-0/) states:

Most importantly, the update seq, or sequence, is not a number any longer but a string.

As you said you do not deal with update_seq directly but couchdb4j does.

The current implementation of couchdb4j client-library parses the server-response-property update_seq as Integer using the following code:

updateSeq = json.getInt("update_seq");

And this will no longer work with CouchDb 2.0

Here's a link to the most recent code containing this line: https://github.com/mbreese/couchdb4j/blob/master/src/java/com/fourspaces/couchdb/Database.java (see line 59)

I hope this helped, Christian

Community
  • 1
  • 1
  • sorry, but still have some confusion. Are you telling me to use ektorp jar in place of couchb4j. As couchdb4j hasn't been updated from a long time. Pardon me , but didnt understood the answer clearly. How you want me to change the update_seq datatype – Vartika Mar 04 '17 at 06:41
  • sorry for not being fully clear on this. as of my investigation newest couchdb4j client-library and couchdb 2.0 are incompatible in the way the update_seq is handled. so you will need to switch over to another client-library. discussion on good client-libraries for couchdb can be found in the link i provided. – Christian Gintenreiter Mar 04 '17 at 07:50
  • Sorry sir, tried to search other library found cloudant but unable to use it, may be missing something. How will the code be like how we will create session, get databaase and create document? sorry – Vartika Mar 04 '17 at 10:53
  • In the CouchDB Java Client link I added to the answer there are several links to libraries. The following two seem pretty useful and are actively developed: https://github.com/helun/Ektorp/blob/master/README.md or http://lightcouch.org (see 'Get Started'). Then you can decide which one fits best for your needs. – Christian Gintenreiter Mar 04 '17 at 11:51
  • coudn't find a new client-library – Vartika Mar 07 '17 at 07:24
  • Does none of the mentioned client-libraries work for you? As I see it you have two options: 1) use another client-library 2) keep using CouchDB 1.6 – Christian Gintenreiter Mar 07 '17 at 16:40
  • at the time I am still using couchdb 1.6. I tried cloudant but wasn't able to use it perfectly. I will look into it again. – Vartika Mar 09 '17 at 06:27
0

Use matching or new version of jar files everywhere in client as well as server. One may do directory search for file versions. Clean and rebuild whole project to eliminate possibilities of old files being picked.

SACn
  • 1,862
  • 1
  • 14
  • 29