0 Replies Latest reply on May 23, 2011 5:30 AM by Hans Stöber

    Managed beans, Weld client proxy, custom annotations

    Hans Stöber Newbie

      Hi,


      I am using Glassfish 3.1 with included Weld 1.1.0 final and Jersey 1.5. I defined a simple Jersey resource class and a managed bean, both annotated with @Model. I am injecting the managed bean into the Jersey resource class, which works fine. Apart from @Model, the managed bean is also annotated with some custom annotation, retention is RetentionPolicy.RUNTIME.


      Here is some simplistic code to demonstrate what I'm doing:


      Managed Bean:


      @Model
      @MyAnnotation
      public class MyManagedBean {
           
           public MyManagedBean() {
                // intentionally left blank
           }
      }



      Resource class:


      @Path("myresource")
      @Model
      public class MyResource {
      
           @Inject
           private MyManagedBean myManagedBean;
                
           @GET
           @Path("/display")
           @Produces(MediaType.TEXT_HTML)
           public String display() {
                return  Arrays.toString(myManagedBean.getClass().getAnnotations());
           }
      }



      Annotation:


      @Retention(RetentionPolicy.RUNTIME)
      public @interface MyAnnotation {
      }




      However, it seems that the generated Weld client proxy for the managed bean does not include the annotations. For example, if I do a


      myManagedBean.getClass().getAnnotations()



      an empty array is returned. This does not seem to be limited to custom annotations, since also the @Model annotation is missing.

      The only way I found to access the annotatons is to cast the managed bean to TargetInstanceProxy, and call getTargetClass() like that:


      ((org.jboss.interceptor.util.proxy.TargetInstanceProxy)myManagedBean).getTargetClass().getAnnotations()



      Obviously this is nothing I want in my code. So, my question is:



      • are the annotations removed on purpose? Why?

      • is there any way to access them without using none-portable JBoss code / classes?



      Thanks,


      Hans