为 SSLSocket 握手设置超时 [英] Placing timeout for SSLSocket handshake
本文介绍了为 SSLSocket 握手设置超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
最近,我在使用 apache 轴 1.4 的 SOAP 调用时遇到了问题.我已将超时设置为 30 秒,但有时会在引发异常之前达到约 1000 秒.在探索axis的内部实现后,我发现这是由于SSLSocket握手造成的.
Recently, I am having trouble with our SOAP calls which uses apache axis 1.4. I have set the timeout as 30s, however it sometimes reaches around ~1000s before throwing an exception. After exploring internal implementation of axis, I found out that it is due to the SSLSocket handshake.
请参阅下面的示例错误.
See sample error below.
java.net.SocketException: Connection timed out (Read failed)
at java.net.SocketInputStream.$$YJP$$socketRead0(Native Method)
at java.net.SocketInputStream.socketRead0(SocketInputStream.java)
at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
at java.net.SocketInputStream.read(SocketInputStream.java:171)
at java.net.SocketInputStream.read(SocketInputStream.java:141)
at sun.security.ssl.InputRecord.readFully(InputRecord.java:465)
at sun.security.ssl.InputRecord.read(InputRecord.java:503)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:983)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1385)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1413)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1397)
at org.apache.axis.components.net.JSSESocketFactory.create(JSSESocketFactory.java:186)
是否可以在握手中设置超时?或者有没有别的办法强行切断连接.
Is it possible to put a timeout also on the handshake? Or is there another way to forcibly cut the connection.
另见代码中的握手部分
sslSocket = sslFactory.createSocket(tunnel, host, port, true);
if (log.isDebugEnabled()) {
log.debug(Messages.getMessage("setupTunnel00",
tcp.getProxyHost(),
"" + tunnelPort));
}
}
((SSLSocket) sslSocket).startHandshake();
推荐答案
创建tunnel
时,调用tunnel.connect(new InetSocketAddress(host, port), 30000);代码>
这篇关于为 SSLSocket 握手设置超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文