0

I'm working on a small java app that requests json data from an open online db, and I've run into the problem that the first URL has no issues having its stream opened (doesn't matter which URL I start with), but as soon as I try to use a second one I get "javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure".

I can't seem to find anything mentioning this on the internet, which seems kinda weird to me, so I wanted to actually ask how to do this properly, because I use Jackson to handle the incoming Json data, and while it has a method to just handle URLs, all that does is call openStream() which causes this problem. I'm using Java 11 for the record.

EDIT: Also forgot to mention it's a JavaFX application, if that could possibly be an issue

  • You are just getting an SSL classical error. As Jackson is poorly documented and you also didn't provide any code, maybe go to their mailing list asking for SSL sample code or configuration options. – Eugène Adell May 05 '21 at 07:04
  • The problem is not Jackson, I just mentioned it because it's what I wanted to use the URLs for. `InputStream stream1 = new URL(URL1).openStream(); InputStream stream2 = new URL(URL2).openStream();` Already doesn't work – The Intelligent One May 05 '21 at 07:49
  • As you said it seems not related to jackson, have you tried to download the json from browser or tools like curl ? – dariosicily May 05 '21 at 08:08
  • Could you try closing the URLConnection from the 1st URL before opening the connection with the 2nd URL and check if that works. Are the URLs public, can they be shared. – Ironluca May 05 '21 at 08:50
  • I can reach the json easily from the browser, and as I said, it doesn't matter which json I request, the first always works fine, but the second one gives the exception. @Ironluca What exactly do you mean by closing the URLConnection? The URLConnection class doesn't seem to have a close method or similar. I tried to close the first InputStream from the URL before, but that changed nothing, which is honestly surprising. I haven't dealt much with URL stuff before, so I don't know if I'm just being dumb here – The Intelligent One May 05 '21 at 09:51
  • @TheIntelligentOne, try using HttpsURLConnection (url.openConnection) and call disconnect on the connection to check if the problem persists. Alternatively you could try using Apache HTTP Component (https://hc.apache.org/httpcomponents-client-5.0.x/) and check. – Ironluca May 05 '21 at 10:48
  • 1
    If you are using 11.0.1 and talking to a server that requires SNI, could be same as https://stackoverflow.com/questions/53913758/java-11-https-connection-fails-with-ssl-handshakeexception-while-using-jsoup in which case my re-testing shows that 11.0.2 up fix this. – dave_thompson_085 May 05 '21 at 11:06
  • @Ironluca the url.openConnection method gives back a URLConnection object, which does not have a disconnect method (or anything I can see that would do anything similar) so I'm not able to do that. As for the Apache stuff, I guess I can try it with a bit of reading, but I'd like to figure out what the solution would be in native Java if it's possible, since it seems like it should work, and I'd like to minimize the amount of dependencies if possible as well – The Intelligent One May 05 '21 at 11:32
  • @dave_thompson_085 I'll try updating, because I don't know if the server requires SNI (or even what that is really) but I can see that I am using 11.0.1 – The Intelligent One May 05 '21 at 11:33
  • @dave_thompson_085 YES, updating worked. I guess it's a bug in 11.0.1. I updated to 11.0.11 and it works perfectly now, thank you – The Intelligent One May 05 '21 at 11:51
  • @TheIntelligentOne, great the problem got solved. Though not relevant for the problem, the URLConnection object as mentioned in your comment is actually an HttpsURLConnection. You could cast it and use the disconnect method. – Ironluca May 05 '21 at 15:09

1 Answers1

0

Thanks to @dave_thompson_085, I found out that it was an issue with Java 11.0.1 specifically, updating (to 11.0.11 in my case) solved the problem