cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sumit Arora <sumit1...@gmail.com>
Subject Re: How to handle ClientAbortException in CXF ?
Date Wed, 23 Dec 2015 16:03:50 GMT
Sergey,

I tried using to write Exception Mapper :

1.Here MapperException - > IOException, ClientErrorException
public class GTMClientExceptionMapper implements
ExceptionMapper<MapperException > {

    public Response toResponse(IOException ce) {

        ErrorMessage errorMessage = new
ErrorMessage(ce.getMessage(),400,"Example : XYZ");
        return Response.status(Response.Status.NOT_FOUND)
                .header("Content-Type", "application/json")
                .entity(errorMessage)
                .build();
    }
}

But it doesn't work, other exception mapper stuff is working ?

May you please tell me If there is something else I supposed to do ? :
JAXRSOutInterceptor.handleWriteException

2. Suggest me one example of this : Another option to try is to wrap
Jackson with a custom JAX-RS MessageBoryWriter and handle the write
exception there.

3.May you suggest any example of this :

Finally, when working with AsyncResponse is used, one might want to register

https://jax-rs-spec.java.net/nonav/2.0-rev-a/apidocs/javax/ws/rs/container/ConnectionCallback.html

'Sumit


On Wed, Dec 23, 2015 at 7:13 PM, Sergey Beryozkin <sberyozkin@gmail.com>
wrote:

> Hi
>
> JAXRSOutInterceptor.handleWriteException checks JAX-RS ExceptionMapper so
> perhaps you can intercept that Exception and return Response with the code
> only from this exception mapper.
>
> Another option to try is to wrap Jackson with a custom JAX-RS
> MessageBoryWriter and handle the write exception there.
>
> Finally, when working with AsyncResponse is used, one might want to
> register
>
>
> https://jax-rs-spec.java.net/nonav/2.0-rev-a/apidocs/javax/ws/rs/container/ConnectionCallback.html
>
> HTH, Sergey
>
> On 23/12/15 11:47, Sumit Arora wrote:
>
>> Hi All,
>>
>> I have made a  web application, which uses Apache CXF on backend. In many
>> situation - Client(user) uses the web application to fetch some data to
>> view ( say click on button) which  CXF web service provide from the
>> backend, But Client closes the browser, however the cxf web service was
>> busy to bring the data. So on logs it shows : ClientAbortException. This
>> behaviour is correct. Its fine.
>>
>> But I need the help on following :
>>
>> Is there any way to catch such exception in the CXF webservice code and
>> logs the customized error message, rather showing complete logs( as below)
>> ? If Client has aborted the connection then is there any way to handle
>> such
>> situation and act accordingly?
>>
>>
>> [http-bio-8080-exec-2:ERROR] org.apache.cxf.jaxrs.utils.JAXRSUtils:
>> Problem
>> with writing the data, class java.util.ArrayList, ContentType:
>> application/json
>> [http-bio-8080-exec-2:WARN] org.apache.cxf.phase.PhaseInterceptorChain:
>> Interceptor for {http://X.X.X.X }GTMDataServiceEndPointImpl
>> <http://X.X.X.X/%7DGTMDataServiceEndPointImpl> has thrown exception,
>>
>> unwinding now
>> org.apache.cxf.interceptor.Fault
>> at
>>
>> org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor.handleWriteException(JAXRSOutInterceptor.java:363)
>> at
>>
>> org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor.serializeMessage(JAXRSOutInterceptor.java:266)
>> at
>>
>> org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor.handleWriteException(JAXRSOutInterceptor.java:365)
>> at
>>
>> org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor.serializeMessage(JAXRSOutInterceptor.java:266)
>> at
>>
>> org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor.processResponse(JAXRSOutInterceptor.java:117)
>> at
>>
>> org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor.handleMessage(JAXRSOutInterceptor.java:80)
>> at
>>
>> org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:307)
>> at
>>
>> org.apache.cxf.interceptor.OutgoingChainInterceptor.handleMessage(OutgoingChainInterceptor.java:81)
>> at
>>
>> org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:307)
>> at
>>
>> org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
>> at
>>
>> org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:243)
>> at
>>
>> org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:223)
>> at
>>
>> org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:197)
>> at
>>
>> org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:149)
>> at
>>
>> org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:171)
>> at
>>
>> org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:286)
>> at
>>
>> org.apache.cxf.transport.servlet.AbstractHTTPServlet.doGet(AbstractHTTPServlet.java:211)
>> at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
>> at
>>
>> org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:262)
>> 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:222)
>> at
>>
>> org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
>> at
>>
>> org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
>> at
>>
>> org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
>> at
>>
>> org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
>> at
>> org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
>> at
>>
>> org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
>> at
>>
>> org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
>> at
>>
>> org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
>> at
>>
>> org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
>> at
>> org.apache.tomcat.util.net
>> .JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
>> at
>>
>> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
>> at
>>
>> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
>> at java.lang.Thread.run(Thread.java:695)
>> Caused by: ClientAbortException:  java.net.SocketException: Broken pipe
>> at
>>
>> org.apache.catalina.connector.OutputBuffer.realWriteBytes(OutputBuffer.java:413)
>> at org.apache.tomcat.util.buf.ByteChunk.flushBuffer(ByteChunk.java:480)
>> at org.apache.tomcat.util.buf.ByteChunk.append(ByteChunk.java:366)
>> at
>>
>> org.apache.catalina.connector.OutputBuffer.writeBytes(OutputBuffer.java:438)
>> at org.apache.catalina.connector.OutputBuffer.write(OutputBuffer.java:426)
>> at
>>
>> org.apache.catalina.connector.CoyoteOutputStream.write(CoyoteOutputStream.java:91)
>> at
>> org.apache.cxf.io
>> .AbstractWrappedOutputStream.write(AbstractWrappedOutputStream.java:51)
>> at
>> org.apache.cxf.io
>> .CacheAndWriteOutputStream.write(CacheAndWriteOutputStream.java:80)
>> at
>>
>> com.fasterxml.jackson.core.json.UTF8JsonGenerator._flushBuffer(UTF8JsonGenerator.java:1731)
>> at
>>
>> com.fasterxml.jackson.core.json.UTF8JsonGenerator.flush(UTF8JsonGenerator.java:1070)
>> at
>>
>> com.fasterxml.jackson.databind.ObjectWriter.writeValue(ObjectWriter.java:426)
>> at
>>
>> com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider.writeTo(JacksonJsonProvider.java:578)
>> at
>>
>> org.apache.cxf.jaxrs.utils.JAXRSUtils.writeMessageBody(JAXRSUtils.java:1363)
>> at
>>
>> org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor.serializeMessage(JAXRSOutInterceptor.java:244)
>> ... 33 more
>> Caused by: java.net.SocketException: Broken pipe
>> 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:215)
>> at org.apache.tomcat.util.buf.ByteChunk.flushBuffer(ByteChunk.java:480)
>> at org.apache.tomcat.util.buf.ByteChunk.append(ByteChunk.java:366)
>> at
>>
>> org.apache.coyote.http11.InternalOutputBuffer$OutputStreamOutputBuffer.doWrite(InternalOutputBuffer.java:240)
>> at
>>
>> org.apache.coyote.http11.filters.ChunkedOutputFilter.doWrite(ChunkedOutputFilter.java:117)
>> at
>>
>> org.apache.coyote.http11.AbstractOutputBuffer.doWrite(AbstractOutputBuffer.java:192)
>> at org.apache.coyote.Response.doWrite(Response.java:517)
>> at
>>
>> org.apache.catalina.connector.OutputBuffer.realWriteBytes(OutputBuffer.java:408)
>> ... 46 more
>> [http-bio-8080-exec-2:ERROR] org.apache.cxf.jaxrs.utils.JAXRSUtils:
>> Problem
>> with writing the data, class
>> com.zimperium.gtm.endpoint.model.ErrorMessage,
>> ContentType: application/json
>> [http-bio-8080-exec-2:WARN] org.apache.cxf.phase.PhaseInterceptorChain:
>> Interceptor for {http://X.X.X.X }GTMDataServiceEndPointImpl
>> <http://X.X.X.X/%7DGTMDataServiceEndPointImpl> has thrown exception,
>>
>> unwinding now
>> org.apache.cxf.interceptor.Fault
>> at
>>
>> org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor.handleWriteException(JAXRSOutInterceptor.java:363)
>> at
>>
>> org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor.serializeMessage(JAXRSOutInterceptor.java:266)
>> at
>>
>> org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor.handleWriteException(JAXRSOutInterceptor.java:365)
>> at
>>
>> org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor.serializeMessage(JAXRSOutInterceptor.java:266)
>> at
>>
>> org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor.processResponse(JAXRSOutInterceptor.java:117)
>> at
>>
>> org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor.handleMessage(JAXRSOutInterceptor.java:80)
>> at
>>
>> org.apache.cxf.jaxrs.interceptor.JAXRSDefaultFaultOutInterceptor.handleMessage(JAXRSDefaultFaultOutInterceptor.java:61)
>> at
>>
>> org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:307)
>> at
>>
>> org.apache.cxf.interceptor.AbstractFaultChainInitiatorObserver.onMessage(AbstractFaultChainInitiatorObserver.java:113)
>> at
>>
>> org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:371)
>> at
>>
>> org.apache.cxf.interceptor.OutgoingChainInterceptor.handleMessage(OutgoingChainInterceptor.java:81)
>> at
>>
>> org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:307)
>> at
>>
>> org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
>> at
>>
>> org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:243)
>> at
>>
>> org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:223)
>> at
>>
>> org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:197)
>> at
>>
>> org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:149)
>> at
>>
>> org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:171)
>> at
>>
>> org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:286)
>> at
>>
>> org.apache.cxf.transport.servlet.AbstractHTTPServlet.doGet(AbstractHTTPServlet.java:211)
>> at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
>> at
>>
>> org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:262)
>> 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:222)
>> at
>>
>> org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
>> at
>>
>> org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
>> at
>>
>> org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
>> at
>>
>> org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
>> at
>> org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
>> at
>>
>> org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
>> at
>>
>> org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
>> at
>>
>> org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
>> at
>>
>> org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
>> at
>> org.apache.tomcat.util.net
>> .JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
>> at
>>
>> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
>> at
>>
>> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
>> at java.lang.Thread.run(Thread.java:695)
>> Caused by: ClientAbortException:  java.net.SocketException: Broken pipe
>> at
>>
>> org.apache.catalina.connector.OutputBuffer.realWriteBytes(OutputBuffer.java:413)
>> at org.apache.tomcat.util.buf.ByteChunk.flushBuffer(ByteChunk.java:480)
>> at org.apache.tomcat.util.buf.ByteChunk.append(ByteChunk.java:366)
>> at
>>
>> org.apache.catalina.connector.OutputBuffer.writeBytes(OutputBuffer.java:438)
>> at org.apache.catalina.connector.OutputBuffer.write(OutputBuffer.java:426)
>> at
>>
>> org.apache.catalina.connector.CoyoteOutputStream.write(CoyoteOutputStream.java:91)
>> at
>> org.apache.cxf.io
>> .AbstractWrappedOutputStream.write(AbstractWrappedOutputStream.java:51)
>> at
>> org.apache.cxf.io
>> .CacheAndWriteOutputStream.write(CacheAndWriteOutputStream.java:80)
>> at
>>
>> com.fasterxml.jackson.core.json.UTF8JsonGenerator._flushBuffer(UTF8JsonGenerator.java:1731)
>> at
>>
>> com.fasterxml.jackson.core.json.UTF8JsonGenerator.flush(UTF8JsonGenerator.java:1070)
>> at
>>
>> com.fasterxml.jackson.databind.ObjectWriter.writeValue(ObjectWriter.java:426)
>> at
>>
>> com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider.writeTo(JacksonJsonProvider.java:578)
>> at
>>
>> org.apache.cxf.jaxrs.utils.JAXRSUtils.writeMessageBody(JAXRSUtils.java:1363)
>> at
>>
>> org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor.serializeMessage(JAXRSOutInterceptor.java:244)
>> ... 36 more
>> Caused by: java.net.SocketException: Broken pipe
>> 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:215)
>> at org.apache.tomcat.util.buf.ByteChunk.flushBuffer(ByteChunk.java:480)
>> at org.apache.tomcat.util.buf.ByteChunk.append(ByteChunk.java:366)
>> at
>>
>> org.apache.coyote.http11.InternalOutputBuffer$OutputStreamOutputBuffer.doWrite(InternalOutputBuffer.java:240)
>> at
>>
>> org.apache.coyote.http11.filters.ChunkedOutputFilter.doWrite(ChunkedOutputFilter.java:117)
>> at
>>
>> org.apache.coyote.http11.AbstractOutputBuffer.doWrite(AbstractOutputBuffer.java:192)
>> at org.apache.coyote.Response.doWrite(Response.java:517)
>> at
>>
>> org.apache.catalina.connector.OutputBuffer.realWriteBytes(OutputBuffer.java:408)
>> ... 49 more
>>
>> Process finished with exit code 137
>>
>> {http://X.X.X.X } - It was package name string ,which I hve replaced with
>> X.X.X.X....
>>
>>
>>
>>
>>>
>>
>
> --
> Sergey Beryozkin
>
> Talend Community Coders
> http://coders.talend.com/
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message