-
1. Re: EntityManager injection in Webservice
asoldano Jan 4, 2008 3:46 AM (in response to nudelaug)AFAIK the injection requires your class to be an EJB.
-
2. Re: EntityManager injection in Webservice
heiko.braun Jan 7, 2008 9:34 AM (in response to nudelaug)Right, injection only works on EJB endpoints.
-
3. Re: EntityManager injection in Webservice
froden Jan 16, 2008 9:19 AM (in response to nudelaug)I have a similar problem.
The interface for the EJB:package services; import javax.ejb.Local; @Local public interface TestServiceInterface { public String getString(); }
The EJB itself:package services; import javax.ejb.Stateless; import javax.jws.WebMethod; import javax.jws.WebService; import javax.jws.soap.SOAPBinding; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; @Stateless @WebService @SOAPBinding(style=SOAPBinding.Style.RPC) public class TestService implements TestServiceInterface { @PersistenceContext private EntityManager em; @WebMethod public String getString() { System.out.println("em: " + em); return "Quite frankly, it gives me the heebie jeebies."; } }
The web service is defined in my web.xml like this:<servlet> <servlet-name>TestService</servlet-name> <servlet-class>services.TestService</servlet-class> </servlet> <servlet-mapping> <servlet-name>TestService</servlet-name> <url-pattern>/TestService.ws</url-pattern> </servlet-mapping> </servlet>
The web service works like it should, but the EntityManager is not injected. System.out.println("em: " + em); in the webmethod always prints a null.
Any clues? -
4. Re: EntityManager injection in Webservice
froden Jan 16, 2008 9:21 AM (in response to nudelaug)Sorry - forgot to mention that I use JBoss AS 4.2.0 with JBossWS 2.0.0.
-
5. Re: EntityManager injection in Webservice
ropalka Jan 16, 2008 9:33 AM (in response to nudelaug)Remove the web.xml file. It's not necessary because your webservice is EJB3 not POJO. You can use @WebContext annotation to specify/customize the request binding path
-
6. Re: EntityManager injection in Webservice
froden Jan 16, 2008 12:12 PM (in response to nudelaug)Err, it actually turns out that I'm using JBossWS 1.2.1, not 2.0.0..
Regardless, I removed the and <servlet-mapping/> and added the annotation @WebContext(contextRoot="/ws") to the EJB.
The webservice is now deployed at localhost/TestServiceService/TestService. Shouldn't it be localhost/ws/TestService? -
7. Re: EntityManager injection in Webservice
froden Jan 16, 2008 12:15 PM (in response to nudelaug)Please disregard the last post, the angle brackets were messing up.
Err, it actually turns out that I'm using JBossWS 1.2.1, not 2.0.0..
Regardless, I removed the servlet and servlet-mapping from web.xml and added the annotation @WebContext(contextRoot="/ws") to the EJB.
The webservice is now deployed at localhost/TestServiceService/TestService. Shouldn't it be localhost/ws/TestService? -
8. Re: EntityManager injection in Webservice
froden Jan 16, 2008 1:14 PM (in response to nudelaug)I guess I should also add that after I had removed the servlet and servlet mapping, and added the WebContext annotation, calling the web service would cause the following exception:
19:05:06,212 ERROR [SOAPFaultHelperJAXWS] SOAP request exception org.jboss.ws.WSException: Cannot obtain container from Dispatcher: jboss.j2ee:ear=Community.ear,jar=Community-1.0.jar,name=MyService,service=EJB3 at org.jboss.ws.integration.jboss42.ServiceEndpointInvokerEJB3.invokeServiceEndpointInstance(ServiceEndpointInvokerEJB3.java:109) at org.jboss.ws.core.server.AbstractServiceEndpointInvoker.invoke(AbstractServiceEndpointInvoker.java:207) at org.jboss.ws.core.server.ServiceEndpoint.processRequest(ServiceEndpoint.java:212) at org.jboss.ws.core.server.ServiceEndpointManager.processRequest(ServiceEndpointManager.java:448) at org.jboss.ws.core.server.AbstractServiceEndpointServlet.doPost(AbstractServiceEndpointServlet.java:114) at javax.servlet.http.HttpServlet.service(HttpServlet.java:710) at org.jboss.ws.core.server.AbstractServiceEndpointServlet.service(AbstractServiceEndpointServlet.java:75) at javax.servlet.http.HttpServlet.service(HttpServlet.java:803) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175) at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179) at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104) at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:241) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:580) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447) at java.lang.Thread.run(Thread.java:595) 19:05:06,221 ERROR [SOAPFaultHelperJAXWS] SOAP request exception org.jboss.ws.WSException: Cannot obtain container from Dispatcher: jboss.j2ee:ear=Community.ear,jar=Community-1.0.jar,name=MyService,service=EJB3 at org.jboss.ws.integration.jboss42.ServiceEndpointInvokerEJB3.invokeServiceEndpointInstance(ServiceEndpointInvokerEJB3.java:109) at org.jboss.ws.core.server.AbstractServiceEndpointInvoker.invoke(AbstractServiceEndpointInvoker.java:207) at org.jboss.ws.core.server.ServiceEndpoint.processRequest(ServiceEndpoint.java:212) at org.jboss.ws.core.server.ServiceEndpointManager.processRequest(ServiceEndpointManager.java:448) at org.jboss.ws.core.server.AbstractServiceEndpointServlet.doPost(AbstractServiceEndpointServlet.java:114) at javax.servlet.http.HttpServlet.service(HttpServlet.java:710) at org.jboss.ws.core.server.AbstractServiceEndpointServlet.service(AbstractServiceEndpointServlet.java:75) at javax.servlet.http.HttpServlet.service(HttpServlet.java:803) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175) at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179) at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104) at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:241) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:580) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447) at java.lang.Thread.run(Thread.java:595)
Opening the wsdl however, works fine. -
9. Re: EntityManager injection in Webservice
froden Jan 17, 2008 4:02 AM (in response to nudelaug)Are any of the following features limited to JBossWS >=2.0.0?
-The @WebContext annotation
-Using an EJB as a web service class
-Injection of the EntityManager using the @PersistenceContext
When I'm using the @WebContext parameter instead of the servlet and servlet-mapping in web.xml, I get exceptions when calling the web service method. If I instead use the servlet and servlet mapping, injection of the EntityManager wont work. -
10. Re: EntityManager injection in Webservice
froden Jan 18, 2008 4:44 AM (in response to nudelaug)Having stopped being an idiot, I guess I can answer my own questions above.
- Is the @WebContext annotation JBossWS >= 2.0.0 only? No. My problem was that I had imported org.jboss.wsf.spi.annotation.WebContext instead of org.jboss.ws.annotation.WebContext.
- Is using an EJB as a web service class possible in version >=2.0.0 only? No.
- Is injection of EntityManager with @PersistenceContext limited to version >=2.0.0? No
Perhaps this can be helpful for someone. -
11. Re: EntityManager injection in Webservice
kanumalla Mar 24, 2008 4:33 AM (in response to nudelaug)wtf!