2 Replies Latest reply on Apr 15, 2011 6:36 AM by henk de boer

    @Context injection doesn't work in JAX-RS/EJB bean

    henk de boer Master

      Using JBoss AS 6, I have a JAX-RS resource that's also an EJB bean (also see http://community.jboss.org/message/599737).

       

      EJB injections work and the methods are correctly mapped to the declared URLs, but it seems that REST injections do not take place if RestEasy looks up the bean via JNDI.

       

      The following bean is defined in a separate EJB module, and it's JNDI name is declared in web.xml of a web module:

       

      @Produces("application/xml")
      @Path("xxx")
      @Stateless
      public class TestResource {
      
        @Context
        private SecurityContext security;
      
        @EJB
        private SomeEJB someEJB;
      
        @GET
        @Path("bla")
        public User getTest() {
           return "<hi>hi!</hi>";
        }
      
      }
      
      

       

      What happens is:

       

      1. When invoking localhost:8080/myroot/xxx/bla, getTest() is correctly called.
      2. someEJB has a correct stub reference
      3. security remains null

       

      If I put a similar bean directly in the web module and omit the EJB annotations, the SecurityContext is correctly injected:

       

      @Produces("application/xml")
      @Path("yyy")
      public class TestWebResource {
      
        @Context
        private SecurityContext security;
      
        @GET
        @Path("bla")
        public User getTest() {
           return "<hi>hi!</hi>";
        }
      
      }
      
      

       

      From some old posts I learned this was a known problem in the past (2009), but would be fixed with the upcoming Java EE 6/JAX-RS integration.

       

      Am I doing something wrong or has this integration never been done for RestEASY?