5
votes

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

2
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
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
Did you update the server libraries to 2.0 too ? The jars in the screenshot you shares7vr
I tried to update the couchdb4j jar but its still the sameVartika

2 Answers

2
votes

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

0
votes

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.