You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Sergey Beryozkin <sb...@gmail.com> on 2011/12/29 17:28:45 UTC
Re: ExceptionMapper choosing the wrong mapper
Hi Alex,
Sorry for a delay, I've finally tried to get more optimized hierarchies
supported but I'm not sure we can get a handle on this top-level
parameter, here is the test code:
private static class RuntimeExceptionMapper1
extends AbstractTestExceptionMapper<RuntimeException> {
}
private static class RuntimeExceptionMapper2
extends AbstractTestExceptionMapper<WebApplicationException> {
}
private static class AbstractTestExceptionMapper<T extends
RuntimeException>
implements ExceptionMapper<T> {
@Override
public Response toResponse(T arg0) {
// TODO Auto-generated method stub
return null;
}
}
ProviderFactory would get a list of generic interfaces and the bounds
from then and the best we can get to is 'RuntimeException' which is
obtained from "<T extends RuntimeException>".
Any idea on how to get to say "WebApplicationException" which is visible
in the code at least in
"AbstractTestExceptionMapper<WebApplicationException>".
I'm wondering if it is even available at the runtime,
Sergey
On 06/09/11 22:13, Alex Porras wrote:
> On Tue, Sep 6, 2011 at 4:12 PM, Alex Porras<al...@twelve17.com> wrote:
>
>> What is happening is that when FooException is thrown in the
>> application, it is being handled by BarExceptionMapper.
>
> I believe I have found the solution. Despite the child exception
> mappers specifying a generic type required by the parent (abstract)
> exception mapper (which implements ExceptionMapper), each child class
> also needs to include a "implements ExceptionMapper<T>" declaration,
> to prevent CXF from bubbling up to the base interface implementation
> declaration and using that class's generic type.
>
> Thus, my exception mapper hierarchy is now:
>
> (abstract) BaseRuntimeExceptionMapper<T extends BaseRuntimeException>
> FooExceptionMapper extends BaseRuntimeExceptionMapper<FooException>
> implements ExceptionMapper<FooException>
> BarExceptionMapper extends
> BaseRuntimeExceptionMapper<BarException>implements
> ExceptionMapper<BarException>
>
> This seems a little repetitive, but I think it makes sense given the
> route that CXF seems to be using to determine the exception type.
>
> Hope this helps someone else!
>
> Alex
--
Sergey Beryozkin
Talend Community Coders
http://coders.talend.com/
Blog: http://sberyozkin.blogspot.com