我对授权的 ssl 连接有一个奇怪的问题。首先,我创建了使用授权 ssl 连接到外部服务器的 java 类。我已经在命令行中运行了这个类,它工作正常,从外部服务器获得所需的结果。在我在 JSP 页面中使用了这个类之后。重新启动后,我的 tomcat JSP 页面也得到了我想要的结果。但是在 10-15 个请求之后,JSP 页面给了我这个错误:“javax.net.ssl.SSLHandshakeException: Received fatal alert: 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")); %>
Tomcat版本:6.0.32
Java版本:1.6.0_21