users@glassfish.java.net

_at_EJB injection works for Servlet, fails for WebServiceEndpoint

From: <glassfish_at_javadesktop.org>
Date: Fri, 21 Mar 2008 09:47:35 PST

Hi,

The following situation is a WAR existing inside an EAR, whereby the EAR contains a single @Stateless session bean deployed in a JAR. Access to the session bean using dependency injection already works within the EAR from a seperate JSF application. The issue is in getting dependency injection to work for the WebService WAR.

Here are snippets from my web.xml file:

<servlet>
    <servlet-name>RoamGatewaySessionServlet</servlet-name>
    <servlet-class>com.roamdata.gateway.webservice.RoamGatewaySessionServlet</servlet-class>
    <load-on-startup>10</load-on-startup>
</servlet>

<servlet>
    <display-name>RoamGatewayService</display-name>
    <servlet-name>RoamGatewayService</servlet-name>
    <servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class>
</servlet>

I have attached additional sun-*.xml files to show how the second servlet entry maps to a web service endpoint class. These entries were based on SUNs J2EE 5 sample code.

In the first entry, @EJB injection annotation for a Local Session Bean works inside the servlet-class.
The injection fails for the second entry.

Here is a snippet from my sun-jaxws.xml file:

<endpoints xmlns='http://java.sun.com/xml/ns/jax-ws/ri/runtime' version='2.0'>
    <endpoint
        name='RoamGatewayService'
        implementation='com.roamdata.gateway.webservice.RoamGatewayImpl'
        url-pattern='/RoamGateway'/>
</endpoints>

Here you can see that the second servlet entry in my web.xml maps to the class com.roamdata.gateway.webservice.RoamGatewayImpl. Again, these were taken from SUN provided sample code.

However, @EJB injection does not work in this class. I get a NullPointerException. Here is how the dependency injection is defined:
    @EJB
    public GatewaySessionLocal gatewaySessionLocal;


Documentation clearly states that a web services end-point inside a web container should support injection for an EJB resource type (http://www.onjava.com/pub/a/onjava/2006/01/04/dependency-injection-java-ee-5.html).

Why is @EJB dependency injection not working for this WebService class? It is in the same WAR as the servlet is.

See also:

http://forums.java.net/jive/thread.jspa?threadID=38298&tstart=30

David
[Message sent by forum member 'dlindsay_roamdata_com' (dlindsay_roamdata_com)]

http://forums.java.net/jive/thread.jspa?messageID=265215