2 Replies Latest reply on May 7, 2014 9:53 AM by Alessio Soldano

    Cannot inject resource in jax-ws handler on jboss AS 7

    Christophe Domas Newbie



      I'm trying to inject resources defined in env-entry in a jax-ws handler on jboss AS 7 (I've tried jboss AS 7.1, eap-6.0 and eap-6.1) but the resources are not resolved.

      My web app calls a web-service. On the web-service client I set a handler to add a ws-security token. The username/password are defined in env-entries in web.xml:








      On the client side, I set the handler:


          @HandlerChain(file = "handler-chain.xml")
          private TestServiceClient testService;


          public String testWs() {

              return testService.getTestServiceSOAP().sayHello("hello");



      On the jax-ws handler, I'm trying to inject the username and password:


      public class TokenSOAPHandler implements SOAPHandler<SOAPMessageContext> {


          @Resource(name = "wsUsername")
          String username;


          @Resource(name = "wsPassword")
          String password;


          public boolean handleMessage(SOAPMessageContext context) {



                  System.out.println("injected username: " + username);
                  System.out.println("injected password: " + password);
                  System.out.println(new InitialContext().lookup("java:comp/env/wsUsername"));
                  System.out.println(new InitialContext().lookup("java:comp/env/wsPassword"));
              } catch (NamingException e) {


      But the resources are not resolved with @Resource even if I can see the values in the JNDI context:


      19:00:40,266 INFO  [org.apache.cxf.common.injection.ResourceInjector] (http-localhost/ failed to resolve resource wsUsername

      19:00:40,266 INFO  [org.apache.cxf.common.injection.ResourceInjector] (http-localhost/ failed to resolve resource wsPassword


      18:57:46,274 INFO  [stdout] (http-localhost/ injected username: null

      18:57:46,274 INFO  [stdout] (http-localhost/ injected password: null


      18:57:46,275 INFO  [stdout] (http-localhost/ myName

      18:57:46,275 INFO  [stdout] (http-localhost/ myPassword


      I've read in the spec that resource annotation should work:

      The runtime MUST then carry out any injections requested by the handler, typically via the javax-.annotation.Resource annotation.


      And I see a lot of CXF/JBossWS jira ticket marked this problem "resolved".


      As a workaround I've moved @resource annotations on client and pass the username/password in the message contexte and it works but have several webservices that work this way and want to centralize the injection.


      So what I've done wrong?