Creating a document in CouchDB 2.0 fauxton using Java

I created a default GWT project and tried to create a document in a simple record database using CouchDB as my database. We used to use CouchDB 1.6 ie futon as the user interface. Now, recently, I tried using CouchDB 2.0 ie Fauxton as a user interface.

PROBLEM: -

Unable to create document in CouchDB 2.0.

SERVER 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; } 

AN 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 update_seq is mentioned

  • The fact is that we do not update update_seq through our code, which it executed during the creation of the document in the database. So I don’t know what the problem is.

  • I forgot to write that the database was created using java easily on CouchDB 2.0.

  • SHOULD USE NEW JAR FILES VERSIONS>? COUCHDB JARS (USED IN TIME 1 \ COUCHDB 1.6

+5
source share
2 answers

The problem is that couchdb4j is old (the last commit on github was almost 5 years ago).

This post also says that this involves using a client library that is more active, for example. Ektorp (see CouchDB Java Client ).

Background on couchbd4j issue you are facing

Migration documentation related to you ( https://blog.couchdb.org/2016/08/17/migrating-to-couchdb-2-0/ ):

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

As you said, you are not dealing with update_seq directly, but couchdb4j does.

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

 updateSeq = json.getInt("update_seq"); 

And it 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)

Hope this helps, Christian

+2
source

Use a match or a new version of jar files everywhere on both the client and server. You can search directories for file versions. Clean and rebuild the entire project to eliminate the possibility of collecting old files.

0
source

Source: https://habr.com/ru/post/1264566/


All Articles