users@glassfish.java.net

EntityManager injection into a WebService

From: Gurdeep Singh <gurdeep291_at_yahoo.com>
Date: Fri, 22 Apr 2011 03:02:40 -0700 (PDT)

Hi All,

I have a POJO declared as webservice. The WSDL generation and function invocation work just fine. However if I try to inject an EntityManager into it, it doesn't work. It seems to work fine in a Servlet though. Is it unsupported or there is additional configuration to be done. I am trying to inject it in a web service because I want to run my application in a web container later. I see the same behavior with JBoss.

Following are my entries in the web.xml and sun-jaxws.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
  http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
           version="2.5">

    <listener>
        <listener-class>com.sun.xml.ws.transport.http.servlet.WSServletContextListener</listener-class>
    </listener>
    <servlet>
        <display-name>WebServicesServlet</display-name>
        <servlet-name>WebServicesServlet</servlet-name>
        <servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>WebServicesServlet</servlet-name>
        <url-pattern>/services/*</url-pattern>        
    </servlet-mapping>

     <servlet>
        <servlet-name>TestServlet</servlet-name>
        <servlet-class>tracker.servlet.TestServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>TestServlet</servlet-name>
        <url-pattern>/test</url-pattern>        
    </servlet-mapping>
</web-app>



------sun-jaxws.xml-----

<?xml version="1.0" encoding="UTF-8"?>
<endpoints xmlns='http://java.sun.com/xml/ns/jax-ws/ri/runtime' version='2.0'>
    <endpoint
        name='EmployeeService'
        implementation='tracker.services.Employee'
        url-pattern='/services/employee'/>
</endpoints>


Thanks,

Gurdeep