调用Rest WebService时的NoSuchAlgorithm

时间:2016-02-02 11:47:37

标签: java rest ssl

我有这段代码直接处理REST客户端的响应:

 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()));

当我运行此代码时(实际上它是一个jar在OpenESB中运行我的BPEL)我得到以下异常:

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)

我不确定这里发生了什么,更不用说解决它了。我想这与端点是HTTPs服务器有关。我对自己的HTTP很少有经验,所以我不确定原因是什么,或者做些什么来解决它。

Full StackTrace(或者像OpenESB提供的那样完整):

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)

1 个答案:

答案 0 :(得分:0)

解决了!感谢@Daniel指出类似的答案,结果我的OpenESB有这些启动参数:

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

删除它们并再次起作用:)