Java couchdb4j DB connection

I'm using couchdb4j to establish a connection with couchDB. It's working fine when im connecting to my local db, this is the code for that:

Session LocalSession= new Session("localhost", 5984);

But i'm trying to get a connection with this site: stockquotetest.cloudant.com but it's not working, can anybody spot the problem?

Session NewSession = new Session("stockquotetest.cloudant.com/", 5984, "user", "pass");

i'm getting this error: INFO: basic authentication scheme selected

I also get this

java.net.UnknownHostException: https
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at sun.security.ssl.SSLSocketImpl.connect(Unknown Source)
at sun.security.ssl.SSLSocketImpl.<init>(Unknown Source)
at sun.security.ssl.SSLSocketFactoryImpl.createSocket(Unknown Source)
at org.apache.commons.httpclient.protocol.SSLProtocolSocketFactory.createSocket(SSLProtocolSocketFactory.java:82)
at org.apache.commons.httpclient.protocol.SSLProtocolSocketFactory.createSocket(SSLProtocolSocketFactory.java:127)
at org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java:707)
at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:387)
at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:323)
at com.fourspaces.couchdb.Session.http(Session.java:364)
at com.fourspaces.couchdb.Session.get(Session.java:325)
at com.fourspaces.couchdb.Session.getDatabaseNames(Session.java:167)
at CouchDBTest.ConnectDB(CouchDBTest.java:41)
at Home$4.actionPerformed(Home.java:166)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

when I run this line of code:

        Session NewSession = new Session("https://user:pass@stockquotetest.cloudant.com/", 80, true);

Answers


I reproduced this and ran into another issue before I got it working. First, the 6-parameter constructor for Session is what you're after:

public Session(String host, int port, String user, String pass, boolean usesAuth, boolean secure) {

In the example you gave above, this would work:

new Session("stockquotetest.cloudant.com", 443, "user", "pass", true, true);

This is because if you don't set secure to true, the URL will not be constructed with https.


After that was working, the next error was the Database class assuming that update_seq is an int. Cloudant will return a String update_seq, not an integer. I altered the field, response parsing, and getter in the Database class from int to String to make the code work for me.


try this one ... make sure you are suing coucjdb4j lib for couchdb connection.

Session studentDbSession = new Session("localhost", 5984);

Database studentCouchDb = studentDbSession.getDatabase("database_name");

Hope this will help you.


Need Your Help

Disable fade for Bootstrap modal on tablet

javascript jquery css twitter-bootstrap

I've tried searching but haven't found any answers to this question. Wondering if there is a way to disable the fade/fade in only on tablets. I really like the effect but it's a bit glitchy on tabl...

"witadmin destroyid" command does not work with multiple ids

tfs tfs2013

Despite the documentation indicating that multiple work item IDs can be added in a comma-delimited list, whenever I try the following command I get an error: