NPE when starting Modshape REST Server with repository running as a service in JBoss AS
akrambenaissi Jan 15, 2012 4:33 PMHi modeshapers,
I am trying to deploying an extended version of the Modshape REST server.
Following the documentation, I created a maven project with the following dependencies:
<dependency> <groupId>org.modeshape</groupId> <artifactId>modeshape-jcr</artifactId> </dependency> <dependency> <groupId>org.modeshape</groupId> <artifactId>modeshape-web-jcr-rest</artifactId> </dependency> <!-- The JCR API --> <dependency> <groupId>javax.jcr</groupId> <artifactId>jcr</artifactId> </dependency>
Then, I just get the original web.xml from modshape-rest.war which is supposed to use JNDI to locate the repositories.
Modeshape is deployed as a service using the binaries provided for JBoss AS 5 and when using the original modshape-rest.war everithing works well.
Here is a code snippet that I used to extend the server:
public static Repository getRepository(String repositoryName) throws RepositoryException { Map<String, String> parameters = new HashMap<String, String>(); String configUrlKey = "org.modeshape.jcr.URL"; String configUrlKey2 = "org.modeshape.web.jcr.JCR_URL"; String configUrl = "jndi:jcr/local?repositoryName=" + repositoryName; parameters.put(configUrlKey, configUrl); parameters.put(configUrlKey2, configUrl); for (RepositoryFactory factory : ServiceLoader.load(RepositoryFactory.class)) { Repository repository = factory.getRepository(parameters); if (repository != null) { return repository; } } throw new RepositoryException(); }
and
public class RenameService { @GET @Path("/rename") @Produces("application/json") public String rename(@Context HttpServletRequest request/*, @PathParam("repositoryName") String rawRepositoryName*/) throws JSONException, RepositoryException { Repository repository = RepositoryUtils.getRepository("repository"); String login = "admin"; char[] password = login.toCharArray(); Credentials credentials = new SimpleCredentials(login, password); Session session = repository.login(credentials, "default"); Node node = session.getNode("passwd"); session.move(node.getPath(), node.getParent().getPath() + "/aaaa"); // Don't forget - not necessarily here at this place: // node.getSession().save(); return "OK"; } }
And when trying to acces the /rename URL I got the following stacktrace:
java.lang.NullPointerException org.modeshape.web.jcr.spi.FactoryRepositoryProvider.getRepository(FactoryRepositoryProvider.java:71) org.modeshape.web.jcr.spi.FactoryRepositoryProvider.getSession(FactoryRepositoryProvider.java:111) org.modeshape.web.jcr.RepositoryFactory.getSession(RepositoryFactory.java:90) org.modeshape.web.jcr.rest.AbstractHandler.getSession(AbstractHandler.java:39) org.modeshape.web.jcr.rest.RepositoryHandler.getWorkspaces(RepositoryHandler.java:33) org.modeshape.web.jcr.rest.JcrResources.getWorkspaces(JcrResources.java:186) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) java.lang.reflect.Method.invoke(Method.java:597) org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:124) org.jboss.resteasy.core.ResourceMethod.invokeOnTarget(ResourceMethod.java:247) org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:212) org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:202) org.jboss.resteasy.core.SynchronousDispatcher.getResponse(SynchronousDispatcher.java:441) org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:418) org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:111) org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:217) org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:159) javax.servlet.http.HttpServlet.service(HttpServlet.java:717) org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
It doesn't seem that my code is even called, but it looks like resteasy could not instanciate correctly.
Question: is it the correct way to extend the REST server ?
Any help would be really appreciated.