java couchdb4j DB连接 [英] Java couchdb4j DB connection

查看:355
本文介绍了java couchdb4j DB连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用couchdb4j建立与couchDB的连接。当我连接到我的本地数据库,这是工作正常,这是代码:

  Session LocalSession = new Session ,5984); 

但我想尝试与此网站建立连接:stockquotetest.cloudant.com但不是

  Session NewSession = new Session(stockquotetest.cloudant.com/,5984,用户,通过); 

我收到此错误:INFO:选择基本身份验证方案



我也得到这个

  java.net.UnknownHostException:https: .AbstractPlainSocketImpl.connect(未知源)
在java.net.PlainSocketImpl.connect(未知源)
在java.net.SocksSocketImpl.connect(未知源)
在java.net.Socket 。未知来源)
at sun.security.ssl.SSLSocketImpl.connect(未知来源)
at sun.security.ssl.SSLSocketImpl。< init>(未知来源)
sun.security.ssl.SSLSocketFactoryImpl.createSocket(未知源)
在org.apache.commons.httpclient.protocol.SSLProtocolSocketFactory.createSocket(SSLProtocolSocketFactory.java:82)
在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)
在org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171)
在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)
在CouchDBTest.ConnectDB CouchDBTest.java:41)
at Home $ 4.actionPerformed(Home.java:166)
在javax.swing.AbstractButton.fireActionPerformed(未知来源)
at javax.swing.AbstractButton $ Handler .actionPerformed(未知源)
at javax.swing.DefaultButtonModel.fireActionPerformed(未知源)
at javax.swing.DefaultButtonModel.setPressed(未知源)
at javax.swing.plaf.basic .basicButtonListener.mouseReleased(未知源)
at java.awt.Component.processMouseEvent(未知源)
at javax.swing.JComponent.processMouseEvent(未知源)
at java.awt.Component .processEvent(未知源)
at java.awt.Container.processEvent(未知源)
at java.awt.Component.dispatchEventImpl(未知源)
at java.awt.Container.dispatchEventImpl (未知源)
at java.awt.Component.dispatchEvent(未知源)
at java.awt.LightweightDispatcher.retargetMouseEvent(未知源)
at java.awt.LightweightDispatcher.processMouseEvent源)
at java.awt.LightweightDispatcher.dispatchEvent(未知源)
at java.awt.Container.dispatchEventImpl(未知源)
at java.awt.Window.dispatchEventImpl(未知源)
at java.awt.Component.dispatchEvent(未知源)
at java.awt.EventQueue.dispatchEventImpl(未知源)
at java.awt.EventQueue.access $ 200(未知源)
at java.awt.EventQueue $ 3.run(未知源)
at java.awt.EventQueue $ 3.run(未知源)
at java.security.AccessController.doPrivileged(Native方法)
at java.security.ProtectionDomain $ 1.doIntersectionPrivilege(未知源)
at java.security.ProtectionDomain $ 1.doIntersectionPrivilege(未知源)
at java.awt.EventQueue $ 4.run(未知源)
at java.awt.EventQueue $ 4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native方法)
at java.security.ProtectionDomain $ 1.doIntersectionPrivilege(未知来源)
at java.awt.EventQueue.dispatchEvent(未知源)
at java.awt.EventDispatchThread.pumpOneEventForFilters(未知源)
at java.awt.EventDispatchThread.pumpEventsForFilter(未知源)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(未知源)
at java.awt.EventDispatchThread.pumpEvents(未知源)
at java.awt.EventDispatchThread.pumpEvents(未知源)
当我运行这行代码时,在java.awt.EventDispatchThread.run(Unknown Source)



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


解决方案

它工作。首先, 6参数构造函数会话 是您接下来的内容:

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

在上面给出的示例中,这将工作:

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

这是因为如果您没有设置 secure 设置为true,则 URL不会使用https 构建。






之后,下一个错误是数据库 class 假设 update_seq 是一个int 。 Cloudant将返回一个字符串 update_seq ,而不是一个整数。我改变了数据库类中的字段,响应解析和getter从 int String 让代码适用于我。


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);

解决方案

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.

这篇关于java couchdb4j DB连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆