Connection error while connecting to cloudant DB from local

风格不统一 提交于 2019-12-06 08:22:56

The proxy settings you are using are for HTTP. When creating a CloudantClient using the account method it will use HTTPS over HTTP by default. Using a HTTPS proxy should solve your problem.

In your code above you appear to have used the system properties for http. As described in the JVM proxies documentation different system properties are required for the JVM wide proxy settings for http vs https. For https they are:

https.proxyHost
https.proxyPort

It is worth noting that you can also set a proxy specifically for use with the CloudantClient instead of using the system properties for the JVM wide proxy. For example:

CloudantClient client = ClientBuilder.account(user)
                                     .username(user)
                                     .password(password)
                                     .proxyURL(new URL("https://9.184.9.13"))
                                     .build();

I think this option should also work in the case that the proxy only has an http endpoint e.g. proxyURL(new URL("http://9.184.9.13")), but obviously in that case your communication would be unencrypted for the leg between the client and the proxy.

The proxy configuration worked for me only when set explicitly like this:

Authenticator authenticator = new Authenticator() {

                public PasswordAuthentication getPasswordAuthentication() {
                    return (new PasswordAuthentication(cloudantProxyUsername,
                            cloudantProxyPassword.toCharArray()));
                }
            };
            Authenticator.setDefault(authenticator);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!