I'm attempting to download the content of https://slashdot.org/ with this code :
scala.io.Source.fromURL("https://slashdot.org/", "ISO-8859-1").mkString
This throws exception :
Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at sun.security.validator.PKIXValidator.doBuild(Unknown Source)
at sun.security.validator.PKIXValidator.engineValidate(Unknown Source)
at sun.security.validator.Validator.validate(Unknown Source)
To fix I export the certificate from https://slashdot.org/ via Chrome. I assign alias 'slashdot' and name the vert file 'cert'. I install using command
keytool -import -trustcacerts -keystore cacerts -storepass changeit -noprompt -alias slashdot -file cert.cer The certificate is imported successfully but same exception is thrown when I attempt to save URL :
scala.io.Source.fromURL("https://slashdot.org/", "ISO-8859-1").mkString
Have I missed a step installing the cert ?
Do I need to specify the "Certification path" as part of downloading the content as specified for the https://slashdot.org/ cert :
Update :
I thought this could be related to my Scala setup but Java code below throws same error :
import java.io.InputStream;
import java.nio.file.Files;
import java.net.URL;
import java.nio.file.StandardCopyOption;
import java.nio.file.Path;
public class download {
public static void main(String args[]) throws Exception{
URL website = new URL("https://slashdot.org/");
Path target = new java.io.File("c:\\download\\myfile.txt").toPath();
try (InputStream in = website.openStream()) {
Files.copy(in, target, StandardCopyOption.REPLACE_EXISTING);
}
}
}