关于weblogic下使用URL.openConnection获取连接返回javax.net.ssl.SSLKeyException错误

来源:互联网 发布:编程教程学习 编辑:程序博客网 时间:2024/05/16 17:11

本文主要记录如果解决weblogic使用URL.openConnection出现javax.net.ssl.SSLKeyException: [Security:090504]。。。。。。。的异常,tomcat下一切正常。

在解决问题之前查看了http://blog.csdn.net/arvinrong/article/details/7715334和http://winters1224.blog.51cto.com/3021203/1313111这两篇文章的建议(感谢两位作者),原因这两位分析的很清晰了,最终采用一种简单的方式(无须修改weblogic代理配置),如下:


  1. URL url = new URL(null,urlStr,new sun.net.www.protocol.https.Handler());//重点在这里,需要使用带有URLStreamHandler参数的URL构造方法  
  2. HttpsURLConnection httpConnection = (HttpsURLConnection) url.openConnection();//由于我调用的是官方给微信API接口,所以采用HTTPS连接  
  3. int responseCode = httpConnection.getResponseCode();  
  4. if (responseCode == HttpURLConnection.HTTP_OK) {  
  5.     InputStream urlStream = httpConnection.getInputStream();  
  6.     BufferedReader bufferedReader = new BufferedReader(  
  7.             new InputStreamReader(urlStream));  
  8.     String lineStr = "";  
  9.     while ((lineStr = bufferedReader.readLine()) != null) {  
  10.         ......  
  11.     }  
  12.     .....  


0 0
原创粉丝点击