Reputation: 145
I'm using couchdb4j to establish a connection with couchDB, just like the user in the topic: Java couchdb4j DB connection
So locally I am able to connect to couchdb by just using:
Session LocalSession= new Session("localhost", 5984);
But when I am trying to use my company's couchdb version, it does not function.. and I get this error: (NB I have the admin role)
avr. 02, 2015 5:31:04 PM com.fourspaces.couchdb.Session createDatabase
Avertissement: Error creating database: mydatabase
Exception in thread "main" java.lang.NullPointerException
at filecomparison.DbaseManag.saveFinalDocument(DbaseManag.java:359)
at filecomparison.DbaseManag.saveEntryQueryLog(DbaseManag.java:247)
at filecomparison.LoadFiles.loadVirtuosoLog(LoadFiles.java:207)
at filecomparison.LoadFiles.loadingQueryLog(LoadFiles.java:772)
at filecomparison.Main.main(Main.java:197)
In the "couchdb4j" library I observed that there were 4 diiferent versions of the Session constructor (but there was not a version which uses the parameter boolean usesAuth):
public Session(String host, int port, boolean secure)
public Session(String host, int port)
public Session(String host, int port, String user, String pass, boolean secure)
public Session(String host, int port, String user, String pass)
Anyway, I tried to use them all but it didn't worked (even if the Session object was created)
I tried also to see what was printed in the Server's log, while I was running my java code, by using the command:
tail -f /var/log/couchdb/couch.log
And I realized that there was always the same error:
[Tue, 07 Apr 2015 14:07:29 GMT] [debug] [<0.1738.0>] 'DELETE' /mydatabase {1,1} from "127.0.0.1"
Headers: [{'Host',"127.0.0.1:5984"},
{'User-Agent',"Jakarta Commons-HttpClient/3.1"}]
[Tue, 07 Apr 2015 14:07:29 GMT] [debug] [<0.1738.0>] OAuth Params: []
[Tue, 07 Apr 2015 14:07:29 GMT] [debug] [<0.1738.0>] Minor error in HTTP request: {unauthorized,
<<"You are not a server admin.">>}
After searching a while I saw some solutions of this authentication issue with use of curl commands, just like this topic open CouchDB session with admin server credential. E.g.
curl -X DELETE http://username:password@localhost:5984/mydatabase
But has anyone an idea how to solve with my java code? Should I change the library or it is an issue of couchdb configuration?
Thanks in advance for any tip!
Regards
Upvotes: 0
Views: 623
Reputation: 1225
As you have shown with your log line quote - no authentication informations are sent by your java code. You can compare these log lines with the log lines that occurring in result of your curl
request. There should be e.g. an Auth or Cookie header present.
You say that the identical code succeeds/fails depending on the CouchDB target? Then it may it worth to compare the authentication handler configuration of both CouchDB installations. Maybe the authentication method your library is using is not handled in the remote CouchDB.
Upvotes: 1