NPE after looking up for a repository with JNDI
zazo7 Aug 31, 2010 5:27 PMAt first I thought I'm seeing this, but Randal explained to me that I'm wrong and asked to start a new discussion here. So here is my problem:
I've deployed modeshape and modeshape-rest.war (exploded) in Tomcat. Everything works fine, both apps are started, a test jsp page connects to my repo, but when I do GET on http://localhost:8080/modeshape-rest.war/resources I get the following exception:
SEVERE: Servlet.service() for servlet Resteasy threw exception
org.jboss.resteasy.spi.UnhandledException: java.lang.NullPointerException
at org.jboss.resteasy.core.SynchronousDispatcher.handleApplicationException(SynchronousDispatcher.java:263)
at org.jboss.resteasy.core.SynchronousDispatcher.handleException(SynchronousDispatcher.java:169)
at org.jboss.resteasy.core.SynchronousDispatcher.handleInvokerException(SynchronousDispatcher.java:146)
at org.jboss.resteasy.core.SynchronousDispatcher.getResponse(SynchronousDispatcher.java:456)
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:418)
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:111)
at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:217)
at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:159)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:861)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:579)
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1584)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.NullPointerException
at org.modeshape.web.jcr.spi.FactoryRepositoryProvider.getRepository(FactoryRepositoryProvider.java:71)
at org.modeshape.web.jcr.spi.FactoryRepositoryProvider.getSession(FactoryRepositoryProvider.java:108)
at org.modeshape.web.jcr.RepositoryFactory.getSession(RepositoryFactory.java:90)
at org.modeshape.web.jcr.rest.AbstractHandler.getSession(AbstractHandler.java:40)
at org.modeshape.web.jcr.rest.RepositoryHandler.getWorkspaces(RepositoryHandler.java:36)
at org.modeshape.web.jcr.rest.JcrResources.getWorkspaces(JcrResources.java:186)
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 org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:124)
at org.jboss.resteasy.core.ResourceMethod.invokeOnTarget(ResourceMethod.java:247)
at org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:212)
at org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:202)
at org.jboss.resteasy.core.SynchronousDispatcher.getResponse(SynchronousDispatcher.java:441)
... 17 more
snippet from my conf/context.xml :
<Resource name="jcr/local"
auth="Container"
type="javax.jcr.Repository"
factory="org.modeshape.jcr.JndiRepositoryFactory"
configFile="c:\apps\apache-tomcat-6.0.29\webapps\modeshape\WEB-INF\lib\modeshape-config.xml?repositoryName=ANJnb6arAB8c07rsXEnCtA"
repositoryName="ANJnb6arAB8c07rsXEnCtA" />
test.jsp :
<%
Session sess = null;
try {
InitialContext initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
Repository repo = (Repository) envCtx.lookup("jcr/local");
sess = repo.login(new SimpleCredentials("admin", "admin".toCharArray()));
out.println("Primary node type name: "+sess.getRootNode().getPrimaryNodeType().getName());
} catch (Exception ex) {
ex.printStackTrace();
} finally {
if (sess != null) sess.logout();
}
%>
web.xml for the modeshape-rest.war :
<context-param>
<param-name>org.modeshape.web.jcr.JCR_URL</param-name>
<param-value>jndi:jcr\local</param-value>
</context-param>
and finally an excerpt from the log :
org.jboss.resteasy.core.SynchronousDispatcher 2010-08-31 16:36:35,474 -- DEBUG -- PathInfo: /resources
org.modeshape.jcr.JcrRepositoryFactory 2010-08-31 16:36:35,615 -- DEBUG -- Could not load engine from URL: jndi:jcr\local
I don't have access to Modeshape's source code, but I took a look at JcrRepositoryFactory and noticed that the JcrRepositoryFactory#getRepositoriesFromJndi, which is probably called in my case, expects that the object under the JNDI name is type of Repositories. While in fact I'd put there a javax.jcr.Repository. Is that the reason why I receive the exception?
How can I fix this?