-2

i am trying to download from these url

"https://www.treasury.gov/ofac/downloads/sdn.xml" but it is saying that

"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"

I have tried below two,but it's not working 1. System.setProperty("com.sun.security.enableAIAcaIssuers","true"); 2. updated my java version from 1.7 to 1.8.0_121

download("https://www.treasury.gov/ofac/downloads/sdn.xml","D:\\AML_Files\\Download_Check\\sdnList.xml");

public static void download(String url, String fileName) throws Exception { 
//System.setProperty("com.sun.security.enableAIAcaIssuers","true");
try (InputStream in = URI.create(url).toURL().openStream()) {
            Files.copy(in, Paths.get(fileName));
        }
    }

i want to download xml file in my system and after that insert that xml file data to database table

KishanCS
  • 1,357
  • 1
  • 19
  • 38
Krish
  • 1
  • 3
  • So what exactly is the problem? Are you getting an error? The wrong result? – Mureinik Jan 21 '19 at 07:11
  • I am able to download file with your code. "download(url,"sdnList.xml");". So I guess this is not related to JRE. My Java version is "1.8.0_144" – Sagar Gandhi Jan 21 '19 at 07:15

1 Answers1

0

you need to add valid certificate in JRE.

vivekdubey
  • 484
  • 2
  • 7