我对授权的ssl连接有一个奇怪的问题。首先,我创建了使用授权的ssl连接到外部服务器的java类。我在命令行中运行此类它工作正常,从外部服务器获得所需的结果。我在JSP页面中使用此类之后。重新启动后,我的tomcat JSP页面也得到了我想要的结果。但是在10-15次请求之后,JSP页面给了我这个错误:“javax.net.ssl.SSLHandshakeException:收到致命警报:handshake_failure”。在JSP页面中没有更多期望的结果。
这是java类代码中的方法:
public String TransHttpsAuth(String server, String param, String method, String jksPath, String jksPass)
{
try
{
System.setProperty("javax.net.ssl.keyStoreType", "jks");
System.setProperty("javax.net.ssl.keyStore", jksPath);
System.setProperty("javax.net.ssl.keyStorePassword", jksPass);
server=server+"/?"+ param;
URL url = new URL(server);
HttpsURLConnection httpurlconnection = (HttpsURLConnection)url.openConnection();
httpurlconnection.setHostnameVerifier(new NullHostnameVerifier());
httpurlconnection.setRequestMethod(method);
httpurlconnection.setDoOutput(true);
httpurlconnection.connect();
InputStreamReader in = new InputStreamReader((InputStream) httpurlconnection.getContent());
BufferedReader buff = new BufferedReader(in);
String line = buff.readLine();
StringBuffer text = new StringBuffer();
while (line != null) {
text.append(line + "\n");
line = buff.readLine();
}
System.out.println(text.toString());
httpurlconnection.disconnect();
return text.toString();
}
catch(Exception exception)
{
return exception+"";
}
}
从JSP页面调用:<%
fsb fsb = new fsb();
out.println(fsb.TransHttpsAuth(“https:// ext_server”,“prameters”,“GET”,“jks_path”,“password”));
%GT;
Tomcat版本:6.0.32
Java版本:1.6.0_21
答案 0 :(得分:1)
您需要在jre中添加服务器证书并重新启动tomcat才能使用java进行连接。在网上寻找InstallCert.java。