title: JAX-WS: How to handle exceptions when client aborted
body: <p>JAX-WS: How to handle exceptions when client aborted</p>
  
  <p>Hi. 
  Could you please tell me how to handle exceptions in JAX-WS?</p>
  
  <p>The following exception was occured when the client closed connection suddenly.
  I'd like to log the exceptions. How can I catch the exception?</p>
  
  <p>I tried the following methods, but I could not catch the exception.</p>
  
  <ul>
  <li>Thread.setDefaultUncaughtExceptionHandler()</li>
  <li>Servlet's request.getAttribute("javax.servlet.error.exception") and web.xml's error-page</li>
  <li>Filter.doFilter()</li>
  </ul>
  
  <p>Regards,</p>
  
  <pre><code>2012/01/30 14:06:42 com.sun.xml.ws.transport.http.servlet.WSServletDelegate doGet
  : caught throwable
  javax.xml.ws.WebServiceException: com.ctc.wstx.exc.WstxIOException: null
      at com.sun.xml.ws.encoding.StreamSOAPCodec.encode(StreamSOAPCodec.java:112)
      at com.sun.xml.ws.encoding.SOAPBindingCodec.encode(SOAPBindingCodec.java:284)
      at com.sun.xml.ws.transport.http.HttpAdapter.encodePacket(HttpAdapter.java:339)
      at com.sun.xml.ws.transport.http.HttpAdapter.access$100(HttpAdapter.java:93)
      at com.sun.xml.ws.transport.http.HttpAdapter$HttpToolkit.handle(HttpAdapter.java:481)
      at com.sun.xml.ws.transport.http.HttpAdapter.handle(HttpAdapter.java:244)
      at com.sun.xml.ws.transport.http.servlet.ServletAdapter.handle(ServletAdapter.java:135)
      at com.sun.xml.ws.transport.http.servlet.WSServletDelegate.doGet(WSServletDelegate.java:129)
      at com.sun.xml.ws.transport.http.servlet.WSServletDelegate.doPost(WSServletDelegate.java:160)
      at com.sun.xml.ws.transport.http.servlet.WSServlet.doPost(WSServlet.java:75)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
      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:224)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
      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:928)
      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:987)
      at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:539)
      at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:300)
      at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
      at java.lang.Thread.run(Thread.java:662)
  Caused by: com.ctc.wstx.exc.WstxIOException: null
      at com.ctc.wstx.sw.BaseStreamWriter.flush(BaseStreamWriter.java:313)
      at com.sun.xml.ws.streaming.XMLStreamWriterUtil.getOutputStream(XMLStreamWriterUtil.java:97)
      at com.sun.xml.ws.message.jaxb.JAXBMessage.writePayloadTo(JAXBMessage.java:319)
      at com.sun.xml.ws.message.AbstractMessageImpl.writeTo(AbstractMessageImpl.java:142)
      at com.sun.xml.ws.encoding.StreamSOAPCodec.encode(StreamSOAPCodec.java:109)
      ... 27 more
  Caused by: ClientAbortException:  java.net.SocketException: Connection reset by peer: socket write error
      at org.apache.catalina.connector.OutputBuffer.doFlush(OutputBuffer.java:336)
      at org.apache.catalina.connector.OutputBuffer.flush(OutputBuffer.java:301)
      at org.apache.catalina.connector.CoyoteOutputStream.flush(CoyoteOutputStream.java:101)
      at com.ctc.wstx.io.UTF8Writer.flush(UTF8Writer.java:99)
      at com.ctc.wstx.sw.BufferingXmlWriter.flush(BufferingXmlWriter.java:214)
      at com.ctc.wstx.sw.BaseStreamWriter.flush(BaseStreamWriter.java:311)
      ... 31 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(SocketOutputStream.java:92)
      at java.net.SocketOutputStream.write(SocketOutputStream.java:136)
      at org.apache.coyote.http11.InternalOutputBuffer.realWriteBytes(InternalOutputBuffer.java:216)
      at org.apache.tomcat.util.buf.ByteChunk.flushBuffer(ByteChunk.java:460)
      at org.apache.coyote.http11.InternalOutputBuffer.flush(InternalOutputBuffer.java:119)
      at org.apache.coyote.http11.AbstractHttp11Processor.action(AbstractHttp11Processor.java:781)
      at org.apache.coyote.Response.action(Response.java:170)
      at org.apache.catalina.connector.OutputBuffer.doFlush(OutputBuffer.java:331)
      ... 36 more
  </code></pre>