1 2 Previous Next 18 Replies Latest reply on Feb 21, 2012 3:28 PM by asoldano

    CDI @Inject in a JAX-WS service impl?

    paul.robinson

      Hello,

       

      I have a JAX-WS service implementation class, that tries to @Inject a bean. The bean does not seem to be injected. If I change the Web service impl to be a stateless session bean, the @Inject is done.

       

      Here's my code, in which the inject is not done:

       

      @WebService(serviceName = "EchoServiceService", portName = "EchoServicePort",
              name = "EchoServiceImpl", targetNamespace = "http://my.org/simple")
      @SOAPBinding(style = SOAPBinding.Style.RPC)
      public class EchoServiceImpl implements IEchoService
      {
           @Inject
          HelloBean hello;
      
          @WebMethod
          public String sayHello(String msg) throws MyException
          {
              //throws a NPE:
              return hello.sayHello(msg);
          }
      }
      

       

      Is this a known limitation of JBossWS, or am I missing something?

       

      Thanks,


      Paul.

        • 1. Re: CDI @Inject in a JAX-WS service impl?
          asoldano

          Hi Paul,

          just to clarify, are you using AS7 here?

          • 2. Re: CDI @Inject in a JAX-WS service impl?
            paul.robinson

            Alessio,

             

            Yes, I'm using AS 7.1.0.CR1b. I can try it on today's master, if you think it may have ben fixed in the meen time.

             

            Paul.

            • 3. Re: CDI @Inject in a JAX-WS service impl?
              asoldano

              I believe this should have already be working, but checking with AS7 master might be a good idea in any case. If it still does not work, we'll try debugging to see what's happening...

              • 4. Re: CDI @Inject in a JAX-WS service impl?
                paul.robinson

                Thanks Alessio,

                 

                Yes it does work. I was doing something stupid. When I converted from  an EJB jar archive to a JAX-WS war archive, I forgot to move the beans.xml from META-INF to WEB-INF .

                 

                Off the top of your head, should I be able to use CDI interceptors on @WebMethod annotated methods? I have that working on EJBs exposed as JAX-WS services, but not for plain JAX-WS services deployed in a war. Again, it's probably something silly I've done when converting my service. But if you know of any issues, off the top of your head, then it might save me some time.

                 

                Paul.

                • 5. Re: CDI @Inject in a JAX-WS service impl?
                  ropalka

                  Paul Robinson wrote:

                   

                  Off the top of your head, should I be able to use CDI interceptors on @WebMethod annotated methods? I have that working on EJBs exposed as JAX-WS services, but not for plain JAX-WS services deployed in a war.

                   

                  It won't work on POJO endpoints AFAIK.

                  But if you'll provide us sample app (reproducer)

                  and will give us some pointers in CDI spec

                  where this is mandatory EE feature,

                  then it's definitely a bug we need to fix.

                  • 6. Re: CDI @Inject in a JAX-WS service impl?
                    paul.robinson

                    Richard,

                     

                    Thanks for the reply,

                     

                    Are you saying that you don't think it works for JAX-WS endpoints that are implemented as POJOs, or that you don't think it work on POJOs full stop? I have it working for POJOs that are neither EJBs or JAX-WS services and also for JAX-WS services that are also EJBs.

                     

                    Also, you ask me to point to something in the CDI spec that says this should work. I can find something that says a POJO must support interceptors. But the spec does not mention JAX-WS for any CDI feature, so the behavior of interceptors on a JAX-WS service implemented as a POJO is not specified.

                     

                    Paul.

                    • 7. Re: CDI @Inject in a JAX-WS service impl?
                      paul.robinson

                      Richard,

                       

                      I've also been talking to Ales on IRC about this issue. He asked for a failing Arquillian test in the Weld suite. I'm including it here as it may explain better, what I'm trying to get working:

                       

                      https://github.com/paulrobinson/core/blob/JAXWS_POJO_with_CDI_interceptor/tests-arquillian/src/test/java/org/jboss/weld/tests/interceptors/jaxws/InterceptorTest.java

                       

                      You can run the test by:

                       

                      Boot AS7.1.0.Final
                      
                      git clone git@github.com:paulrobinson/core.git
                      cd core
                      git checkout JAXWS_POJO_with_CDI_interceptor
                      cd tests-arquillian/
                      mvn install -Pincontainer-remote -Dtest=org.jboss.weld.tests.interceptors.jaxws.InterceptorTest
                      

                       

                      Observe that the test fails with message:

                       

                      junit.framework.AssertionFailedError: Interceptor not invoked
                      
                      • 8. Re: CDI @Inject in a JAX-WS service impl?
                        ropalka

                        Hi Paul,

                         

                           I reviewed your test and I confirm it won't work.

                        Aren't interceptors intended for EJBs only?

                         

                        Rio

                        • 9. Re: CDI @Inject in a JAX-WS service impl?
                          ropalka

                          Paul Robinson wrote:

                          Are you saying that you don't think it works for JAX-WS endpoints that are implemented as POJOs, or that you don't think it work on POJOs full stop?

                          I'm saying it won't work for JAXWS POJO endpoints.

                           

                          Paul Robinson wrote:

                          I have it working for POJOs that are neither EJBs or JAX-WS services and also for JAX-WS services that are also EJBs.

                          This seems to be generic requirement and probably should work also on JAXWS POJOs.

                           

                          Paul Robinson wrote:

                          But the spec does not mention JAX-WS for any CDI feature, so the behavior of interceptors on a JAX-WS service implemented as a POJO is not specified.

                          It should be clarified IMO because it seems it should work also for JAXWS POJOs.

                          This is against our current design and thus won't work for you

                          • 10. Re: CDI @Inject in a JAX-WS service impl?
                            paul.robinson

                            Rio,

                             

                            These are CDI interceptors, not EJB interceptors. CDI interceptors work on POJOs and EJBs. I would have expected CDI to have seen the JAX-WS impl as a POJO and setup the interceptors accordingly.

                             

                            Are you able to comment on my pull request? Two Weld guys (Ales Justin  and Stuart Douglas) think this should work.

                             

                            https://github.com/weld/core/pull/154

                             

                            Thanks,

                             

                            Paul.

                            • 11. Re: CDI @Inject in a JAX-WS service impl?
                              paul.robinson

                              Rio,

                               

                              I just saw your second post. So you are saying you think this should work, but it is not supported by JBossWS?

                               

                              It sounds like I should be creating a feature request / bug report for this, in JBossWS?

                               

                              Paul.

                              • 12. Re: CDI @Inject in a JAX-WS service impl?
                                ropalka

                                Hi Paul,

                                 

                                Paul Robinson wrote:

                                So you are saying you think this should work, but it is not supported by JBossWS?

                                Exactly.

                                 

                                 

                                Paul Robinson wrote:

                                It sounds like I should be creating a feature request / bug report for this, in JBossWS?

                                Yes, please. Ideally with the spec requirements/pointers so we can understand how this is exactly supposed to work.

                                Please note that fix of this issue won't be trivial and might take time It requires non trivial architecture changes/review.

                                 

                                Rio

                                • 13. Re: CDI @Inject in a JAX-WS service impl?
                                  paul.robinson

                                  Thanks Rio,

                                   

                                  I'll cretae the Jira issue soon. I can use EJBs during development, so I can wait.

                                   

                                  Paul.

                                  • 14. Re: CDI @Inject in a JAX-WS service impl?
                                    paul.robinson

                                    Jira'd: https://issues.jboss.org/browse/JBWS-3441

                                     

                                    Is there enough informtion in the issue?

                                     

                                    Paul.

                                    1 2 Previous Next