users@jersey.java.net

Re: [Jersey] NullPointerException

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Fri, 23 Oct 2009 16:30:14 +0200

Hi Roan,

Can you send code snippets for your resource class, BaseDAO and
BaseDAOImpl? as i am not clear the the relationships.

Are you attempting to inject the BaseDAO as follows:

  @EJB BaseDAO dao

in your resource class?


Fo so, then just like Jersey out of the box does not support injection
@PersistenceUnit (and you have to use a special servlet) it does not
support injection of @EJB. For Java EE 6 this will be supported with
managed beans. In the interim you can register your own injectable
provider class, an example of which is here:

http://kenai.com/projects/puj/sources/arena/content/arena-http/src/main/java/com/kenai/puj/arena/http/EJBProvider.java?rev=188

Make sure that class is registered in the same manner as root resource
classes.

Paul.


On Oct 23, 2009, at 4:20 PM, Roan Brasil Monteiro wrote:

> Hello,
>
> I got the Bookmark example, it has jersey e JPA integrate, I would
> like to add EJB lib, and I did. My question is, do I need to set up
> the web.xml file? What should I add? Currently my web.xml is like
> bellow. Do I need to configure something else? I am getting
> NullPointerException when I made my BaseDAOImpl with @Stateless
> anotation implementing a @Remote interface BaseDAO and on the
> BaseDAOImpl I am injecting with @PersistenceUnit on
> EntityManagerFactory, but I am getting NullPointerException, can
> someone help me please? P.S.-> My Resource class is calling the
> BaseDAOImpl.
>
> <?xml version="1.0" encoding="UTF-8"?>
> <web-app version="2.5" 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
> ">
> <servlet>
> <servlet-name>Jersey Web Application</servlet-name>
> <servlet-
> class>com.sun.jersey.server.impl.container.servlet.ServletAdaptor</
> servlet-class>
> <init-param>
> <param-name>com.sun.jersey.config.feature.Redirect</
> param-name>
> <param-value>true</param-value>
> </init-param>
> <init-param>
> <param-name>unit:citespacePU</param-name>
> <param-value>persistence/citespace</param-value>
> </init-param>
> <load-on-startup>1</load-on-startup>
> </servlet>
> <servlet-mapping>
> <servlet-name>Jersey Web Application</servlet-name>
> <url-pattern>/resources/*</url-pattern>
> </servlet-mapping>
> <session-config>
> <session-timeout>
> 30
> </session-timeout>
> </session-config>
> <welcome-file-list>
> <welcome-file>
> index.jsp
> </welcome-file>
> </welcome-file-list>
> <persistence-unit-ref>
> <persistence-unit-ref-name>persistence/citespace</
> persistence-unit-ref-name>
> <persistence-unit-name>citespacePU</persistence-unit-name>
> </persistence-unit-ref>
> <resource-ref>
> <res-ref-name>UserTransaction</res-ref-name>
> <res-type>javax.transaction.UserTransaction</res-type>
> <res-auth>Container</res-auth>
> </resource-ref>
> </web-app>
>
>
> --
> Atenciosamente,
>
> Roan Brasil Monteiro
> http://roanbrasil.wordpress.com/