You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cxf.apache.org by Ivan Junckes Filho <iv...@gmail.com> on 2019/12/25 13:23:43 UTC

WebApplicationExceptionMapper not being called

Hello guys, I am trying to log the exception thrown by
WebApplicationExceptionMapper but the exception mapper is never called.

Instead of calling it tomee calls ExceptionUtils.convertFaultToResponse.
Even writing a new default exception mapper doesn't work. Anyone knows how
can I print the exception of WebApplicationException? It can be using the
mapper or not.

public static <T extends Throwable> Response convertFaultToResponse(T
ex, Message currentMessage) {
    if (ex == null || currentMessage == null) {
        return null;
    }e
    Message inMessage = currentMessage.getExchange().getInMessage();
    Response response = null;
    if (ex instanceof WebApplicationException) {
        WebApplicationException webEx = (WebApplicationException)ex;
        if (webEx.getResponse().hasEntity()
            && webEx.getCause() == null
            && MessageUtils.getContextualBoolean(inMessage,
SUPPORT_WAE_SPEC_OPTIMIZATION, true)) {
            response = webEx.getResponse();
        }
    }

    if (response == null) {
        ExceptionMapper<T>  mapper =
            ServerProviderFactory.getInstance(inMessage).createExceptionMapper(ex.getClass(),
inMessage);
        if (mapper != null) {
            try {
                response = mapper.toResponse(ex);
            } catch (Throwable mapperEx) {

inMessage.getExchange().put(JAXRSUtils.EXCEPTION_FROM_MAPPER, "true");
                mapperEx.printStackTrace();
                return Response.serverError().build();
            }
        }
    }
    if (response == null) {
        Throwable unwrappedException = ex.getCause();
        if (unwrappedException instanceof WebApplicationException) {
            WebApplicationException webEx =
(WebApplicationException)unwrappedException;
            response = webEx.getResponse();
        }
    }
    JAXRSUtils.setMessageContentType(currentMessage, response);
    return response;
}

Re: WebApplicationExceptionMapper not being called

Posted by Andriy Redko <dr...@gmail.com>.
Thank you, agree with Romain, looks like an issue to me, please open one.

IJF> The issue was the DefaultExceptionMapper that I created that extends WebApplicationExceptionMapper was never
IJF> called. Also WebApplicationExceptionMapper was never called if I didn't create the default one. 


IJF> In summary WebApplicationExceptionMapper is never called, because of the property I mentioned earlier. Changing it to false, it works.
IJF> On Thu, Dec 26, 2019 at 1:33 PM Andriy Redko <dr...@gmail.com> wrote:

IJF> Hi Ivan,

IJF>  Please correct me if I misunderstood the case 

  >> Hello guys, I am trying to log the exception thrown by
  >> WebApplicationExceptionMapper but the exception mapper is never called.

IJF>  You have an exception mapper (WebApplicationExceptionMapper) which throws 
IJF>  (possibly, another) exception while trying to map the exception? And you
IJF>  would like to intercept and log the exceptions thrown from mapper? Or your 
IJF>  JAX-RS resources thrown exceptions and WebApplicationExceptionMapper is never 
IJF>  called? 

IJF>  Thank you.

IJF>  Best Regards,
IJF>      Andriy Redko




 IJF>> Thanks Romain, it seems using a ContainerRequestFilter did the job.

 IJF>> I will open a ticket.

 IJF>> On Wed, Dec 25, 2019 at 2:45 PM Romain Manni-Bucau <rm...@gmail.com>
 IJF>> wrote:

 >>> Hi Ivan

 >>> You can set it with a cxf interceptor or even jaxrs filter but looks like a
 >>> bug, at least the default. Default should be true only if there is no
 >>> custom mapper, not if there is any registered mapper matching and this is
 >>> known at deploy time. Guess you should open a ticket.

 >>> Le mer. 25 déc. 2019 à 15:32, Ivan Junckes Filho <iv...@gmail.com> a
 >>> écrit :

 >>> > It seems the issue is with:
 >>> > wae.spec.optimization property, it needs to be false or it
 >>> > webapplicationexception  will be skipped.
 >>> >
 >>> > But I can't find the way to set it to false. Property is part of
 >>> > org.apache.cxf.message.Message.
 >>> >
 >>> > Anyone can help? system.properties didn't work.
 >>> >
 >>> > On Wed, Dec 25, 2019 at 10:23 AM Ivan Junckes Filho <
 >>> ivanjunckes@gmail.com
 >>> > >
 >>> > wrote:
 >>> >
 >>> > > Hello guys, I am trying to log the exception thrown by
 >>> > > WebApplicationExceptionMapper but the exception mapper is never called.
 >>> > >
 >>> > > Instead of calling it tomee calls
 >>> ExceptionUtils.convertFaultToResponse.
 >>> > > Even writing a new default exception mapper doesn't work. Anyone knows
 >>> > how
 >>> > > can I print the exception of WebApplicationException? It can be using
 >>> the
 >>> > > mapper or not.
 >>> > >
 >>> > > public static <T extends Throwable> Response convertFaultToResponse(T
 >>> > ex, Message currentMessage) {
 >>> > >     if (ex == null || currentMessage == null) {
 >>> > >         return null;
 >>> > >     }e
 >>> > >     Message inMessage = currentMessage.getExchange().getInMessage();
 >>> > >     Response response = null;
 >>> > >     if (ex instanceof WebApplicationException) {
 >>> > >         WebApplicationException webEx = (WebApplicationException)ex;
 >>> > >         if (webEx.getResponse().hasEntity()
 >>> > >             && webEx.getCause() == null
 >>> > >             && MessageUtils.getContextualBoolean(inMessage,
 >>> > SUPPORT_WAE_SPEC_OPTIMIZATION, true)) {
 >>> > >             response = webEx.getResponse();
 >>> > >         }
 >>> > >     }
 >>> > >
 >>> > >     if (response == null) {
 >>> > >         ExceptionMapper<T>  mapper =
 >>> > >
 >>> >
 >>> ServerProviderFactory.getInstance(inMessage).createExceptionMapper(ex.getClass(),
 >>> > inMessage);
 >>> > >         if (mapper != null) {
 >>> > >             try {
 >>> > >                 response = mapper.toResponse(ex);
 >>> > >             } catch (Throwable mapperEx) {
 >>> > >
 >>> >  inMessage.getExchange().put(JAXRSUtils.EXCEPTION_FROM_MAPPER, "true");
 >>> > >                 mapperEx.printStackTrace();
 >>> > >                 return Response.serverError().build();
 >>> > >             }
 >>> > >         }
 >>> > >     }
 >>> > >     if (response == null) {
 >>> > >         Throwable unwrappedException = ex.getCause();
 >>> > >         if (unwrappedException instanceof WebApplicationException) {
 >>> > >             WebApplicationException webEx =
 >>> > (WebApplicationException)unwrappedException;
 >>> > >             response = webEx.getResponse();
 >>> > >         }
 >>> > >     }
 >>> > >     JAXRSUtils.setMessageContentType(currentMessage, response);
 >>> > >     return response;
 >>> > > }
 >>> > >
 >>> > >
 >>> >





Re: WebApplicationExceptionMapper not being called

Posted by Andriy Redko <dr...@gmail.com>.
Thank you, agree with Romain, looks like an issue to me, please open one.

IJF> The issue was the DefaultExceptionMapper that I created that extends WebApplicationExceptionMapper was never
IJF> called. Also WebApplicationExceptionMapper was never called if I didn't create the default one. 


IJF> In summary WebApplicationExceptionMapper is never called, because of the property I mentioned earlier. Changing it to false, it works.
IJF> On Thu, Dec 26, 2019 at 1:33 PM Andriy Redko <dr...@gmail.com> wrote:

IJF> Hi Ivan,

IJF>  Please correct me if I misunderstood the case 

  >> Hello guys, I am trying to log the exception thrown by
  >> WebApplicationExceptionMapper but the exception mapper is never called.

IJF>  You have an exception mapper (WebApplicationExceptionMapper) which throws 
IJF>  (possibly, another) exception while trying to map the exception? And you
IJF>  would like to intercept and log the exceptions thrown from mapper? Or your 
IJF>  JAX-RS resources thrown exceptions and WebApplicationExceptionMapper is never 
IJF>  called? 

IJF>  Thank you.

IJF>  Best Regards,
IJF>      Andriy Redko




 IJF>> Thanks Romain, it seems using a ContainerRequestFilter did the job.

 IJF>> I will open a ticket.

 IJF>> On Wed, Dec 25, 2019 at 2:45 PM Romain Manni-Bucau <rm...@gmail.com>
 IJF>> wrote:

 >>> Hi Ivan

 >>> You can set it with a cxf interceptor or even jaxrs filter but looks like a
 >>> bug, at least the default. Default should be true only if there is no
 >>> custom mapper, not if there is any registered mapper matching and this is
 >>> known at deploy time. Guess you should open a ticket.

 >>> Le mer. 25 déc. 2019 à 15:32, Ivan Junckes Filho <iv...@gmail.com> a
 >>> écrit :

 >>> > It seems the issue is with:
 >>> > wae.spec.optimization property, it needs to be false or it
 >>> > webapplicationexception  will be skipped.
 >>> >
 >>> > But I can't find the way to set it to false. Property is part of
 >>> > org.apache.cxf.message.Message.
 >>> >
 >>> > Anyone can help? system.properties didn't work.
 >>> >
 >>> > On Wed, Dec 25, 2019 at 10:23 AM Ivan Junckes Filho <
 >>> ivanjunckes@gmail.com
 >>> > >
 >>> > wrote:
 >>> >
 >>> > > Hello guys, I am trying to log the exception thrown by
 >>> > > WebApplicationExceptionMapper but the exception mapper is never called.
 >>> > >
 >>> > > Instead of calling it tomee calls
 >>> ExceptionUtils.convertFaultToResponse.
 >>> > > Even writing a new default exception mapper doesn't work. Anyone knows
 >>> > how
 >>> > > can I print the exception of WebApplicationException? It can be using
 >>> the
 >>> > > mapper or not.
 >>> > >
 >>> > > public static <T extends Throwable> Response convertFaultToResponse(T
 >>> > ex, Message currentMessage) {
 >>> > >     if (ex == null || currentMessage == null) {
 >>> > >         return null;
 >>> > >     }e
 >>> > >     Message inMessage = currentMessage.getExchange().getInMessage();
 >>> > >     Response response = null;
 >>> > >     if (ex instanceof WebApplicationException) {
 >>> > >         WebApplicationException webEx = (WebApplicationException)ex;
 >>> > >         if (webEx.getResponse().hasEntity()
 >>> > >             && webEx.getCause() == null
 >>> > >             && MessageUtils.getContextualBoolean(inMessage,
 >>> > SUPPORT_WAE_SPEC_OPTIMIZATION, true)) {
 >>> > >             response = webEx.getResponse();
 >>> > >         }
 >>> > >     }
 >>> > >
 >>> > >     if (response == null) {
 >>> > >         ExceptionMapper<T>  mapper =
 >>> > >
 >>> >
 >>> ServerProviderFactory.getInstance(inMessage).createExceptionMapper(ex.getClass(),
 >>> > inMessage);
 >>> > >         if (mapper != null) {
 >>> > >             try {
 >>> > >                 response = mapper.toResponse(ex);
 >>> > >             } catch (Throwable mapperEx) {
 >>> > >
 >>> >  inMessage.getExchange().put(JAXRSUtils.EXCEPTION_FROM_MAPPER, "true");
 >>> > >                 mapperEx.printStackTrace();
 >>> > >                 return Response.serverError().build();
 >>> > >             }
 >>> > >         }
 >>> > >     }
 >>> > >     if (response == null) {
 >>> > >         Throwable unwrappedException = ex.getCause();
 >>> > >         if (unwrappedException instanceof WebApplicationException) {
 >>> > >             WebApplicationException webEx =
 >>> > (WebApplicationException)unwrappedException;
 >>> > >             response = webEx.getResponse();
 >>> > >         }
 >>> > >     }
 >>> > >     JAXRSUtils.setMessageContentType(currentMessage, response);
 >>> > >     return response;
 >>> > > }
 >>> > >
 >>> > >
 >>> >





Re: WebApplicationExceptionMapper not being called

Posted by Ivan Junckes Filho <iv...@gmail.com>.
The issue was the DefaultExceptionMapper that I created that extends
WebApplicationExceptionMapper was never called. Also
WebApplicationExceptionMapper was never called if I didn't create the
default one.

In summary WebApplicationExceptionMapper is never called, because of the
property I mentioned earlier. Changing it to false, it works.

On Thu, Dec 26, 2019 at 1:33 PM Andriy Redko <dr...@gmail.com> wrote:

> Hi Ivan,
>
> Please correct me if I misunderstood the case
>
>  > Hello guys, I am trying to log the exception thrown by
>  > WebApplicationExceptionMapper but the exception mapper is never called.
>
> You have an exception mapper (WebApplicationExceptionMapper) which throws
> (possibly, another) exception while trying to map the exception? And you
> would like to intercept and log the exceptions thrown from mapper? Or your
> JAX-RS resources thrown exceptions and WebApplicationExceptionMapper is
> never
> called?
>
> Thank you.
>
> Best Regards,
>     Andriy Redko
>
>
>
>
> IJF> Thanks Romain, it seems using a ContainerRequestFilter did the job.
>
> IJF> I will open a ticket.
>
> IJF> On Wed, Dec 25, 2019 at 2:45 PM Romain Manni-Bucau <
> rmannibucau@gmail.com>
> IJF> wrote:
>
> >> Hi Ivan
>
> >> You can set it with a cxf interceptor or even jaxrs filter but looks
> like a
> >> bug, at least the default. Default should be true only if there is no
> >> custom mapper, not if there is any registered mapper matching and this
> is
> >> known at deploy time. Guess you should open a ticket.
>
> >> Le mer. 25 déc. 2019 à 15:32, Ivan Junckes Filho <iv...@gmail.com>
> a
> >> écrit :
>
> >> > It seems the issue is with:
> >> > wae.spec.optimization property, it needs to be false or it
> >> > webapplicationexception  will be skipped.
> >> >
> >> > But I can't find the way to set it to false. Property is part of
> >> > org.apache.cxf.message.Message.
> >> >
> >> > Anyone can help? system.properties didn't work.
> >> >
> >> > On Wed, Dec 25, 2019 at 10:23 AM Ivan Junckes Filho <
> >> ivanjunckes@gmail.com
> >> > >
> >> > wrote:
> >> >
> >> > > Hello guys, I am trying to log the exception thrown by
> >> > > WebApplicationExceptionMapper but the exception mapper is never
> called.
> >> > >
> >> > > Instead of calling it tomee calls
> >> ExceptionUtils.convertFaultToResponse.
> >> > > Even writing a new default exception mapper doesn't work. Anyone
> knows
> >> > how
> >> > > can I print the exception of WebApplicationException? It can be
> using
> >> the
> >> > > mapper or not.
> >> > >
> >> > > public static <T extends Throwable> Response
> convertFaultToResponse(T
> >> > ex, Message currentMessage) {
> >> > >     if (ex == null || currentMessage == null) {
> >> > >         return null;
> >> > >     }e
> >> > >     Message inMessage = currentMessage.getExchange().getInMessage();
> >> > >     Response response = null;
> >> > >     if (ex instanceof WebApplicationException) {
> >> > >         WebApplicationException webEx = (WebApplicationException)ex;
> >> > >         if (webEx.getResponse().hasEntity()
> >> > >             && webEx.getCause() == null
> >> > >             && MessageUtils.getContextualBoolean(inMessage,
> >> > SUPPORT_WAE_SPEC_OPTIMIZATION, true)) {
> >> > >             response = webEx.getResponse();
> >> > >         }
> >> > >     }
> >> > >
> >> > >     if (response == null) {
> >> > >         ExceptionMapper<T>  mapper =
> >> > >
> >> >
> >>
> ServerProviderFactory.getInstance(inMessage).createExceptionMapper(ex.getClass(),
> >> > inMessage);
> >> > >         if (mapper != null) {
> >> > >             try {
> >> > >                 response = mapper.toResponse(ex);
> >> > >             } catch (Throwable mapperEx) {
> >> > >
> >> >  inMessage.getExchange().put(JAXRSUtils.EXCEPTION_FROM_MAPPER,
> "true");
> >> > >                 mapperEx.printStackTrace();
> >> > >                 return Response.serverError().build();
> >> > >             }
> >> > >         }
> >> > >     }
> >> > >     if (response == null) {
> >> > >         Throwable unwrappedException = ex.getCause();
> >> > >         if (unwrappedException instanceof WebApplicationException) {
> >> > >             WebApplicationException webEx =
> >> > (WebApplicationException)unwrappedException;
> >> > >             response = webEx.getResponse();
> >> > >         }
> >> > >     }
> >> > >     JAXRSUtils.setMessageContentType(currentMessage, response);
> >> > >     return response;
> >> > > }
> >> > >
> >> > >
> >> >
>
>
>

Re: WebApplicationExceptionMapper not being called

Posted by Ivan Junckes Filho <iv...@gmail.com>.
The issue was the DefaultExceptionMapper that I created that extends
WebApplicationExceptionMapper was never called. Also
WebApplicationExceptionMapper was never called if I didn't create the
default one.

In summary WebApplicationExceptionMapper is never called, because of the
property I mentioned earlier. Changing it to false, it works.

On Thu, Dec 26, 2019 at 1:33 PM Andriy Redko <dr...@gmail.com> wrote:

> Hi Ivan,
>
> Please correct me if I misunderstood the case
>
>  > Hello guys, I am trying to log the exception thrown by
>  > WebApplicationExceptionMapper but the exception mapper is never called.
>
> You have an exception mapper (WebApplicationExceptionMapper) which throws
> (possibly, another) exception while trying to map the exception? And you
> would like to intercept and log the exceptions thrown from mapper? Or your
> JAX-RS resources thrown exceptions and WebApplicationExceptionMapper is
> never
> called?
>
> Thank you.
>
> Best Regards,
>     Andriy Redko
>
>
>
>
> IJF> Thanks Romain, it seems using a ContainerRequestFilter did the job.
>
> IJF> I will open a ticket.
>
> IJF> On Wed, Dec 25, 2019 at 2:45 PM Romain Manni-Bucau <
> rmannibucau@gmail.com>
> IJF> wrote:
>
> >> Hi Ivan
>
> >> You can set it with a cxf interceptor or even jaxrs filter but looks
> like a
> >> bug, at least the default. Default should be true only if there is no
> >> custom mapper, not if there is any registered mapper matching and this
> is
> >> known at deploy time. Guess you should open a ticket.
>
> >> Le mer. 25 déc. 2019 à 15:32, Ivan Junckes Filho <iv...@gmail.com>
> a
> >> écrit :
>
> >> > It seems the issue is with:
> >> > wae.spec.optimization property, it needs to be false or it
> >> > webapplicationexception  will be skipped.
> >> >
> >> > But I can't find the way to set it to false. Property is part of
> >> > org.apache.cxf.message.Message.
> >> >
> >> > Anyone can help? system.properties didn't work.
> >> >
> >> > On Wed, Dec 25, 2019 at 10:23 AM Ivan Junckes Filho <
> >> ivanjunckes@gmail.com
> >> > >
> >> > wrote:
> >> >
> >> > > Hello guys, I am trying to log the exception thrown by
> >> > > WebApplicationExceptionMapper but the exception mapper is never
> called.
> >> > >
> >> > > Instead of calling it tomee calls
> >> ExceptionUtils.convertFaultToResponse.
> >> > > Even writing a new default exception mapper doesn't work. Anyone
> knows
> >> > how
> >> > > can I print the exception of WebApplicationException? It can be
> using
> >> the
> >> > > mapper or not.
> >> > >
> >> > > public static <T extends Throwable> Response
> convertFaultToResponse(T
> >> > ex, Message currentMessage) {
> >> > >     if (ex == null || currentMessage == null) {
> >> > >         return null;
> >> > >     }e
> >> > >     Message inMessage = currentMessage.getExchange().getInMessage();
> >> > >     Response response = null;
> >> > >     if (ex instanceof WebApplicationException) {
> >> > >         WebApplicationException webEx = (WebApplicationException)ex;
> >> > >         if (webEx.getResponse().hasEntity()
> >> > >             && webEx.getCause() == null
> >> > >             && MessageUtils.getContextualBoolean(inMessage,
> >> > SUPPORT_WAE_SPEC_OPTIMIZATION, true)) {
> >> > >             response = webEx.getResponse();
> >> > >         }
> >> > >     }
> >> > >
> >> > >     if (response == null) {
> >> > >         ExceptionMapper<T>  mapper =
> >> > >
> >> >
> >>
> ServerProviderFactory.getInstance(inMessage).createExceptionMapper(ex.getClass(),
> >> > inMessage);
> >> > >         if (mapper != null) {
> >> > >             try {
> >> > >                 response = mapper.toResponse(ex);
> >> > >             } catch (Throwable mapperEx) {
> >> > >
> >> >  inMessage.getExchange().put(JAXRSUtils.EXCEPTION_FROM_MAPPER,
> "true");
> >> > >                 mapperEx.printStackTrace();
> >> > >                 return Response.serverError().build();
> >> > >             }
> >> > >         }
> >> > >     }
> >> > >     if (response == null) {
> >> > >         Throwable unwrappedException = ex.getCause();
> >> > >         if (unwrappedException instanceof WebApplicationException) {
> >> > >             WebApplicationException webEx =
> >> > (WebApplicationException)unwrappedException;
> >> > >             response = webEx.getResponse();
> >> > >         }
> >> > >     }
> >> > >     JAXRSUtils.setMessageContentType(currentMessage, response);
> >> > >     return response;
> >> > > }
> >> > >
> >> > >
> >> >
>
>
>

Re: WebApplicationExceptionMapper not being called

Posted by Andriy Redko <dr...@gmail.com>.
Hi Ivan,

Please correct me if I misunderstood the case 

 > Hello guys, I am trying to log the exception thrown by
 > WebApplicationExceptionMapper but the exception mapper is never called.

You have an exception mapper (WebApplicationExceptionMapper) which throws 
(possibly, another) exception while trying to map the exception? And you
would like to intercept and log the exceptions thrown from mapper? Or your 
JAX-RS resources thrown exceptions and WebApplicationExceptionMapper is never 
called? 

Thank you.

Best Regards,
    Andriy Redko




IJF> Thanks Romain, it seems using a ContainerRequestFilter did the job.

IJF> I will open a ticket.

IJF> On Wed, Dec 25, 2019 at 2:45 PM Romain Manni-Bucau <rm...@gmail.com>
IJF> wrote:

>> Hi Ivan

>> You can set it with a cxf interceptor or even jaxrs filter but looks like a
>> bug, at least the default. Default should be true only if there is no
>> custom mapper, not if there is any registered mapper matching and this is
>> known at deploy time. Guess you should open a ticket.

>> Le mer. 25 déc. 2019 à 15:32, Ivan Junckes Filho <iv...@gmail.com> a
>> écrit :

>> > It seems the issue is with:
>> > wae.spec.optimization property, it needs to be false or it
>> > webapplicationexception  will be skipped.
>> >
>> > But I can't find the way to set it to false. Property is part of
>> > org.apache.cxf.message.Message.
>> >
>> > Anyone can help? system.properties didn't work.
>> >
>> > On Wed, Dec 25, 2019 at 10:23 AM Ivan Junckes Filho <
>> ivanjunckes@gmail.com
>> > >
>> > wrote:
>> >
>> > > Hello guys, I am trying to log the exception thrown by
>> > > WebApplicationExceptionMapper but the exception mapper is never called.
>> > >
>> > > Instead of calling it tomee calls
>> ExceptionUtils.convertFaultToResponse.
>> > > Even writing a new default exception mapper doesn't work. Anyone knows
>> > how
>> > > can I print the exception of WebApplicationException? It can be using
>> the
>> > > mapper or not.
>> > >
>> > > public static <T extends Throwable> Response convertFaultToResponse(T
>> > ex, Message currentMessage) {
>> > >     if (ex == null || currentMessage == null) {
>> > >         return null;
>> > >     }e
>> > >     Message inMessage = currentMessage.getExchange().getInMessage();
>> > >     Response response = null;
>> > >     if (ex instanceof WebApplicationException) {
>> > >         WebApplicationException webEx = (WebApplicationException)ex;
>> > >         if (webEx.getResponse().hasEntity()
>> > >             && webEx.getCause() == null
>> > >             && MessageUtils.getContextualBoolean(inMessage,
>> > SUPPORT_WAE_SPEC_OPTIMIZATION, true)) {
>> > >             response = webEx.getResponse();
>> > >         }
>> > >     }
>> > >
>> > >     if (response == null) {
>> > >         ExceptionMapper<T>  mapper =
>> > >
>> >
>> ServerProviderFactory.getInstance(inMessage).createExceptionMapper(ex.getClass(),
>> > inMessage);
>> > >         if (mapper != null) {
>> > >             try {
>> > >                 response = mapper.toResponse(ex);
>> > >             } catch (Throwable mapperEx) {
>> > >
>> >  inMessage.getExchange().put(JAXRSUtils.EXCEPTION_FROM_MAPPER, "true");
>> > >                 mapperEx.printStackTrace();
>> > >                 return Response.serverError().build();
>> > >             }
>> > >         }
>> > >     }
>> > >     if (response == null) {
>> > >         Throwable unwrappedException = ex.getCause();
>> > >         if (unwrappedException instanceof WebApplicationException) {
>> > >             WebApplicationException webEx =
>> > (WebApplicationException)unwrappedException;
>> > >             response = webEx.getResponse();
>> > >         }
>> > >     }
>> > >     JAXRSUtils.setMessageContentType(currentMessage, response);
>> > >     return response;
>> > > }
>> > >
>> > >
>> >



Re: WebApplicationExceptionMapper not being called

Posted by Andriy Redko <dr...@gmail.com>.
Hi Ivan,

Please correct me if I misunderstood the case 

 > Hello guys, I am trying to log the exception thrown by
 > WebApplicationExceptionMapper but the exception mapper is never called.

You have an exception mapper (WebApplicationExceptionMapper) which throws 
(possibly, another) exception while trying to map the exception? And you
would like to intercept and log the exceptions thrown from mapper? Or your 
JAX-RS resources thrown exceptions and WebApplicationExceptionMapper is never 
called? 

Thank you.

Best Regards,
    Andriy Redko




IJF> Thanks Romain, it seems using a ContainerRequestFilter did the job.

IJF> I will open a ticket.

IJF> On Wed, Dec 25, 2019 at 2:45 PM Romain Manni-Bucau <rm...@gmail.com>
IJF> wrote:

>> Hi Ivan

>> You can set it with a cxf interceptor or even jaxrs filter but looks like a
>> bug, at least the default. Default should be true only if there is no
>> custom mapper, not if there is any registered mapper matching and this is
>> known at deploy time. Guess you should open a ticket.

>> Le mer. 25 déc. 2019 à 15:32, Ivan Junckes Filho <iv...@gmail.com> a
>> écrit :

>> > It seems the issue is with:
>> > wae.spec.optimization property, it needs to be false or it
>> > webapplicationexception  will be skipped.
>> >
>> > But I can't find the way to set it to false. Property is part of
>> > org.apache.cxf.message.Message.
>> >
>> > Anyone can help? system.properties didn't work.
>> >
>> > On Wed, Dec 25, 2019 at 10:23 AM Ivan Junckes Filho <
>> ivanjunckes@gmail.com
>> > >
>> > wrote:
>> >
>> > > Hello guys, I am trying to log the exception thrown by
>> > > WebApplicationExceptionMapper but the exception mapper is never called.
>> > >
>> > > Instead of calling it tomee calls
>> ExceptionUtils.convertFaultToResponse.
>> > > Even writing a new default exception mapper doesn't work. Anyone knows
>> > how
>> > > can I print the exception of WebApplicationException? It can be using
>> the
>> > > mapper or not.
>> > >
>> > > public static <T extends Throwable> Response convertFaultToResponse(T
>> > ex, Message currentMessage) {
>> > >     if (ex == null || currentMessage == null) {
>> > >         return null;
>> > >     }e
>> > >     Message inMessage = currentMessage.getExchange().getInMessage();
>> > >     Response response = null;
>> > >     if (ex instanceof WebApplicationException) {
>> > >         WebApplicationException webEx = (WebApplicationException)ex;
>> > >         if (webEx.getResponse().hasEntity()
>> > >             && webEx.getCause() == null
>> > >             && MessageUtils.getContextualBoolean(inMessage,
>> > SUPPORT_WAE_SPEC_OPTIMIZATION, true)) {
>> > >             response = webEx.getResponse();
>> > >         }
>> > >     }
>> > >
>> > >     if (response == null) {
>> > >         ExceptionMapper<T>  mapper =
>> > >
>> >
>> ServerProviderFactory.getInstance(inMessage).createExceptionMapper(ex.getClass(),
>> > inMessage);
>> > >         if (mapper != null) {
>> > >             try {
>> > >                 response = mapper.toResponse(ex);
>> > >             } catch (Throwable mapperEx) {
>> > >
>> >  inMessage.getExchange().put(JAXRSUtils.EXCEPTION_FROM_MAPPER, "true");
>> > >                 mapperEx.printStackTrace();
>> > >                 return Response.serverError().build();
>> > >             }
>> > >         }
>> > >     }
>> > >     if (response == null) {
>> > >         Throwable unwrappedException = ex.getCause();
>> > >         if (unwrappedException instanceof WebApplicationException) {
>> > >             WebApplicationException webEx =
>> > (WebApplicationException)unwrappedException;
>> > >             response = webEx.getResponse();
>> > >         }
>> > >     }
>> > >     JAXRSUtils.setMessageContentType(currentMessage, response);
>> > >     return response;
>> > > }
>> > >
>> > >
>> >



Re: WebApplicationExceptionMapper not being called

Posted by Ivan Junckes Filho <iv...@gmail.com>.
Thanks Romain, it seems using a ContainerRequestFilter did the job.

I will open a ticket.

On Wed, Dec 25, 2019 at 2:45 PM Romain Manni-Bucau <rm...@gmail.com>
wrote:

> Hi Ivan
>
> You can set it with a cxf interceptor or even jaxrs filter but looks like a
> bug, at least the default. Default should be true only if there is no
> custom mapper, not if there is any registered mapper matching and this is
> known at deploy time. Guess you should open a ticket.
>
> Le mer. 25 déc. 2019 à 15:32, Ivan Junckes Filho <iv...@gmail.com> a
> écrit :
>
> > It seems the issue is with:
> > wae.spec.optimization property, it needs to be false or it
> > webapplicationexception  will be skipped.
> >
> > But I can't find the way to set it to false. Property is part of
> > org.apache.cxf.message.Message.
> >
> > Anyone can help? system.properties didn't work.
> >
> > On Wed, Dec 25, 2019 at 10:23 AM Ivan Junckes Filho <
> ivanjunckes@gmail.com
> > >
> > wrote:
> >
> > > Hello guys, I am trying to log the exception thrown by
> > > WebApplicationExceptionMapper but the exception mapper is never called.
> > >
> > > Instead of calling it tomee calls
> ExceptionUtils.convertFaultToResponse.
> > > Even writing a new default exception mapper doesn't work. Anyone knows
> > how
> > > can I print the exception of WebApplicationException? It can be using
> the
> > > mapper or not.
> > >
> > > public static <T extends Throwable> Response convertFaultToResponse(T
> > ex, Message currentMessage) {
> > >     if (ex == null || currentMessage == null) {
> > >         return null;
> > >     }e
> > >     Message inMessage = currentMessage.getExchange().getInMessage();
> > >     Response response = null;
> > >     if (ex instanceof WebApplicationException) {
> > >         WebApplicationException webEx = (WebApplicationException)ex;
> > >         if (webEx.getResponse().hasEntity()
> > >             && webEx.getCause() == null
> > >             && MessageUtils.getContextualBoolean(inMessage,
> > SUPPORT_WAE_SPEC_OPTIMIZATION, true)) {
> > >             response = webEx.getResponse();
> > >         }
> > >     }
> > >
> > >     if (response == null) {
> > >         ExceptionMapper<T>  mapper =
> > >
> >
> ServerProviderFactory.getInstance(inMessage).createExceptionMapper(ex.getClass(),
> > inMessage);
> > >         if (mapper != null) {
> > >             try {
> > >                 response = mapper.toResponse(ex);
> > >             } catch (Throwable mapperEx) {
> > >
> >  inMessage.getExchange().put(JAXRSUtils.EXCEPTION_FROM_MAPPER, "true");
> > >                 mapperEx.printStackTrace();
> > >                 return Response.serverError().build();
> > >             }
> > >         }
> > >     }
> > >     if (response == null) {
> > >         Throwable unwrappedException = ex.getCause();
> > >         if (unwrappedException instanceof WebApplicationException) {
> > >             WebApplicationException webEx =
> > (WebApplicationException)unwrappedException;
> > >             response = webEx.getResponse();
> > >         }
> > >     }
> > >     JAXRSUtils.setMessageContentType(currentMessage, response);
> > >     return response;
> > > }
> > >
> > >
> >
>

Re: WebApplicationExceptionMapper not being called

Posted by Ivan Junckes Filho <iv...@gmail.com>.
Thanks Romain, it seems using a ContainerRequestFilter did the job.

I will open a ticket.

On Wed, Dec 25, 2019 at 2:45 PM Romain Manni-Bucau <rm...@gmail.com>
wrote:

> Hi Ivan
>
> You can set it with a cxf interceptor or even jaxrs filter but looks like a
> bug, at least the default. Default should be true only if there is no
> custom mapper, not if there is any registered mapper matching and this is
> known at deploy time. Guess you should open a ticket.
>
> Le mer. 25 déc. 2019 à 15:32, Ivan Junckes Filho <iv...@gmail.com> a
> écrit :
>
> > It seems the issue is with:
> > wae.spec.optimization property, it needs to be false or it
> > webapplicationexception  will be skipped.
> >
> > But I can't find the way to set it to false. Property is part of
> > org.apache.cxf.message.Message.
> >
> > Anyone can help? system.properties didn't work.
> >
> > On Wed, Dec 25, 2019 at 10:23 AM Ivan Junckes Filho <
> ivanjunckes@gmail.com
> > >
> > wrote:
> >
> > > Hello guys, I am trying to log the exception thrown by
> > > WebApplicationExceptionMapper but the exception mapper is never called.
> > >
> > > Instead of calling it tomee calls
> ExceptionUtils.convertFaultToResponse.
> > > Even writing a new default exception mapper doesn't work. Anyone knows
> > how
> > > can I print the exception of WebApplicationException? It can be using
> the
> > > mapper or not.
> > >
> > > public static <T extends Throwable> Response convertFaultToResponse(T
> > ex, Message currentMessage) {
> > >     if (ex == null || currentMessage == null) {
> > >         return null;
> > >     }e
> > >     Message inMessage = currentMessage.getExchange().getInMessage();
> > >     Response response = null;
> > >     if (ex instanceof WebApplicationException) {
> > >         WebApplicationException webEx = (WebApplicationException)ex;
> > >         if (webEx.getResponse().hasEntity()
> > >             && webEx.getCause() == null
> > >             && MessageUtils.getContextualBoolean(inMessage,
> > SUPPORT_WAE_SPEC_OPTIMIZATION, true)) {
> > >             response = webEx.getResponse();
> > >         }
> > >     }
> > >
> > >     if (response == null) {
> > >         ExceptionMapper<T>  mapper =
> > >
> >
> ServerProviderFactory.getInstance(inMessage).createExceptionMapper(ex.getClass(),
> > inMessage);
> > >         if (mapper != null) {
> > >             try {
> > >                 response = mapper.toResponse(ex);
> > >             } catch (Throwable mapperEx) {
> > >
> >  inMessage.getExchange().put(JAXRSUtils.EXCEPTION_FROM_MAPPER, "true");
> > >                 mapperEx.printStackTrace();
> > >                 return Response.serverError().build();
> > >             }
> > >         }
> > >     }
> > >     if (response == null) {
> > >         Throwable unwrappedException = ex.getCause();
> > >         if (unwrappedException instanceof WebApplicationException) {
> > >             WebApplicationException webEx =
> > (WebApplicationException)unwrappedException;
> > >             response = webEx.getResponse();
> > >         }
> > >     }
> > >     JAXRSUtils.setMessageContentType(currentMessage, response);
> > >     return response;
> > > }
> > >
> > >
> >
>

Re: WebApplicationExceptionMapper not being called

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Hi Ivan

You can set it with a cxf interceptor or even jaxrs filter but looks like a
bug, at least the default. Default should be true only if there is no
custom mapper, not if there is any registered mapper matching and this is
known at deploy time. Guess you should open a ticket.

Le mer. 25 déc. 2019 à 15:32, Ivan Junckes Filho <iv...@gmail.com> a
écrit :

> It seems the issue is with:
> wae.spec.optimization property, it needs to be false or it
> webapplicationexception  will be skipped.
>
> But I can't find the way to set it to false. Property is part of
> org.apache.cxf.message.Message.
>
> Anyone can help? system.properties didn't work.
>
> On Wed, Dec 25, 2019 at 10:23 AM Ivan Junckes Filho <ivanjunckes@gmail.com
> >
> wrote:
>
> > Hello guys, I am trying to log the exception thrown by
> > WebApplicationExceptionMapper but the exception mapper is never called.
> >
> > Instead of calling it tomee calls ExceptionUtils.convertFaultToResponse.
> > Even writing a new default exception mapper doesn't work. Anyone knows
> how
> > can I print the exception of WebApplicationException? It can be using the
> > mapper or not.
> >
> > public static <T extends Throwable> Response convertFaultToResponse(T
> ex, Message currentMessage) {
> >     if (ex == null || currentMessage == null) {
> >         return null;
> >     }e
> >     Message inMessage = currentMessage.getExchange().getInMessage();
> >     Response response = null;
> >     if (ex instanceof WebApplicationException) {
> >         WebApplicationException webEx = (WebApplicationException)ex;
> >         if (webEx.getResponse().hasEntity()
> >             && webEx.getCause() == null
> >             && MessageUtils.getContextualBoolean(inMessage,
> SUPPORT_WAE_SPEC_OPTIMIZATION, true)) {
> >             response = webEx.getResponse();
> >         }
> >     }
> >
> >     if (response == null) {
> >         ExceptionMapper<T>  mapper =
> >
>  ServerProviderFactory.getInstance(inMessage).createExceptionMapper(ex.getClass(),
> inMessage);
> >         if (mapper != null) {
> >             try {
> >                 response = mapper.toResponse(ex);
> >             } catch (Throwable mapperEx) {
> >
>  inMessage.getExchange().put(JAXRSUtils.EXCEPTION_FROM_MAPPER, "true");
> >                 mapperEx.printStackTrace();
> >                 return Response.serverError().build();
> >             }
> >         }
> >     }
> >     if (response == null) {
> >         Throwable unwrappedException = ex.getCause();
> >         if (unwrappedException instanceof WebApplicationException) {
> >             WebApplicationException webEx =
> (WebApplicationException)unwrappedException;
> >             response = webEx.getResponse();
> >         }
> >     }
> >     JAXRSUtils.setMessageContentType(currentMessage, response);
> >     return response;
> > }
> >
> >
>

Re: WebApplicationExceptionMapper not being called

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Hi Ivan

You can set it with a cxf interceptor or even jaxrs filter but looks like a
bug, at least the default. Default should be true only if there is no
custom mapper, not if there is any registered mapper matching and this is
known at deploy time. Guess you should open a ticket.

Le mer. 25 déc. 2019 à 15:32, Ivan Junckes Filho <iv...@gmail.com> a
écrit :

> It seems the issue is with:
> wae.spec.optimization property, it needs to be false or it
> webapplicationexception  will be skipped.
>
> But I can't find the way to set it to false. Property is part of
> org.apache.cxf.message.Message.
>
> Anyone can help? system.properties didn't work.
>
> On Wed, Dec 25, 2019 at 10:23 AM Ivan Junckes Filho <ivanjunckes@gmail.com
> >
> wrote:
>
> > Hello guys, I am trying to log the exception thrown by
> > WebApplicationExceptionMapper but the exception mapper is never called.
> >
> > Instead of calling it tomee calls ExceptionUtils.convertFaultToResponse.
> > Even writing a new default exception mapper doesn't work. Anyone knows
> how
> > can I print the exception of WebApplicationException? It can be using the
> > mapper or not.
> >
> > public static <T extends Throwable> Response convertFaultToResponse(T
> ex, Message currentMessage) {
> >     if (ex == null || currentMessage == null) {
> >         return null;
> >     }e
> >     Message inMessage = currentMessage.getExchange().getInMessage();
> >     Response response = null;
> >     if (ex instanceof WebApplicationException) {
> >         WebApplicationException webEx = (WebApplicationException)ex;
> >         if (webEx.getResponse().hasEntity()
> >             && webEx.getCause() == null
> >             && MessageUtils.getContextualBoolean(inMessage,
> SUPPORT_WAE_SPEC_OPTIMIZATION, true)) {
> >             response = webEx.getResponse();
> >         }
> >     }
> >
> >     if (response == null) {
> >         ExceptionMapper<T>  mapper =
> >
>  ServerProviderFactory.getInstance(inMessage).createExceptionMapper(ex.getClass(),
> inMessage);
> >         if (mapper != null) {
> >             try {
> >                 response = mapper.toResponse(ex);
> >             } catch (Throwable mapperEx) {
> >
>  inMessage.getExchange().put(JAXRSUtils.EXCEPTION_FROM_MAPPER, "true");
> >                 mapperEx.printStackTrace();
> >                 return Response.serverError().build();
> >             }
> >         }
> >     }
> >     if (response == null) {
> >         Throwable unwrappedException = ex.getCause();
> >         if (unwrappedException instanceof WebApplicationException) {
> >             WebApplicationException webEx =
> (WebApplicationException)unwrappedException;
> >             response = webEx.getResponse();
> >         }
> >     }
> >     JAXRSUtils.setMessageContentType(currentMessage, response);
> >     return response;
> > }
> >
> >
>

Re: WebApplicationExceptionMapper not being called

Posted by Ivan Junckes Filho <iv...@gmail.com>.
It seems the issue is with:
wae.spec.optimization property, it needs to be false or it
webapplicationexception  will be skipped.

But I can't find the way to set it to false. Property is part of
org.apache.cxf.message.Message.

Anyone can help? system.properties didn't work.

On Wed, Dec 25, 2019 at 10:23 AM Ivan Junckes Filho <iv...@gmail.com>
wrote:

> Hello guys, I am trying to log the exception thrown by
> WebApplicationExceptionMapper but the exception mapper is never called.
>
> Instead of calling it tomee calls ExceptionUtils.convertFaultToResponse.
> Even writing a new default exception mapper doesn't work. Anyone knows how
> can I print the exception of WebApplicationException? It can be using the
> mapper or not.
>
> public static <T extends Throwable> Response convertFaultToResponse(T ex, Message currentMessage) {
>     if (ex == null || currentMessage == null) {
>         return null;
>     }e
>     Message inMessage = currentMessage.getExchange().getInMessage();
>     Response response = null;
>     if (ex instanceof WebApplicationException) {
>         WebApplicationException webEx = (WebApplicationException)ex;
>         if (webEx.getResponse().hasEntity()
>             && webEx.getCause() == null
>             && MessageUtils.getContextualBoolean(inMessage, SUPPORT_WAE_SPEC_OPTIMIZATION, true)) {
>             response = webEx.getResponse();
>         }
>     }
>
>     if (response == null) {
>         ExceptionMapper<T>  mapper =
>             ServerProviderFactory.getInstance(inMessage).createExceptionMapper(ex.getClass(), inMessage);
>         if (mapper != null) {
>             try {
>                 response = mapper.toResponse(ex);
>             } catch (Throwable mapperEx) {
>                 inMessage.getExchange().put(JAXRSUtils.EXCEPTION_FROM_MAPPER, "true");
>                 mapperEx.printStackTrace();
>                 return Response.serverError().build();
>             }
>         }
>     }
>     if (response == null) {
>         Throwable unwrappedException = ex.getCause();
>         if (unwrappedException instanceof WebApplicationException) {
>             WebApplicationException webEx = (WebApplicationException)unwrappedException;
>             response = webEx.getResponse();
>         }
>     }
>     JAXRSUtils.setMessageContentType(currentMessage, response);
>     return response;
> }
>
>

Re: WebApplicationExceptionMapper not being called

Posted by Ivan Junckes Filho <iv...@gmail.com>.
It seems the issue is with:
wae.spec.optimization property, it needs to be false or it
webapplicationexception  will be skipped.

But I can't find the way to set it to false. Property is part of
org.apache.cxf.message.Message.

Anyone can help? system.properties didn't work.

On Wed, Dec 25, 2019 at 10:23 AM Ivan Junckes Filho <iv...@gmail.com>
wrote:

> Hello guys, I am trying to log the exception thrown by
> WebApplicationExceptionMapper but the exception mapper is never called.
>
> Instead of calling it tomee calls ExceptionUtils.convertFaultToResponse.
> Even writing a new default exception mapper doesn't work. Anyone knows how
> can I print the exception of WebApplicationException? It can be using the
> mapper or not.
>
> public static <T extends Throwable> Response convertFaultToResponse(T ex, Message currentMessage) {
>     if (ex == null || currentMessage == null) {
>         return null;
>     }e
>     Message inMessage = currentMessage.getExchange().getInMessage();
>     Response response = null;
>     if (ex instanceof WebApplicationException) {
>         WebApplicationException webEx = (WebApplicationException)ex;
>         if (webEx.getResponse().hasEntity()
>             && webEx.getCause() == null
>             && MessageUtils.getContextualBoolean(inMessage, SUPPORT_WAE_SPEC_OPTIMIZATION, true)) {
>             response = webEx.getResponse();
>         }
>     }
>
>     if (response == null) {
>         ExceptionMapper<T>  mapper =
>             ServerProviderFactory.getInstance(inMessage).createExceptionMapper(ex.getClass(), inMessage);
>         if (mapper != null) {
>             try {
>                 response = mapper.toResponse(ex);
>             } catch (Throwable mapperEx) {
>                 inMessage.getExchange().put(JAXRSUtils.EXCEPTION_FROM_MAPPER, "true");
>                 mapperEx.printStackTrace();
>                 return Response.serverError().build();
>             }
>         }
>     }
>     if (response == null) {
>         Throwable unwrappedException = ex.getCause();
>         if (unwrappedException instanceof WebApplicationException) {
>             WebApplicationException webEx = (WebApplicationException)unwrappedException;
>             response = webEx.getResponse();
>         }
>     }
>     JAXRSUtils.setMessageContentType(currentMessage, response);
>     return response;
> }
>
>