收到致命警报:JSP 页面中出现握手失败错误
我在授权 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", "密码")); %>
Tomcat版本:6.0.32
Java版本:1.6.0_21
I have a strange problem with authorized ssl connection. First I have created java class that connects to external server with authorized ssl. I've run this class in command line it works fine, gets desired results from external server. After I've use this class in JSP page. After reboot my tomcat JSP page gets me desired results, too. But after 10-15 requests JSP page gives me this error: "javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure ". No more desired results in JSP page.
Here is method in java class code:
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+"";
}
}
Calling from JSP page: <%
fsb fsb = new fsb();
out.println(fsb.TransHttpsAuth("https://ext_server","prameters","GET", "jks_path", "password"));
%>
Tomcat version: 6.0.32
Java version: 1.6.0_21
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要在 jre 中添加服务器证书并重新启动 tomcat 才能使用 java 进行连接。在 Web 上查找 InstallCert.java。
You will need to add the server certificate in your jre and restart tomcat in order to connect using java. Look for InstallCert.java on the web.