I am using the CloudantClient libary to connect to Cloudant CouchDB. There are no exceptions thrown by this call. But after this, when I am making any call using CloudantClient, I am getting HttpHostConnectException
. I tried making calls like serverVersion
, getAllDbs
, etc. Here is the code:
cloudantClient = new CloudantClient(username, password);
//ConnectOptions options = new ConnectOptions();
//options.setProxyHost("myproxy.address.co.in");
//options.setProxyPort(8080);
//options.setConnectionTimeout(3000);
//options.setMaxConnections(100);
//options.setSocketTimeout(30000);
//cloudantClient = new CloudantClient(username, password, options);
//cloudantClient = new CloudantClient(username, password);
//cloudantClient = new CloudantClient(username, username, password);
//cloudantClient = new CloudantClient(url, username, password);
System.out.println("Connected to Cloudant");
System.out.println("Trying to fetch metadata from Cloudant");
System.out.println("Server Version: " + cloudantClient.serverVersion());
List<String> databases = cloudantClient.getAllDbs();
System.out.println("All my databases : ");
for ( String db : databases ) {
System.out.println(db);
}
I am running this code in Eclipse and the credentials are correct, as I can call successfully from browser rest client. Complete stack trace for the exception (I have replaced the acct/pwd in the log with acct string for security reasons):
Connected to Cloudant
Trying to fetch metadata from Cloudant
2015-07-29 10:07:39 DEBUG CouchDbClient:? - > GET /
2015-07-29 10:07:39 DEBUG RequestAddCookies:122 - CookieSpec selected: default
2015-07-29 10:07:39 DEBUG RequestAddCookies:167 - Cookie [version: 0][name: AuthSession][value: <Acct_PWD>][domain: <Account>.cloudant.com][path: null][expiry: null] match [(secure)<Account>.cloudant.com:443/]
2015-07-29 10:07:39 DEBUG RequestAuthCache:130 - Re-using cached 'basic' auth scheme for https://<Account>.cloudant.com:443
2015-07-29 10:07:39 DEBUG RequestAuthCache:144 - No credentials for preemptive authentication
2015-07-29 10:07:39 DEBUG PoolingHttpClientConnectionManager:249 - Connection request: [route: {s}->https://<Account>.cloudant.com:443][total kept alive: 0; route allocated: 0 of 2; total allocated: 0 of 20]
2015-07-29 10:07:39 DEBUG PoolingHttpClientConnectionManager:282 - Connection leased: [id: 0][route: {s}->https://<Account>.cloudant.com:443][total kept alive: 0; route allocated: 1 of 2; total allocated: 1 of 20]
2015-07-29 10:07:39 DEBUG MainClientExec:234 - Opening connection {s}->https://<Account>.cloudant.com:443
2015-07-29 10:07:40 DEBUG DefaultHttpClientConnectionOperator:131 - Connecting to <Account>.cloudant.com/184.173.103.226:443
2015-07-29 10:07:40 DEBUG SSLConnectionSocketFactory:335 - Connecting socket to <Account>.cloudant.com/184.173.103.226:443 with timeout 0
2015-07-29 10:08:01 DEBUG DefaultManagedHttpClientConnection:87 - http-outgoing-0: Shutdown connection
2015-07-29 10:08:01 DEBUG MainClientExec:128 - Connection discarded
2015-07-29 10:08:01 DEBUG DefaultManagedHttpClientConnection:79 - http-outgoing-0: Close connection
2015-07-29 10:08:01 DEBUG PoolingHttpClientConnectionManager:320 - Connection released: [id: 0][route: {s}->https://<Account>.cloudant.com:443][total kept alive: 0; route allocated: 0 of 2; total allocated: 0 of 20]
2015-07-29 10:08:01 DEBUG MainClientExec:143 - Cancelling request execution
Exception in thread "main" org.lightcouch.CouchDbException: Error executing request.
at org.lightcouch.CouchDbClientBase.executeRequest(Unknown Source)
at org.lightcouch.CouchDbClientBase.get(Unknown Source)
at org.lightcouch.CouchDbClientBase.get(Unknown Source)
at org.lightcouch.CouchDbClientBase.serverVersion(Unknown Source)
at com.cloudant.client.api.CloudantClient.serverVersion(Unknown Source)
at boss.metering.agent.connection.CloudantConnection.<init>(CloudantConnection.java:94)
at boss.metering.agent.connection.DBCommunicator.getCloudantConnection(DBCommunicator.java:33)
at boss.metering.agent.connection.DBCommunicator.main(DBCommunicator.java:26)
Caused by: org.apache.http.conn.HttpHostConnectException: Connect to <Account>.cloudant.com:443 [<Account>.cloudant.com/184.173.103.226] failed: Connection timed out: connect
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:151)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:353)
at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:380)
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184)
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:88)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:71)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:55)
... 8 more
Caused by: java.net.ConnectException: Connection timed out: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:345)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:337)
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:134)
... 17 more
What I can see in the exception trace is some IP address is getting appended to the URL: <Account>.cloudant.com/184.173.103.226
I am not sure how and when this IP is getting added in the URL. I am directly using the Java Cloudant Client API's.
Can anybody provide any pointers/inputs to resolve this issue?
Adding the updated code below for reference about all diff options i tried for connection -
Adding the stack trace when proxy is set in the ConnectOptions below . I have replaced the real account credentilas and proxy details with string for security resons. -
Connected to Cloudant
Trying to fetch metadata from Cloudant
2015-07-29 20:21:23 DEBUG CouchDbClient:? - > GET /
2015-07-29 20:21:23 DEBUG RequestAddCookies:122 - CookieSpec selected: default
2015-07-29 20:21:23 DEBUG RequestAddCookies:167 - Cookie [version: 0][name: AuthSession][value: <AccountPWD>][domain: <Account>.cloudant.com][path: null][expiry: null] match [(secure)<Account>.cloudant.com:443/]
2015-07-29 20:21:23 DEBUG RequestAuthCache:130 - Re-using cached 'basic' auth scheme for https://<Account>.cloudant.com:443
2015-07-29 20:21:23 DEBUG RequestAuthCache:144 - No credentials for preemptive authentication
2015-07-29 20:21:23 DEBUG PoolingHttpClientConnectionManager:249 - Connection request: [route: {tls}->http://<myproxy.co.in>:0->https://<Account>.cloudant.com:443][total kept alive: 0; route allocated: 0 of 100; total allocated: 0 of 100]
2015-07-29 20:21:23 DEBUG PoolingHttpClientConnectionManager:282 - Connection leased: [id: 0][route: {tls}->http://<myproxy.co.in>:0->https://<Account>.cloudant.com:443][total kept alive: 0; route allocated: 1 of 100; total allocated: 1 of 100]
2015-07-29 20:21:23 DEBUG MainClientExec:234 - Opening connection {tls}->http://<myproxy.co.in>:0->https://<Account>.cloudant.com:443
2015-07-29 20:21:23 DEBUG DefaultManagedHttpClientConnection:87 - http-outgoing-0: Shutdown connection
2015-07-29 20:21:23 DEBUG MainClientExec:128 - Connection discarded
2015-07-29 20:21:23 DEBUG DefaultManagedHttpClientConnection:79 - http-outgoing-0: Close connection
2015-07-29 20:21:23 DEBUG PoolingHttpClientConnectionManager:320 - Connection released: [id: 0][route: {tls}->http://<myproxy.co.in>:0->https://<Account>.cloudant.com:443][total kept alive: 0; route allocated: 0 of 100; total allocated: 0 of 100]
2015-07-29 20:21:23 INFO RetryExec:96 - I/O exception (org.apache.http.conn.UnsupportedSchemeException) caught when processing request to {tls}->http://<myproxy.co.in>:0->https://<Account>.cloudant.com:443: http protocol is not supported
2015-07-29 20:21:23 DEBUG RetryExec:103 - http protocol is not supported
org.apache.http.conn.UnsupportedSchemeException: http protocol is not supported
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:108)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:353)
at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:388)
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184)
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:88)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:71)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:55)
at org.lightcouch.CouchDbClientBase.executeRequest(Unknown Source)
at org.lightcouch.CouchDbClientBase.get(Unknown Source)
at org.lightcouch.CouchDbClientBase.get(Unknown Source)
at org.lightcouch.CouchDbClientBase.serverVersion(Unknown Source)
at com.cloudant.client.api.CloudantClient.serverVersion(Unknown Source)
at boss.metering.agent.connection.CloudantConnection.testCloudantDBConnection(CloudantConnection.java:284)
at boss.metering.agent.connection.CloudantConnection.<init>(CloudantConnection.java:90)
at boss.metering.agent.connection.DBCommunicator.getCloudantConnection(DBCommunicator.java:32)
at boss.metering.agent.connection.DBCommunicator.main(DBCommunicator.java:26)
2015-07-29 20:21:23 INFO RetryExec:112 - Retrying request to {tls}->http://<myproxy.co.in>:0->https://<Account>.cloudant.com:443
2015-07-29 20:21:23 DEBUG CouchDbClient:? - > GET /
2015-07-29 20:21:23 DEBUG RequestAddCookies:122 - CookieSpec selected: default
2015-07-29 20:21:23 DEBUG RequestAddCookies:167 - Cookie [version: 0][name: AuthSession][value: <AccountPWD>][domain: <Account>.cloudant.com][path: null][expiry: null] match [(secure)<Account>.cloudant.com:443/]
2015-07-29 20:21:23 DEBUG RequestAuthCache:130 - Re-using cached 'basic' auth scheme for https://<Account>.cloudant.com:443
2015-07-29 20:21:23 DEBUG RequestAuthCache:144 - No credentials for preemptive authentication
2015-07-29 20:21:23 DEBUG PoolingHttpClientConnectionManager:249 - Connection request: [route: {tls}->http://<myproxy.co.in>:0->https://<Account>.cloudant.com:443][total kept alive: 0; route allocated: 0 of 100; total allocated: 0 of 100]
2015-07-29 20:21:23 DEBUG PoolingHttpClientConnectionManager:282 - Connection leased: [id: 1][route: {tls}->http://<myproxy.co.in>:0->https://<Account>.cloudant.com:443][total kept alive: 0; route allocated: 1 of 100; total allocated: 1 of 100]
2015-07-29 20:21:23 DEBUG MainClientExec:234 - Opening connection {tls}->http://<myproxy.co.in>:0->https://<Account>.cloudant.com:443
2015-07-29 20:21:23 DEBUG DefaultManagedHttpClientConnection:87 - http-outgoing-1: Shutdown connection
2015-07-29 20:21:23 DEBUG MainClientExec:128 - Connection discarded
2015-07-29 20:21:23 DEBUG DefaultManagedHttpClientConnection:79 - http-outgoing-1: Close connection
2015-07-29 20:21:23 DEBUG PoolingHttpClientConnectionManager:320 - Connection released: [id: 1][route: {tls}->http://<myproxy.co.in>:0->https://<Account>.cloudant.com:443][total kept alive: 0; route allocated: 0 of 100; total allocated: 0 of 100]
2015-07-29 20:21:23 INFO RetryExec:96 - I/O exception (org.apache.http.conn.UnsupportedSchemeException) caught when processing request to {tls}->http://<myproxy.co.in>:0->https://<Account>.cloudant.com:443: http protocol is not supported
2015-07-29 20:21:23 DEBUG RetryExec:103 - http protocol is not supported
org.apache.http.conn.UnsupportedSchemeException: http protocol is not supported
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:108)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:353)
at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:388)
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184)
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:88)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:71)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:55)
at org.lightcouch.CouchDbClientBase.executeRequest(Unknown Source)
at org.lightcouch.CouchDbClientBase.get(Unknown Source)
at org.lightcouch.CouchDbClientBase.get(Unknown Source)
at org.lightcouch.CouchDbClientBase.serverVersion(Unknown Source)
at com.cloudant.client.api.CloudantClient.serverVersion(Unknown Source)
at boss.metering.agent.connection.CloudantConnection.testCloudantDBConnection(CloudantConnection.java:284)
at boss.metering.agent.connection.CloudantConnection.<init>(CloudantConnection.java:90)
at boss.metering.agent.connection.DBCommunicator.getCloudantConnection(DBCommunicator.java:32)
at boss.metering.agent.connection.DBCommunicator.main(DBCommunicator.java:26)
2015-07-29 20:21:23 INFO RetryExec:112 - Retrying request to {tls}->http://<myproxy.co.in>:0->https://<Account>.cloudant.com:443
2015-07-29 20:21:23 DEBUG CouchDbClient:? - > GET /
2015-07-29 20:21:23 DEBUG RequestAddCookies:122 - CookieSpec selected: default
2015-07-29 20:21:23 DEBUG RequestAddCookies:167 - Cookie [version: 0][name: AuthSession][value: <AccountPWD>][domain: <Account>.cloudant.com][path: null][expiry: null] match [(secure)<Account>.cloudant.com:443/]
2015-07-29 20:21:23 DEBUG RequestAuthCache:130 - Re-using cached 'basic' auth scheme for https://<Account>.cloudant.com:443
2015-07-29 20:21:23 DEBUG RequestAuthCache:144 - No credentials for preemptive authentication
2015-07-29 20:21:23 DEBUG PoolingHttpClientConnectionManager:249 - Connection request: [route: {tls}->http://<myproxy.co.in>:0->https://<Account>.cloudant.com:443][total kept alive: 0; route allocated: 0 of 100; total allocated: 0 of 100]
2015-07-29 20:21:23 DEBUG PoolingHttpClientConnectionManager:282 - Connection leased: [id: 2][route: {tls}->http://<myproxy.co.in>:0->https://<Account>.cloudant.com:443][total kept alive: 0; route allocated: 1 of 100; total allocated: 1 of 100]
2015-07-29 20:21:23 DEBUG MainClientExec:234 - Opening connection {tls}->http://<myproxy.co.in>:0->https://<Account>.cloudant.com:443
2015-07-29 20:21:23 DEBUG DefaultManagedHttpClientConnection:87 - http-outgoing-2: Shutdown connection
2015-07-29 20:21:23 DEBUG MainClientExec:128 - Connection discarded
2015-07-29 20:21:23 DEBUG DefaultManagedHttpClientConnection:79 - http-outgoing-2: Close connection
Exception in thread "main" org.lightcouch.CouchDbException: Error executing request.
at org.lightcouch.CouchDbClientBase.executeRequest(Unknown Source)
at org.lightcouch.CouchDbClientBase.get(Unknown Source)
at org.lightcouch.CouchDbClientBase.get(Unknown Source)
at org.lightcouch.CouchDbClientBase.serverVersion(Unknown Source)
at com.cloudant.client.api.CloudantClient.serverVersion(Unknown Source)
at boss.metering.agent.connection.CloudantConnection.testCloudantDBConnection(CloudantConnection.java:284)
at boss.metering.agent.connection.CloudantConnection.<init>(CloudantConnection.java:90)
at boss.metering.agent.connection.DBCommunicator.getCloudantConnection(DBCommunicator.java:32)
at boss.metering.agent.connection.DBCommunicator.main(DBCommunicator.java:26)
Caused by: org.apache.http.conn.UnsupportedSchemeException: http protocol is not supported
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:108)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:353)
at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:388)
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184)
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:88)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:71)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:55)
... 9 more
2015-07-29 20:21:23 DEBUG PoolingHttpClientConnectionManager:320 - Connection released: [id: 2][route: {tls}->http://<myproxy.co.in>:0->https://<Account>.cloudant.com:443][total kept alive: 0; route allocated: 0 of 100; total allocated: 0 of 100]
2015-07-29 20:21:23 INFO RetryExec:96 - I/O exception (org.apache.http.conn.UnsupportedSchemeException) caught when processing request to {tls}->http://<myproxy.co.in>:0->https://<Account>.cloudant.com:443: http protocol is not supported
2015-07-29 20:21:23 DEBUG RetryExec:103 - http protocol is not supported
org.apache.http.conn.UnsupportedSchemeException: http protocol is not supported
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:108)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:353)
at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:388)
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184)
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:88)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:71)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:55)
at org.lightcouch.CouchDbClientBase.executeRequest(Unknown Source)
at org.lightcouch.CouchDbClientBase.get(Unknown Source)
at org.lightcouch.CouchDbClientBase.get(Unknown Source)
at org.lightcouch.CouchDbClientBase.serverVersion(Unknown Source)
at com.cloudant.client.api.CloudantClient.serverVersion(Unknown Source)
at boss.metering.agent.connection.CloudantConnection.testCloudantDBConnection(CloudantConnection.java:284)
at boss.metering.agent.connection.CloudantConnection.<init>(CloudantConnection.java:90)
at boss.metering.agent.connection.DBCommunicator.getCloudantConnection(DBCommunicator.java:32)
at boss.metering.agent.connection.DBCommunicator.main(DBCommunicator.java:26)
2015-07-29 20:21:23 INFO RetryExec:112 - Retrying request to {tls}->http://<myproxy.co.in>:0->https://<Account>.cloudant.com:443
2015-07-29 20:21:23 DEBUG CouchDbClient:? - > GET /
2015-07-29 20:21:23 DEBUG RequestAddCookies:122 - CookieSpec selected: default
2015-07-29 20:21:23 DEBUG RequestAddCookies:167 - Cookie [version: 0][name: AuthSession][value: <AccountPWD>][domain: <Account>.cloudant.com][path: null][expiry: null] match [(secure)<Account>.cloudant.com:443/]
2015-07-29 20:21:23 DEBUG RequestAuthCache:130 - Re-using cached 'basic' auth scheme for https://<Account>.cloudant.com:443
2015-07-29 20:21:23 DEBUG RequestAuthCache:144 - No credentials for preemptive authentication
2015-07-29 20:21:23 DEBUG PoolingHttpClientConnectionManager:249 - Connection request: [route: {tls}->http://<myproxy.co.in>:0->https://<Account>.cloudant.com:443][total kept alive: 0; route allocated: 0 of 100; total allocated: 0 of 100]
2015-07-29 20:21:23 DEBUG PoolingHttpClientConnectionManager:282 - Connection leased: [id: 3][route: {tls}->http://<myproxy.co.in>:0->https://<Account>.cloudant.com:443][total kept alive: 0; route allocated: 1 of 100; total allocated: 1 of 100]
2015-07-29 20:21:23 DEBUG MainClientExec:234 - Opening connection {tls}->http://<myproxy.co.in>:0->https://<Account>.cloudant.com:443
2015-07-29 20:21:23 DEBUG DefaultManagedHttpClientConnection:87 - http-outgoing-3: Shutdown connection
2015-07-29 20:21:23 DEBUG MainClientExec:128 - Connection discarded
2015-07-29 20:21:23 DEBUG DefaultManagedHttpClientConnection:79 - http-outgoing-3: Close connection
2015-07-29 20:21:23 DEBUG PoolingHttpClientConnectionManager:320 - Connection released: [id: 3][route: {tls}->http://<myproxy.co.in>:0->https://<Account>.cloudant.com:443][total kept alive: 0; route allocated: 0 of 100; total allocated: 0 of 100]
2015-07-29 20:21:23 DEBUG MainClientExec:143 - Cancelling request execution