dev@jersey.java.net

Re: [Jersey] Re: Jersey & Atmosphere annotations

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Wed, 14 Oct 2009 11:28:33 +0200

Hi,

It is not an issue with Atmosphere. Jaro, could you log an issue with
Jersey?

Jersey is being unduly restrictive when merging the annotations. It
should be safe to merge any annotations from the JAX-RS identified
method as long as those annotations do not already exist on the
overriding/implementing method. Same goes for the annotations declared
on the parameters.

Unfortunately there is no standard behavior specified for annotation
inheritance for methods and method parameters. So each spec/framework
does its own thing.

Thanks,
Paul.

On Oct 14, 2009, at 2:02 AM, Jeanfrancois Arcand wrote:

> Salut,
>
> Jaros?aw Lewandowski wrote:
>> Hi,
>> I found some issue with Atmosphere and Jersey integration. In my
>> code resources are EJBs. Some of these resources are returned as
>> sub resources from root resource and as spec says the annotations
>> are discovered in the runtime. So my beans have business interfaces
>> defined and to allow jersey to discover all it's annotations they
>> are included in such interfaces e.g.
>> @Stateless
>> public class SystemResourceBean implements SystemResource {
>> @Override
>> public String status() {
>> ....
>> }
>> }
>> public interface SystemResource {
>> @GET
>> public String status();
>> }
>> and root resource
>> @Stateless
>> public class RootResource {
>> }
>> Unfortunately when methods of this interface are annotated with
>> Atmosphere annotations (like @Suspend etc.) they have no effect.
>> After some investigation I found in Jersey code that the class
>> com.sun.jersey.core.reflection.AnnotatedMethod uses all annotation
>> of class if it is simple POJO (including Atmosphere's ones) and
>> tries to merge annotations from super classes and all interfaces.
>> Due to this fragment of code:
>> private static Annotation[] mergeMethodAnnotations(Method m, Method
>> am) {
>> List<Annotation> al = asList(m.getAnnotations());
>> for (Annotation a : am.getAnnotations()) {
>> if (isMethodAnnotation(a))
>> al.add(a);
>> }
>> return al.toArray(new Annotation[0]);
>> }
>> only annotations passing isMethodAnnotation(...) check are added to
>> the result, which means that only @Path, @Produces, @Consumes and
>> any other annotations annotated by @HttpMethod are merged from
>> interfaces.. and obviously annotations like @Suspend are
>> discarded... In my opinion is it kind of inconsistency in treating
>> POJO's annotations and their interfaces in different way... Lack of
>> this annotation in method specification of resource causes that
>> org.atmosphere.core.AtmosphereFilter is not able to work properly :(
>
> First, Great analysis.
>
>> So my question is: does anybody know about this issue? If not, then
>> should I rise it in Atmosphere or in Jersey project?
>
> This is a new issue. I'm cc-ing the Jersey's dev list but I suspect
> the issue is with Atmosphere and how I defines those annotations.
> Let me look at how Jersey defines its annotation and see if I can
> comes with a solution. Meanwhile if someone of the Jersey list knows
> the solution, let me know :-)
>
>
>> I know that workaround for this is to use no-interface Session
>> Beans only... but this is not a solution for me :(
>
> Sure let's try to find a solution and include it in the upcoming 0.4
> release.
>
> Thanks
>
> -- Jeanfrancois
>
>
>> Regards
>> Jaro
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: dev-help_at_jersey.dev.java.net
>