gpt4 book ai didi

java - 为 SSLSocket 握手设置超时

转载 作者:太空宇宙 更新时间:2023-11-03 14:34:20 25 4
gpt4 key购买 nike

最近,我在使用 apache axis 1.4 的 SOAP 调用时遇到了问题。我已将超时设置为 30 秒,但有时会在抛出异常之前达到约 1000 秒。在探索axis的内部实现后,我发现这是由于SSLSocket握手。

请参阅下面的示例错误。

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)

是否可以在握手时设置超时?或者有没有别的办法强行切断连接。

另外,看代码中的握手部分

 sslSocket = sslFactory.createSocket(tunnel, host, port, true);
if (log.isDebugEnabled()) {
log.debug(Messages.getMessage("setupTunnel00",
tcp.getProxyHost(),
"" + tunnelPort));
}
}

((SSLSocket) sslSocket).startHandshake();

最佳答案

创建隧道时,调用:

tunnel.connect(new InetSocketAddress(host, port), 30000);

关于java - 为 SSLSocket 握手设置超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49441183/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com