• Post Reply Bookmark Topic Watch Topic
  • New Topic

java.net.ConnectException: Tried all: 1 addresses, but could not connect over HTTPS to server  RSS feed

 
Satej Koli
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Previously , we had following code in our application and it used to fetch the required data. We just used to read the required fields by forming a web-service URL by passing username , password and search parameter (DEA number). The same URL (with parameters) could also be hit from browser directly to see the results :



Now, the web-service URL has got changed from http to https with rest of the things same. The new URL also works from the browser. Moreover, even if I enter the http URL in the browser , it automatically redirects to https and shows the data. However, the above code is not doing the same and it gave following exception : java.net.ProtocolException: Unsupported protocol: https'

So, I changed the code to use https in the url, but now a new exception is coming - java.net.UnknownHostException. From the console log, I can see that the exception is coming at ==>document = parser.parse(strURL). Here , parser is a reference variable for a DocumentBuilderobject as you can see from the code above.

Then, I added the IP address of the website to the hosts file (Windows) as I am testing it currently on my local setup through Eclipse. Now , it's giving below exception: java.net.ConnectException: Tried all: 1 addresses, but could not connect over HTTPS to server: www.deanumber.com port: 443. Also, following code returns False: boolean res = java.net.InetAddress.getByName(url.getHost()).isReachable(10000);

Below is the complete stack trace for UnknownHostException for your reference:

 
Paul Clapham
Sheriff
Posts: 22713
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It looks like you're connecting to that URL via a proxy server. Since changing from HTTP to HTTPS leads to the problems you've documented there, then most likely the proxy server doesn't handle HTTPS requests properly. I'd recommend talking to somebody who knows about the proxy server, then. I assume that you aren't the one who set it up, right? Normally somebody in a company's network management area sets up a proxy server and then just tells people how to point their browsers to it.
 
Tim Holloway
Bartender
Posts: 18781
74
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Javadocs wrote:
Thrown to indicate that the IP address of a host could not be determined.


Check to see if you can resolve hostname www.deanumber.com on the failing machine. An easy way to test this is to use the "ping" command with that hostname.

If you cannot, either set up DNS for that machine to resolve www.deanumber.com or add www.deanumber.com and its IP address to the machines "hosts" file (/etc/hosts, if you're running Unix/Linux/MacOS).
 
Ron McLeod
Bartender
Posts: 1602
232
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For Windows, host file is: %WINDIR%\System32\drivers\etc\hosts
 
Satej Koli
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:It looks like you're connecting to that URL via a proxy server. Since changing from HTTP to HTTPS leads to the problems you've documented there, then most likely the proxy server doesn't handle HTTPS requests properly. I'd recommend talking to somebody who knows about the proxy server, then. I assume that you aren't the one who set it up, right? Normally somebody in a company's network management area sets up a proxy server and then just tells people how to point their browsers to it.


I have checked already. The proxy which my browser is using is same as the one used in my Java code. Strangely , the URL works from the browser but not from my web project.
 
Satej Koli
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Holloway wrote:
Javadocs wrote:
Thrown to indicate that the IP address of a host could not be determined.


Check to see if you can resolve hostname www.deanumber.com on the failing machine. An easy way to test this is to use the "ping" command with that hostname.

If you cannot, either set up DNS for that machine to resolve www.deanumber.com or add www.deanumber.com and its IP address to the machines "hosts" file (/etc/hosts, if you're running Unix/Linux/MacOS).


Thank you...But I have already mentioned in my question that I have tried it :

Then, I added the IP address of the website to the hosts file (Windows) as I am testing it currently on my local setup through Eclipse. Now , it's giving below exception: java.net.ConnectException: Tried all: 1 addresses, but could not connect over HTTPS to server: www.deanumber.com port: 443. Also, following code returns False: boolean res = java.net.InetAddress.getByName(url.getHost()).isReachable(10000);
 
Tim Holloway
Bartender
Posts: 18781
74
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry about that. You posted the stack trace for an issue you'd already addressed and it obscured the following part. I hadn't realized that the stack trace no longer applied. It's not easy for me to read coherently from a screen, which is why I encourage posts to be no longer (but no shorter!) than they need to be.

If you cannot connect, then either the target host isn't listening or it's blocked or there's no route to the host. The netstat command can be used to determine whether the port of interest is actually being listened on. Checking for a usable route can be done via the ping and traceroute commands.

Finding a blockage is a bit more difficult, as there are often multiple places where firewalls can be active - in the client computer, in one or more of the intervening routers, in the server, and even (in the case of proxies) between the proxy and its target. Also, of course, a mis-configured proxy can break the connectability chain.
 
Paul Clapham
Sheriff
Posts: 22713
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Satej Koli wrote:I have checked already. The proxy which my browser is using is same as the one used in my Java code. Strangely , the URL works from the browser but not from my web project.


Not totally strange. When I was at work I had to deal with issues like that -- one of them was that the site I was connecting to required authentication in a format which Java couldn't handle, but the browser could. That particular issue isn't your issue, I don't think, but anyway I'd suggest you get your networking people back and ask them to look at the interactions between your code and the proxy server and the problematic site. That may help you identify something you could change in your code (or configuration).
 
Tim Holloway
Bartender
Posts: 18781
74
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You provided the stack trace for the UnknownHostException, but you said you fixed that. What about the stack trace for the current exception?

Also, if your JVM is attempting to connect using one of the banned versions of TLS, you won't get an UnknownHostException, but you will fail to connect. An older JVM would have that problem.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!