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

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

    domak

      Hi,

       

      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:

       

      web.xml:

       

         <env-entry>
              <env-entry-name>wsUsername</env-entry-name>
              <env-entry-type>java.lang.String</env-entry-type>
              <env-entry-value>myName</env-entry-value>
          </env-entry>

       

          <env-entry>
              <env-entry-name>wsPassword</env-entry-name>
              <env-entry-type>java.lang.String</env-entry-type>
              <env-entry-value>myPassword</env-entry-value>
          </env-entry>

       

      On the client side, I set the handler:

       

          @HandlerChain(file = "handler-chain.xml")
          @WebServiceRef
          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;

       

          @Override
          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) {
                  e.printStackTrace();
              }

       

      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/127.0.0.1:8080-1) failed to resolve resource wsUsername

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

       

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

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

       

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

      18:57:46,275 INFO  [stdout] (http-localhost/127.0.0.1:8080-1) 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?

      Thanks.