4 Replies Latest reply on Sep 29, 2006 8:40 AM by Joan Bordeau

    Inject EJB problem in web service method !!

    Joan Bordeau Newbie

      Hello,

      I try to inject an EJB with @EJB in WebMethod, but that does not works, whereas with InitialContext is ok.

      Is it possible to inject an EJB in a web service method ???

      Regards,
      Joan Bordeau

        • 1. Re: Inject EJB problem in web service method !!
          Joan Bordeau Newbie

          I forgot to specify that I use jboss-4.0.4.GA with jbossws by default.
          And my code :

          @Stateless
          @SecurityDomain("Protected-Web-Services")
          @Interceptors( { LoggerInterceptor.class, ConnectionInterceptor.class })
          @RemoteBinding(jndiBinding = "TestSession")
          @WebService(name = "Test")
          public class TestSessionBean implements TestSession {
          
           private static Logger logger = Logger.getLogger(TestSessionBean.class.getSimpleName());
           @EJB
           ResourcesDAOSession resourcesDAOSession;
          
          @RolesAllowed("ws_resources")
          @WebMethod
          public Resource echo(int idResource) {
           logger.info("DAO : " + this.resourcesDAOSession);
           Resource resource = this.resourcesDAOSession.getResource(idResource);
           logger.info("resource : " + resource);
           return resource;
           }
          


          • 2. Re: Inject EJB problem in web service method !!
            Eric Ray Novice

            if you are using a java client point it to the TestSessionBean?wsdl and it should work. this way you get the bean isntantiated in the EJB container. if you don't reference the web service as a bean then you loose the EJB context and thus you loose the EJB supported injection.

            Same thing happens if you are injecting a @Resource or @PersistenceContext. it's the container that understands the annotations. so if the object is created in the wrong container the annotations are ignored.

            i don't understand the details of how this works, but i do know that the container is very important and i'm sure the jboss web service container doesn't undestand @EJB, but the EJB container does.

            • 3. Re: Inject EJB problem in web service method !!
              Joan Bordeau Newbie

              Thanks for the answer.

              It is that I thought. The containers are different. There are the web container and the EJB container, because when I use an EJB client, the @EJB works, whereas with a web service client does not work.

              I have the same problem when I want to use the security annotation with web service annotation. The context is not propagated, whereas with Axis Web service works.
              I use HTTP Basic authentification, then a file descriptor jboss-web.xml for the propagation context. However I would like use the jbossws to simplify the development and to avoid a layer Axis web service (1.4) supplementary.
              It is the most important problem. I read in the Wiki :
              http://labs.jboss.com/portal/jbossws/user-guide/en/html/secure-ejb.html
              but it does not treat with annotation EJB3.

              So anyone knows how to resolve this problem, it will be great !!!

              Regards

              • 4. Re: Inject EJB problem in web service method !!
                Joan Bordeau Newbie

                I installed the last version of jbossws and now that works.
                I have the annotation authentification with the context propagation.

                @WebService(name = "EndpointInterface")
                @SOAPBinding(style = SOAPBinding.Style.RPC)
                @PortComponent(authMethod = "BASIC", transportGuarantee = "NONE")
                @Stateless
                @SecurityDomain("Protected-Web-Services")
                @Interceptors( { LoggerInterceptor.class, ConnectionInterceptor.class })
                @RemoteBinding(jndiBinding = "TestSession")
                public class TestSessionBean implements TestSession { code }