For some time now, I have been trying to extract data from the internet using technologies such as:
Problem
I never had a problem doing data extraction before. Everything always worked correctly. However, I'm suddenly starting to get the following error:
java.net.SocketException: java.security.NoSuchAlgorithmException: Error constructing implementation (algorithm: Default, provider: SunJSSE, class: sun.security.ssl.SSLContextImpl$DefaultSSLContext)
at java.base/javax.net.ssl.DefaultSSLSocketFactory.throwException(SSLSocketFactory.java:266)
at java.base/javax.net.ssl.DefaultSSLSocketFactory.createSocket(SSLSocketFactory.java:273)
at java.base/sun.net.www.protocol.https.HttpsClient.createSocket(HttpsClient.java:420)
at java.base/sun.net.NetworkClient.doConnect(NetworkClient.java:162)
at java.base/sun.net.www.http.HttpClient.openServer(HttpClient.java:497)
at java.base/sun.net.www.http.HttpClient.openServer(HttpClient.java:600)
at java.base/sun.net.www.protocol.https.HttpsClient.<init>(HttpsClient.java:265)
at java.base/sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:379)
at java.base/sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:189)
at java.base/sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1232)
at java.base/sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1120)
at java.base/sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:175)
at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:142)
at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:859)
at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:829)
at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:366)
at org.jsoup.helper.HttpConnection.get(HttpConnection.java:353)
at com.plua.jsoupteste.JSoupTest.main(JSoupTest.java:13)
Caused by: java.security.NoSuchAlgorithmException: Error constructing implementation (algorithm: Default, provider: SunJSSE, class: sun.security.ssl.SSLContextImpl$DefaultSSLContext)
at java.base/java.security.Provider$Service.newInstance(Provider.java:1900)
at java.base/sun.security.jca.GetInstance.getInstance(GetInstance.java:236)
at java.base/sun.security.jca.GetInstance.getInstance(GetInstance.java:164)
at java.base/javax.net.ssl.SSLContext.getInstance(SSLContext.java:184)
at java.base/javax.net.ssl.SSLContext.getDefault(SSLContext.java:110)
at java.base/javax.net.ssl.SSLSocketFactory.getDefault(SSLSocketFactory.java:83)
at java.base/javax.net.ssl.HttpsURLConnection.getDefaultSSLSocketFactory(HttpsURLConnection.java:334)
at java.base/javax.net.ssl.HttpsURLConnection.<init>(HttpsURLConnection.java:291)
at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.<init>(HttpsURLConnectionImpl.java:81)
at java.base/sun.net.www.protocol.https.Handler.openConnection(Handler.java:62)
at java.base/sun.net.www.protocol.https.Handler.openConnection(Handler.java:57)
at java.base/java.net.URL.openConnection(URL.java:1101)
at org.jsoup.helper.HttpConnection$Response.createConnection(HttpConnection.java:1020)
at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:856)
... 4 more
Caused by: java.security.KeyManagementException: problem accessing trust store
at java.base/sun.security.ssl.SSLContextImpl$DefaultManagersHolder.<clinit>(SSLContextImpl.java:942)
at java.base/sun.security.ssl.SSLContextImpl$DefaultSSLContext.<init>(SSLContextImpl.java:1112)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:78)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480)
at java.base/java.security.Provider.newInstanceUtil(Provider.java:155)
at java.base/java.security.Provider$Service.newInstance(Provider.java:1893)
... 17 more
This error is persistent and is displayed regardless of using any of the technologies listed above (JSoup, HtmlUnit, java.net.http, etc.). Even a simple code like the one shown below is causing this problem (in the example, JSoup was used for demonstration purposes only):
public static void main(String[] args) {
try {
Document doc = Jsoup.connect("https://en.wikipedia.org/").get();
System.out.println(doc.title());
Elements newsHeadlines = doc.select("#mp-itn b a");
for (Element headline : newsHeadlines) {
System.out.printf("%s\n\t%s",
headline.attr("title"), headline.absUrl("href"));
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
I am fully aware that this is a problem related to certificates, SSL, etc., something that unfortunately I am not able to solve on my own.
The problem is that I never messed with anything, any files, configuration, or anything that could make any changes compromising the application to work properly (at least, not that I'm aware of).
Desired Goal
I've already been looking on the internet for solutions for this type of exception, but my case has a very specific detail:
I am developing an application that will be used on home computers, that is, this data extraction application will need to be used by common people, who are not programmers, such as friends, family, etc.
I'm not sure if solving this certificate issue here on my personal computer (creating commands, applying JVM arguments, extracting and manipulating certificates, etc.), I would have to do the same on every computer the application will be distributed to (which would be a nightmare, and completely unfeasible in this case).
In summary: I want to be able to develop an application for extracting data from the internet, distribute it, and not need to do any configuration on the computers that will receive the application, after all, they would only need to have Java installed.
The graphical interface I'm doing using JavaFX, something I've been able to do before. My problem is extracting data, precisely because I'm ALWAYS getting this error.
Development Environment
- Eclipse IDE for Java Developers Version 2018-09 (4.9.0), Build id 20180917-1800
- JSoup 1.14.3
- JDK 16
- JRE 1.8.0_311