Hi Jack,
Currently only one such exception mapper will be selected and it will
be the first one that is registered, in your example the one in the
package "com.a.rest.provider".
JAX-RS does not specify what to do when there are multiple providers
registered for the same type. It states:
When choosing an exception mapping provider to map an exception, an
implementation MUST use the provider whose generic type
is the nearest superclass of the exception.
I suppose Jersey could support adapting multiple providers of the same
type and call each in sequence until a non-null value is returned. But
that would not be conforming to the JAX-RS API which states for
ExceptionMapper.toResponse:
Map an exception to a Response. Returning null results in a
Response.Status.NO_CONTENT response. Throwing a runtime
exception results in a Response.Status.INTERNAL_SERVER_ERROR response
I think we made a mistake with exception mappers and what the
returning of null means. A null should mean try the next matching
mapper and then try any matching the super class etc.
What is your use-case? Perhaps in your case if possible each provider
"module" should differentiate with exception mappers that map to more
specific runtime exceptions?
Paul.
On Jan 13, 2009, at 8:43 AM, beanor wrote:
>
> hi,
>
> If we have tow class like this:
>
> A:
>
> package com.a.rest.provider;
> @Provider
> public class RuntimeExceptionMapper implements
> ExceptionMapper<RuntimeException> {
> ......
> }
>
> B:
>
> package com.b.rest.provider;
> @Provider
> public class RuntimeExceptionMapper implements
> ExceptionMapper<RuntimeException> {
> ......
> }
>
> Tow class name is same , But package is different, Web config the
> web.xml
> like this:
>
>
> <init-param>
> <param-name>
> com.sun.jersey.config.property.packages
> </param-name>
> <param-value>
> com.a.rest.provider;
> com.b.rest.provider
> </param-value>
> </init-param>
>
> This case happen at A class in a jar, B is currently project.
>
> My question is:
>
> Is it working with exsiting tow RuntimeException implement in one web
> project? And is it working for the same class name?
>
> Thanks!
>
> jack.
>
> --
> View this message in context: http://n2.nabble.com/Is-it-working-with-exsiting-tow-RuntimeException-in-one-web-project--tp2150052p2150052.html
> Sent from the Jersey mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>