1

我有一个网络服务和一个客户端。有时客户端连接,而不是立即获得返回值。稍后,如果从 WS 返回一个值并且同时客户端已关闭,我会收到我不知道如何处理的异常。

如何捕获对等异常重置的那些,以便网络服务器不会崩溃?

@Webservice
class MyWebservice {
    public boolean myWebserviceMethod() {
        //sleep, cut the client, then return.
        return false;
    }   
}

Okt 2012 年 2 月 2 日下午 2:26:52 org.apache.cxf.phase.PhaseInterceptorChain doDefaultLogging

Warnung: Interceptor for {http://myproject.de/wsdl}ConnectionService#{http://myproject.de/wsdl}myWebserviceMethod has thrown exception, unwinding now
org.apache.cxf.interceptor.Fault: Could not send Message.
    at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:64)
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:262)
    at org.apache.cxf.interceptor.OutgoingChainInterceptor.handleMessage(OutgoingChainInterceptor.java:77)
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:262)
    at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
    at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:211)
    at org.apache.openejb.server.cxf.CxfWsContainer.onMessage(CxfWsContainer.java:73)
    at org.apache.openejb.server.webservices.WsServlet.service(WsServlet.java:98)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:45)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1001)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: ClientAbortException:  java.net.SocketException: Connection reset by peer: socket write error
    at org.apache.catalina.connector.OutputBuffer.doFlush(OutputBuffer.java:346)
    at org.apache.catalina.connector.OutputBuffer.flush(OutputBuffer.java:306)
    at org.apache.catalina.connector.Response.flushBuffer(Response.java:568)
    at org.apache.catalina.connector.ResponseFacade.flushBuffer(ResponseFacade.java:307)
    at org.apache.openejb.server.httpd.ServletResponseAdapter.flushBuffer(ServletResponseAdapter.java:205)
    at org.apache.cxf.transport.http.AbstractHTTPDestination$WrappedOutputStream.close(AbstractHTTPDestination.java:684)
    at org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:56)
    at org.apache.cxf.transport.http.AbstractHTTPDestination$BackChannelConduit.close(AbstractHTTPDestination.java:626)
    at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:62)
    ... 24 more
Caused by: java.net.SocketException: Connection reset by peer: socket write error
    at java.net.SocketOutputStream.socketWrite0(Native Method)
    at java.net.SocketOutputStream.socketWrite(Unknown Source)
    at java.net.SocketOutputStream.write(Unknown Source)
    at org.apache.coyote.http11.InternalOutputBuffer.realWriteBytes(InternalOutputBuffer.java:215)
    at org.apache.tomcat.util.buf.ByteChunk.flushBuffer(ByteChunk.java:462)
    at org.apache.coyote.http11.InternalOutputBuffer.flush(InternalOutputBuffer.java:119)
    at org.apache.coyote.http11.AbstractHttp11Processor.action(AbstractHttp11Processor.java:789)
    at org.apache.coyote.Response.action(Response.java:174)
    at org.apache.catalina.connector.OutputBuffer.doFlush(OutputBuffer.java:341)
    ... 32 more
4

1 回答 1

0

服务器确实崩溃了,还是您(错误地)通过见证堆栈跟踪得出服务器崩溃的结论?

堆栈跟踪在那里是因为 Catalina 无法对为与客户端通信而打开的套接字写入响应。这种情况下总会出现这个异常;Catalina 无法确切知道为什么它不能写入套接字——它只知道它不能写响应。它打印堆栈跟踪(因为这是一个可能对系统管理员有价值的错误条件,例如 - 用于性能调整目的),然后继续。

如果您的服务器确实在这种情况发生后崩溃,那么您可能会遇到更大的问题。我很难相信如果服务器无法对死 TCP/IP 套接字写入响应,它实际上会崩溃。

于 2012-10-02T13:17:10.887 回答