2

Here's the Code in Question

        //dvntUrl is any web API that returns a .json, eg:https://backend.deviantart.com/oembed?url=http%3A%2F%2Ffav.me%2Fd2enxz7
        URL dURL = new URL(dvntUrl);
        HttpURLConnection con = (HttpURLConnection) dURL.openConnection();
    
        con.setRequestMethod("GET");

        Scanner s= new Scanner(dURL.openStream());

Here's the Error Stack Trace

java.lang.NoSuchMethodError: sun.security.ssl.Handshaker.setApplicationProtocols([Ljava/lang/String;)V
at sun.security.ssl.SSLSocketImpl.initHandshaker(SSLSocketImpl.java:1350)
at sun.security.ssl.SSLSocketImpl.doneConnect(SSLSocketImpl.java:708)
at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:687)
at sun.security.ssl.BaseSSLSocketImpl.connect(BaseSSLSocketImpl.java:173)
at sun.net.NetworkClient.doConnect(NetworkClient.java:180)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:463)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:558)
at sun.net.www.protocol.https.HttpsClient.<init>(HttpsClient.java:264)
at sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:367)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:191)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1162)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1056)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:177)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1570)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1498)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:268)
at java.net.URL.openStream(URL.java:1068)
at API_Processors.apiPrccsr.getSrcForDeviation(apiPrccsr.java:36)
at Servlets.entry_page_gen.fillEntryTemplate(entry_page_gen.java:213)
at Servlets.entry_page_gen.getEntryPage(entry_page_gen.java:173)
at Servlets.entry_page_gen.processRequest(entry_page_gen.java:59)
at Servlets.entry_page_gen.doGet(entry_page_gen.java:89)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:645)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:750)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1540)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:217)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:119)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:611)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:550)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:114)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:332)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:199)
at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:463)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:168)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:206)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:180)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:242)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:539)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:593)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:573)
at java.lang.Thread.run(Thread.java:748)

From what I read, it could be an error caused due to a different library being used during run time and compile time. But how do I fix it?

I've read through This Question. However, No clear method for fixing the error was shown.

If more info is needed, Please do ask.

ORAS
  • 39
  • 3
  • What value does `dvntUrl` have? – Jeff Scott Brown Nov 30 '20 at 20:10
  • In the code I use, it links to the devaintART API, so it's value could be `https://backend.deviantart.com/oembed?url=http%3A%2F%2Ffav.me%2Fd2enxz7` But it could link to any web API that returns a .json. I've updated the question to reflect the same. – ORAS Nov 30 '20 at 20:33
  • no pom xml or build gradle ? – ozkanpakdil Nov 30 '20 at 21:03
  • 2
    Does this question help? https://stackoverflow.com/questions/62158828/ – Luke Woodward Nov 30 '20 at 21:32
  • "But it could link to any web API that returns a .json." - It looks like what the API is returning may be irrelevant to your error. Your error is happening while attempting to connect to the service. – Jeff Scott Brown Nov 30 '20 at 21:34
  • @LukeWoodward It removes the current error, but another error takes it's place, namely: `Severe: 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` – ORAS Dec 01 '20 at 11:48
  • @JeffScottBrown yes, The API doesn't matter, `dURL.openConnection` is throwing the error. – ORAS Dec 01 '20 at 12:06
  • @ORAS: that's progress. You've now got a problem regarding certificate trust: basically, the Java trust store doesn't contain the certificate(s) your endpoint is using. Without knowing your setup I can't help any more than that. There are plenty of other search results for that error message, hopefully one of those will help you. – Luke Woodward Dec 01 '20 at 19:30
  • Yes, Thanks for your help, I looked around and managed to find a way to fix the issue, I'll keep the question open, in case someone else knows a way to fix the issue without the ssl errors – ORAS Dec 09 '20 at 10:48

0 Answers0