aspose file tools*
The moose likes Java in General and the fly likes Downloading files from a HTTPS server Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Downloading files from a HTTPS server" Watch "Downloading files from a HTTPS server" New topic
Author

Downloading files from a HTTPS server

Pranabesh Sinha
Greenhorn

Joined: Aug 10, 2009
Posts: 5
Hi
I want to download a file from a server over https, I get the following error


javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Unknown Source)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.fatal(Unknown Source)
at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Unknown Source)
at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Unknown Source)
at com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(Unknown Source)
at com.sun.net.ssl.internal.ssl.ClientHandshaker.processMessage(Unknown Source)
at com.sun.net.ssl.internal.ssl.Handshaker.processLoop(Unknown Source)

I have the URL of the file and I use URLConnection.

Thanks
Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
Hello,

please put code, stacktraces etc. in code tags.

Try this approach:



JDBCSupport - An easy to use, light-weight JDBC framework -
Pranabesh Sinha
Greenhorn

Joined: Aug 10, 2009
Posts: 5
Hi,
Here is a code that I copied from the web



Because of line 33 I get this error


Now the reason for this error is of course that the certificate sent by my server is not already in my list of trusted certificates.
My question is how to get the certificate into the trusted list.

Thanks
Pranabesh Sinha
Greenhorn

Joined: Aug 10, 2009
Posts: 5
Hi
I made a mistake in the earlier post, the error occurs due to line 33 not 29.

Thanks
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19696
    
  20

And what happens if you try to connect using URL, URLConnection and HttpsURLConnection as Sebastian suggested?


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Sunny X Narula
Greenhorn

Joined: Dec 07, 2008
Posts: 22
Hand shake exception is caused due to java not being to handle SSL connections by default.
As per my understanding when you open a secure internet connection over https you need to exchange certificates which the server uses to identify the caller and so that the security of the transferred information can be ensured.
Also this is a session specific thing.
I have had the problem when working with websphere and these are the settings I do to solve it.



You need to know who you are talking to and use an appropriate handler. May be there is some sort of generic handler that can be used for all https connections.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Downloading files from a HTTPS server