gpt4 book ai didi

java - 是什么导致了我的 java.net.SocketException : Connection reset?

转载 作者:行者123 更新时间:2023-12-02 12:57:55 25 4
gpt4 key购买 nike

我们经常看到但间歇性的java.net.SocketException: Connection reset我们的日志中出现错误。我们不确定Connection reset在哪里错误究竟是从何而来,以及如何去调试。

该问题似乎与我们尝试发送的消息无关。请注意,该消息不是connection reset by peer .

关于此异常的典型原因可能是什么以及我们如何处理有什么建议吗?

这是一个代表性的堆栈跟踪( com.companyname.mtix.sms 是我们的组件):

    java.net.SocketException: Connection reset        at java.net.SocketInputStream.read(SocketInputStream.java:168)        at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)        at java.io.BufferedInputStream.read(BufferedInputStream.java:235)        at org.apache.commons.httpclient.HttpParser.readRawLine(HttpParser.java:77)        at org.apache.commons.httpclient.HttpParser.readLine(HttpParser.java:105)        at org.apache.commons.httpclient.HttpConnection.readLine(HttpConnection.java:1115)        at org.apache.commons.httpclient.HttpMethodBase.readStatusLine(HttpMethodBase.java:1832)        at org.apache.commons.httpclient.HttpMethodBase.readResponse(HttpMethodBase.java:1590)        at org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java:995)        at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:397)        at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:170)        at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:396)        at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:324)        at com.companyname.mtix.sms.services.impl.message.SendTextMessage.sendTextMessage(SendTextMessage.java:127)        at com.companyname.mtix.sms.services.MessageServiceImpl.sendTextMessage(MessageServiceImpl.java:125)        at com.companyname.mtix.sms.services.remote.MessageServiceRemoteImpl.sendTextMessage(MessageServiceRemoteImpl.java:43)        at sun.reflect.GeneratedMethodAccessor203.invoke(Unknown Source)        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)        at java.lang.reflect.Method.invoke(Method.java:585)        at org.apache.axis.providers.java.RPCProvider.invokeMethod(RPCProvider.java:397)        at org.apache.axis.providers.java.RPCProvider.processMessage(RPCProvider.java:186)        at org.apache.axis.providers.java.JavaProvider.invoke(JavaProvider.java:323)        at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)        at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)        at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)        at org.apache.axis.handlers.soap.SOAPService.invoke(SOAPService.java:453)        at org.apache.axis.server.AxisServer.invoke(AxisServer.java:281)        at org.apache.axis.transport.http.AxisServlet.doPost(AxisServlet.java:699)        at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)        at org.apache.axis.transport.http.AxisServletBase.service(AxisServletBase.java:327)        at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)        at com.companyname.mtix.sms.http.filters.NoCacheFilter.doFilter(NoCacheFilter.java:63)        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)        at com.companyname.mtix.sms.http.filters.MessageFilter.doFilter(MessageFilter.java:53)        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)        at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:61)        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:77)        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)        at org.ajaxanywhere.AAFilter.doFilter(AAFilter.java:46)        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)        at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:541)        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)        at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)        at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)        at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)        at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)        at java.lang.Thread.run(Thread.java:595)    

Our component is a web application, running under Tomcat, that calls a third party Web service that sends SMS messages, it so happens. The line of our code on which the exception gets thrown from is the last line in the code snippet below.

String aggregatorResponse = null;
HttpClient httpClient = prepareHttpClient( username, password );
PostMethod postMethod = preparePostMethod( textUrl );

try {
SybaseTextMessageBuilder builder = new SybaseTextMessageBuilder();
URL notifyUrl = buildNotificationUrl( textMessage, codeSetManager );
String smsRequestDocument = builder.buildTextMessage( textMessage, notifyUrl );
LOG.debug( "Sybase MT document created as: \n" + smsRequestDocument );

postMethod.setRequestEntity( new StringRequestEntity( smsRequestDocument ) );
LOG.debug( "commiting SMS to aggregator: " + textMessage.toString() );
int httpStatus = httpClient.executeMethod( postMethod );

最佳答案

SocketException 的 javadoc 指出它是

Thrown to indicate that there is an error in the underlying protocol such as a TCP error

在您的情况下,连接的服务器端似乎已关闭连接。这可能是您发送的请求存在问题,也可能是请求末尾的问题。

为了帮助调试,您可以使用 Wireshark 等工具。查看实际的网络数据包。另外,是否有 Java 代码的替代客户端可用于测试 Web 服务?如果成功,则可能表明 Java 代码中存在错误。

当您使用 Commons HTTP 客户端时,请查看 Common HTTP Client Logging Guide 。这将告诉您如何在 HTTP 级别记录请求。

关于java - 是什么导致了我的 java.net.SocketException : Connection reset?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38398000/

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