在尝试与我们的服务器建立SSL连接时,我们在IBM AIX上经常看到以下异常:
java.net.SocketException: Socket closed
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.a(DashoA6275(Compiled Code))
at com.sun.net.ssl.internal.ssl.AppOutputStream.write(DashoA6275(Compiled Code))
at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java(Inlined Compiled Code))
at java.io.BufferedOutputStream.flush(BufferedOutputStream.java(Compiled Code))
at java.io.FilterOutputStream.flush(FilterOutputStream.java(Compiled Code))
at org.apache.commons.httpclient.methods.EntityEnclosingMethod.writeRequestBody(EntityEnclosingMethod.java(Compiled Code))
at org.apache.commons.httpclient.HttpMethodBase.writeRequest(HttpMethodBase.java(Compiled Code))
at org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java(Compiled Code))
at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java(Compiled Code))
at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java(Compiled Code))
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java(Compiled Code))
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java(Inlined Compiled Code))
at com.eximtechnologies.httptransport.client.ClientTransport.receiveMessages(ClientTransport.java(Compiled Code))
at com.eximtechnologies.httptransport.client.ClientTransport.receiveMessages(ClientTransport.java(Inlined Compiled Code))
at com.eximtechnologies.ecserver.connection.XMSHTTPConnection.checkForNewMessages(XMSHTTPConnection.java(Compiled Code))
at com.eximtechnologies.ecserver.connection.XMSHTTPConnection.timeoutExpired(XMSHTTPConnection.java(Compiled Code))
at com.eximtechnologies.xmd.timer.TimerEvent$1.run(TimerEvent.java(Compiled Code))
从错误中,你会认为这只是一个网络问题,但客户从未在大约2个月前遇到过这个问题,而AFAIK,网络布局没有任何变化.
我们也经常收到这个:
java.net.SocketException: Connection timed out:could be due to invalid address
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:336)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:201)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:188)
at java.net.Socket.connect(Socket.java:478)
at java.net.Socket.connect(Socket.java:428)
at java.net.Socket.<init>(Socket.java:335)
at java.net.Socket.<init>(Socket.java:210)
at javax.net.ssl.SSLSocket.<init>(Unknown Source)
我怀疑这是一个AIX问题,但我想这可能是防火墙问题?我还看到谷歌搜索中的一些人暗示公共http的问题,但我看不出这是如何相关的.
这是其他人最近在AIX上看到过的吗?
解决方法:
“java.net.SocketException:Socket closed”意味着你的一方关闭了套接字.您说当您尝试与服务器建立SSL连接时会发生这种情况.但是,堆栈跟踪表明当HTTPClient尝试通过已建立的连接写入HTTP请求时会发生这种情况.
例如,如果您以某种方式设法使HTTPClient通过之前由HTTPClient关闭的连接发送请求,或者更有可能是您身边的其他代码,则可能会发生这种情况.检查您是否在某处访问底层套接字.或者可能是套接字被SSL / TLS协议关闭(如果我没弄错,SSL / TLS有自己的更高级协议来关闭底层连接),但HTTPClient以某种方式设法不注意到这一点(不要不知道是否可能,但是,比方说,远程端关闭了SSL连接,但是使用了HTTP / 1.1持久连接并没有设置Connection:close响应.
您可以使用tcpdump / Wireshark分析TCP流量来解决这些问题.您还可以在计算机上启动stunnel到服务器的HTTPS端口,然后通过此隧道使您的代码通过普通HTTP与服务器通信.这应该使您能够以纯文本格式查看HTTP流量.
“java.net.SocketException:Connection timed out”表示由于超时而无法建立TCP连接.可能是防火墙丢弃了数据包.例如,您可能需要使用HTTP代理来发出HTTPS请求.也可能是服务器机器真的很忙或网络真的很忙.再次,我建议您尝试使用tcpdump / Wireshark来查看TCP级别的情况.