users@glassfish.java.net

JAX-WS _at_Resource injection fails with HTTP Basic Authentication

From: Ryan de Laplante <ryan_at_ijws.com>
Date: Mon, 04 Jun 2007 12:33:12 -0400

Hi,

I recently decided to add http basic authentication to a web service.
Using a web browser I was able to confirm that I now need to enter a
username/password before the WSDL will be displayed.

I use a jax-ws web service client inside a @Stateless EJB session bean.
I have my @WebServiceRef near the top of the class, and it worked well
until I added the HTTP Basic authentication (as expected). I'm getting
an exception that indicates the web service client was not able to be
injected into my EJB.

EJB5070: Exception creating stateless session bean : [{0}]
com.sun.enterprise.InjectionException: Exception attempting to inject
Env-Prop: com.company.product.dao.MySessionBean/service_at_Field-Injectable
Resource. Class name = com.company.product.dao.MySessionBean Field
name=service_at_javax.jws.WebServiceRef@@@ into class
com.company.product.dao.MySessionBean
        at
com.sun.enterprise.util.InjectionManagerImpl._inject(InjectionManagerImpl.java:374)
        at
com.sun.enterprise.util.InjectionManagerImpl.inject(InjectionManagerImpl.java:193)
        at
com.sun.enterprise.util.InjectionManagerImpl.injectInstance(InjectionManagerImpl.java:114)
        at
com.sun.ejb.containers.StatelessSessionContainer.createStatelessEJB(StatelessSessionContainer.java:519)
     ..........
Caused by: javax.xml.ws.WebServiceException: Failed to access the WSDL
at: https://ryan1.orillia.ijws.local:8181/MyService/MyService?wsdl. It
failed with:
        Server returned HTTP response code: 401 for URL:
https://ryan1.orillia.ijws.local:8181/MyService/MyService?wsdl.
        at
com.sun.xml.ws.wsdl.parser.RuntimeWSDLParser.tryWithMex(RuntimeWSDLParser.java:136)
        at
com.sun.xml.ws.wsdl.parser.RuntimeWSDLParser.parse(RuntimeWSDLParser.java:122)
        at
com.sun.xml.ws.client.WSServiceDelegate.parseWSDL(WSServiceDelegate.java:226)
 

Every webpage I have read about HTTP Basic authentication with JAX-WS
tells me to add the following code before executing one of the web
service methods:

MyService port = service.getMyServicePort();
((BindingProvider)port).getRequestContext().put(BindingProvider.USERNAME_PROPERTY,
"username");
((BindingProvider)port).getRequestContext().put(BindingProvider.PASSWORD_PROPERTY,
"secret");


That doesn't make a difference because the exception is happening while
the EJB is being created, and the web service reference is being
injected. I suspect it is trying to access the WSDL before I have a
chance to tell it a username/password to use.



Thanks,
Ryan