Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NoSuchAlgorithm when calling Rest WebService

Tags:

java

rest

ssl

I have this piece of code that directly processes the response out of a REST client:

 uc = (HttpURLConnection) u.openConnection();
 uc.setConnectTimeout(2000);
 uc.setDoOutput(true);

 out = new OutputStreamWriter(uc.getOutputStream());
 out.write(posturl);
 out.flush();
 rd = new BufferedReader(new InputStreamReader(uc.getInputStream()));

When I run this code (actually it is a jar run my a BPEL within OpenESB) I get the following exception:

java.security.NoSuchAlgorithmException: Error constructing implementation (algorithm: Default, provider: SunJSSE, class: sun.security.ssl.SSLContextImpl$DefaultSSLContext) cause java.security.NoSuchAlgorithmException: Error constructing implementation (algorithm: Default, provider: SunJSSE, class: sun.security.ssl.SSLContextImpl$DefaultSSLContext)

I'm not sure what's happening here let alone solve it. I guess this is related to the endpoint being a HTTPs server. I have little experience myself with HTTPs so I'm not sure what's the cause or what to do to fix it.

Full StackTrace (or as full as OpenESB offers):

java.net.SocketException: java.security.NoSuchAlgorithmException: Error constructing implementation (algorithm: Default, provider: SunJSSE, class: sun.security.ssl.SSLContextImpl$DefaultSSLContext)
    at javax.net.ssl.DefaultSSLSocketFactory.throwException(SSLSocketFactory.java:198)
    at javax.net.ssl.DefaultSSLSocketFactory.createSocket(SSLSocketFactory.java:205)
    at sun.net.www.protocol.https.HttpsClient.createSocket(HttpsClient.java:361)
    at sun.net.NetworkClient.doConnect(NetworkClient.java:162)
    at sun.net.www.http.HttpClient.openServer(HttpClient.java:378)
    at sun.net.www.http.HttpClient.openServer(HttpClient.java:473)
    at sun.net.www.protocol.https.HttpsClient.<init>(HttpsClient.java:270)
    at sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:327)
    at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:191)
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:931)
    at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:177)
    at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1090)
    at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:250)
    at es.myapp.OpenAMRESTAuthentication.readURLResponse(OpenAMRESTAuthentication.java:157)
    at es.myapp.OpenAMRESTAuthentication.authenticate(OpenAMRESTAuthentication.java:60)
    at es.myapp.OpenAMRESTAuthentication.authenticate(OpenAMRESTAuthentication.java:94)
    at es.myapp.AuthSingleton.authenticate(AuthSingleton.java:82)
like image 908
MichelReap Avatar asked Jun 03 '26 21:06

MichelReap


1 Answers

Solved it! Thanks to @Daniel for pointing out to a similar answer, turns out my OpenESB had these startup parameters:

"-Djavax.net.ssl.keyStore=%OPENESB_HOME%/keystore.jks" "-Djavax.net.ssl.trustStore=%OPENESB_HOME%/cacerts.jks" -Djavax.net.ssl.keyStorePassword=changeit

Removed them and it works again :)

like image 127
MichelReap Avatar answered Jun 06 '26 11:06

MichelReap



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!