这个ibmjdk1.3版本让我上个星期也够郁闷的了,搞好久。原以为,都是一样的接口,谁实现都一样,可是就是不一样,在ibm的jdk上配置sun的jsse就是不行,死活不行。
不过ibm也是够恶心的,官方网站上根本没有提供JSSE包的下载,反倒有也是指向sun公司的下载地址,误导了我好长时间!最后实在是没有办法了,抱着试试看的心态找看看ibm的jsse。自己的机器也没有安装websphere,想websphere应该有jsse相关的包,通过友人获取该包,并部署在jvm/lib/ext目录下,竟然成功了!
状态1-》n、使用sun的jsse类包,汗,尝试n种方法以失败告终!
java.net.MalformedURLException: unknown protocol: https
System.setProperty("java.protocol.handler.pkgs", "com.ibm.net.ssl.internal.www.protocol");
java.net.SocketException: Algorithm SSL not available 使用ibmjsse.jar
------------------------
状态n+1、unknown certificate系统已经成功配置了JSSE环境,缺乏证书
异常消息:
javax.net.ssl.SSLHandshakeException: unknown certificate
at com.ibm.jsse.bf.a(Unknown Source)
at com.ibm.jsse.bf.startHandshake(Unknown Source)
at com.ibm.net.ssl.www.protocol.https.b.n(Unknown Source)
at com.ibm.net.ssl.www.protocol.https.p.connect(Unknown Source)
at com.ibm.net.ssl.www.protocol.http.bw.getOutputStream(Unknown Source)
at com.ibm.net.ssl.internal.www.protocol.https.HttpsURLConnection.getOutputStream(Unknown Source)
at com.longtop.security.URLReader.main(URLReader.java:29)
Exception in thread "main"
解决方法:
1、往信任库里添加证书
keytool -import -noprompt -keystore cacerts -storepass changeit -alias xyhuang-longtop-ks -file xyhuang.cer
2、修改实现自动接受证书(安全风险)X509TrustManager
以下为最终的连接代码
System.setProperty("java.protocol.handler.pkgs",
"com.ibm.net.ssl.internal.www.protocol");
if (Security.getProvider("com.ibm.jsse.IBMJSSEProvider") == null)
Security.addProvider(new IBMJSSEProvider());
URL url = new URL("https://msxyhuang.xyhuang.com:443/cas1/index.asp");
String poststr = "name=new&ccc=ddd";
URLConnection conn = url.openConnection();
if (conn == null) {
return;
}
conn.setDoOutput(true);
PrintStream pout = new PrintStream(conn.getOutputStream());
pout.print(poststr);
pout.close();
BufferedReader reader = new BufferedReader(new InputStreamReader(conn
.getInputStream()));
String line = null;
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
reader.close();
输出结果:huangxinyi
asp的代码
<%@ Language=VBScript %>
<%
Dim name
Set name = Request.Form("name")
if name = "new" then
Response.write "huangxinyi"
elseif name = null or name = "" then
Response.write "null"
else
Response.write "bluelover"
end if
%>