Re: How to handle ClientAbortException in CXF ?

2015-12-23 Thread Sergey Beryozkin

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
 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 

Re: How to handle ClientAbortException in CXF ?

2015-12-23 Thread Sumit Arora
Sergey,

I tried using to write Exception Mapper :

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

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 
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
>>  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

Re: How to handle ClientAbortException in CXF ?

2015-12-23 Thread Sumit Arora
It comes here on exception mapper :

public class GTMClientExceptionMapper implements
ExceptionMapper {

public Response toResponse(IOException ce) {

  //  ErrorMessage errorMessage = new
ErrorMessage(ce.getMessage(),400,"Exmaple Message ");

return null;
   // return Response.status(Response.Status.NOT_FOUND)
//.header("Content-Type", "application/json")
 //   .build();
}
}

I tried to various stuff, but still throw the error, any guess here ?

On Wed, Dec 23, 2015 at 9:45 PM, Sergey Beryozkin 
wrote:

> Well, first thing to check is whether this mapper is invoked, note it is
> not auto-discovered by default, unless you explicitly enable the
> auto-discovery, so it needs to be registered in jaxrs:providers.
>
> But even if it is invoked, the problem is you still try to return some
> error message - the runtime will again attempt to write it to the output
> stream which is already terminated.
>
> So make sure it is invoked, then make Throwable more specific and finally,
> do not set an entity on Response
>
> Sergey
>
>
> On 23/12/15 16:09, Sumit Arora wrote:
>
>> I have tried that as well, that didn't work :
>>
>> @Provider
>> public class GTMGenericExceptionMapper implements
>> ExceptionMapper {
>>
>>  public Response toResponse(Throwable th) {
>>
>>  ErrorMessage errorMessage = new
>> ErrorMessage(th.getMessage(),500,"Example Message");
>>  return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
>>   .header("Content-Type", "application/json")
>>  .entity(errorMessage)
>>  .build();
>>  }
>> }
>>
>> On Wed, Dec 23, 2015 at 9:35 PM, Sergey Beryozkin 
>> wrote:
>>
>> Try registering ExceptionMapper and see what happens
>>>
>>> Cheers. Sergey
>>>
>>> On 23/12/15 16:03, Sumit Arora wrote:
>>>
>>> Sergey,

 I tried using to write Exception Mapper :

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

   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 
 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
>> 

Re: How to handle ClientAbortException in CXF ?

2015-12-23 Thread Sergey Beryozkin
Well, first thing to check is whether this mapper is invoked, note it is 
not auto-discovered by default, unless you explicitly enable the 
auto-discovery, so it needs to be registered in jaxrs:providers.


But even if it is invoked, the problem is you still try to return some 
error message - the runtime will again attempt to write it to the output 
stream which is already terminated.


So make sure it is invoked, then make Throwable more specific and 
finally, do not set an entity on Response


Sergey

On 23/12/15 16:09, Sumit Arora wrote:

I have tried that as well, that didn't work :

@Provider
public class GTMGenericExceptionMapper implements
ExceptionMapper {

 public Response toResponse(Throwable th) {

 ErrorMessage errorMessage = new
ErrorMessage(th.getMessage(),500,"Example Message");
 return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
  .header("Content-Type", "application/json")
 .entity(errorMessage)
 .build();
 }
}

On Wed, Dec 23, 2015 at 9:35 PM, Sergey Beryozkin 
wrote:


Try registering ExceptionMapper and see what happens

Cheers. Sergey

On 23/12/15 16:03, Sumit Arora wrote:


Sergey,

I tried using to write Exception Mapper :

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

  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 
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
 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



Re: How to handle ClientAbortException in CXF ?

2015-12-23 Thread Sumit Arora
I have tried that as well, that didn't work :

@Provider
public class GTMGenericExceptionMapper implements
ExceptionMapper {

public Response toResponse(Throwable th) {

ErrorMessage errorMessage = new
ErrorMessage(th.getMessage(),500,"Example Message");
return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
 .header("Content-Type", "application/json")
.entity(errorMessage)
.build();
}
}

On Wed, Dec 23, 2015 at 9:35 PM, Sergey Beryozkin 
wrote:

> Try registering ExceptionMapper and see what happens
>
> Cheers. Sergey
>
> On 23/12/15 16:03, Sumit Arora wrote:
>
>> Sergey,
>>
>> I tried using to write Exception Mapper :
>>
>> 1.Here MapperException - > IOException, ClientErrorException
>> public class GTMClientExceptionMapper implements
>> ExceptionMapper {
>>
>>  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 
>> 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
  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)

Re: How to handle ClientAbortException in CXF ?

2015-12-23 Thread Sergey Beryozkin

Try registering ExceptionMapper and see what happens

Cheers. Sergey
On 23/12/15 16:03, Sumit Arora wrote:

Sergey,

I tried using to write Exception Mapper :

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

 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 
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
 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


Re: How to handle ClientAbortException in CXF ?

2015-12-23 Thread Sergey Beryozkin
As I have already said, return Response with the error code only. 
Returning null indicates to the runtime that the mapping has not been 
done in which case it has to rethrow the original exception.


If returning a response with the code only does not help then move to 
the alternative 2 (write your own MessageBodyWriter which will 
internally delegate to Jackson MessageBodyWriter - it will be loaded 
inside your custom MBW, and register it instead of Jackson with the 
endpoint).


If that does not work - move to the alternative 3. Introduce 
AsyncResponse first into your code (see for ex AsyncResponse package 
docs), and then once you have it, you will be able to register the 
callback with this AsyncResponse


Sergey
On 23/12/15 16:28, Sumit Arora wrote:

It comes here on exception mapper :

public class GTMClientExceptionMapper implements
ExceptionMapper {

 public Response toResponse(IOException ce) {

   //  ErrorMessage errorMessage = new
ErrorMessage(ce.getMessage(),400,"Exmaple Message ");

 return null;
// return Response.status(Response.Status.NOT_FOUND)
 //.header("Content-Type", "application/json")
  //   .build();
 }
}

I tried to various stuff, but still throw the error, any guess here ?

On Wed, Dec 23, 2015 at 9:45 PM, Sergey Beryozkin 
wrote:


Well, first thing to check is whether this mapper is invoked, note it is
not auto-discovered by default, unless you explicitly enable the
auto-discovery, so it needs to be registered in jaxrs:providers.

But even if it is invoked, the problem is you still try to return some
error message - the runtime will again attempt to write it to the output
stream which is already terminated.

So make sure it is invoked, then make Throwable more specific and finally,
do not set an entity on Response

Sergey


On 23/12/15 16:09, Sumit Arora wrote:


I have tried that as well, that didn't work :

@Provider
public class GTMGenericExceptionMapper implements
ExceptionMapper {

  public Response toResponse(Throwable th) {

  ErrorMessage errorMessage = new
ErrorMessage(th.getMessage(),500,"Example Message");
  return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
   .header("Content-Type", "application/json")
  .entity(errorMessage)
  .build();
  }
}

On Wed, Dec 23, 2015 at 9:35 PM, Sergey Beryozkin 
wrote:

Try registering ExceptionMapper and see what happens


Cheers. Sergey

On 23/12/15 16:03, Sumit Arora wrote:

Sergey,


I tried using to write Exception Mapper :

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

   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