users@glassfish.java.net

Re: JAX-RS Servlet - EntityManagerFactory.createEntityManager() throwing null pointer exception - Glassfish 3.1

From: Arun Gupta <arun.p.gupta_at_oracle.com>
Date: Sun, 10 Apr 2011 11:28:41 -0700

Did you add @ManagedBean on your JAX-RS resource ?

-Arun

On 4/10/11 9:46 AM, forums_at_java.net wrote:
> I appreciate the efforts of Arun gupta for publishing Screencast #31:
> Java EE
> 6 using GlassFish and Eclipse 3.6 - Oracle Enterprise Pack for Eclipse
> 11.1.1.6 is now available - 5 new screencasts [1]. This was really helpful.
> I tried the examples using
> oepe-helios-installer-11.1.1.7.1.201103091755-win32 and ogs-3.1-windows-ml.
> While trying the example for JAX-RS (the last one), i facing
> NullPointerException while creating entity manager from the injected entity
> manager factory. below is the exception stacktrace. It would be helpful,
> to you know your insight. This exception occurs exactly while creating
> entity manager. However, the same approach works with other example when
> entitymanagerfactory is injected to HelloServlet.
> SEVERE: The RuntimeException could not be mapped to a response, re-throwing
> to the HTTP container
> java.lang.NullPointerException
> at resource.SimpleResource.getXml(SimpleResource.java:40)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>
> at java.lang.reflect.Method.invoke(Method.java:597)
> at
> com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$TypeOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:167)
>
> at
> com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:70)
>
> at
> com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:279)
>
> at
> com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:86)
>
> at
> com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:136)
>
> at
> com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:74)
>
> at
> com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1347)
>
> at
> com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1279)
>
> at
> com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1229)
>
> at
> com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1219)
>
> at
> com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:419)
>
> at
> com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537)
>
> at
> com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:699)
>
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:848)
> at
> org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1534)
> at
> org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
>
> at
> org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
>
> at
> org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
>
> at
> org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
> at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:98)
> at
> com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:91)
>
> at
> org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:162)
>
> at
> org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:326)
>
> at
> org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:227)
> at
> com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:170)
>
> at
> com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:822)
> at
> com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:719)
> at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1013)
> at
> com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:225)
>
> at
> com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
>
> at
> com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
> at
> com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
> at
> com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
> at
> com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
>
> at
> com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
>
> at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
> at
> com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
>
> at
> com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
>
> at java.lang.Thread.run(Thread.java:662)
> WARNING: StandardWrapperValve[JAX-RS Servlet]: PWC1406:
> Servlet.service() for
> servlet JAX-RS Servlet threw exception
> java.lang.NullPointerException
> at resource.SimpleResource.getXml(SimpleResource.java:40)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>
> .....
>
> has this behavior of nullpointerexception been observed by anyone?
>
>
> [1] http://blogs.sun.com/arungupta/entry/screencast_31_java_ee_6
>
> --
>
> [Message sent by forum member 'mathivananp']
>
> View Post: http://forums.java.net/node/790553
>
>

-- 
Blog: http://blogs.sun.com/arungupta
Twitter: http://twitter.com/arungupta