admin管理员组文章数量:1405643
In the past I could read the current exchange rates provided by the European Central Bank as xml data with the following code. Also when entering the web address given in the code in a browser, the xml structure was nicely displayed.
But the behaviour changed recently:
- The code now throws a
javax.ssl.SSLHandshakeException:
PKIX path building failed:
Sun.security.provider.certpath.SunCertPathBuilderException:
unable to find valid certification path to requested target - When entering the web address in a browser, the xml file is no more displayed,
but immediately and automatically downloaded in the default download folder.
So I am looking for a way either - to provide the requested certification to java or
- to programatically initiate the download, for then I could read the data from the downloaded file.
There are several links in the web treating the certification, but to my understanding they are mostly tied to a specific framework or library. The solution most voted for on Stackoverflow is here, but I fail already at step 1, as Firefox doesn't show the lock icon, when entering an address ending with xml.
P.S.: I barely need to access web pages in my programming tasks; that's why I never had to care for certificates so far. If this becomes a must now to understand a suggested solution, any tutorial or other learning link is welcome.
import java.io.*;
import java.*;
public class ReadURLTest {
static String webAddress;
public static void main(String[] args) {
if (args.length==0)
webAddress= ".xml";
else
webAddress= args[0];
try {
URL url = new URI(webAddress).toURL();
InputStream in = url.openStream();
byte[] b = new byte[700];
int l= in.readNBytes(b, 0, b.length);
System.out.println(l);
in.close();
String s= new String(b, 0, l);
System.out.println(s);
} catch (MalformedURLException ex) {
System.err.println("Bad URL string: " + webAddress + "\n"+ex);
} catch (IOException ex) {
System.err.println("Error reading stream: " + ex);
} catch (URISyntaxException ex) {
System.err.println("Erroneous URI syntax: " + ex);
}
}
}
本文标签: javaReading ECB currency exchange rates from the webunable to find valid certificationStack Overflow
版权声明:本文标题:java - Reading ECB currency exchange rates from the web - unable to find valid certification - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744336769a2601234.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论