Problem with Jcr 2.0 style of looking up Repository instance using JNDI
penkween Aug 22, 2011 12:58 AMHi ,
I am using Modeshape-2.6.0-Beta2 and currently testing using Glassfish V3.1.1 with a Web App and having problem of looking up Repository instance using the following code with error dump. This error is similar to a last year forum dicussion ( http://community.jboss.org/thread/155998 ) but not sure if it has been fixed or it is a new issue. Anybody, appreciate your help . Thanks in advance.
Note:
Under the same environment, have tested the following of obtaining Repository instance:
1. Using jcr 1.0 style - OK
eg.
InitialContext initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
Repository repository = (Repository) envCtx.lookup("jcr/local");
2. Using CDI injection using Seam-Jcr-3.0.0-Alpha2 - OK
eg.
@Inject
@JcrConfiguration(name = "org.modeshape.jcr.URL", value = "file:///C:/test/configRepository.xml?repositoryName=Cars")
Repository repository;
3. Using jcr 2.0 style
OK if using -> configUrl = "file:///C:/test/configRepository.xml?repositoryName=Cars";
Fail if using -> configUrl = "jndi:jcr/local?repositoryName=Cars";
* Codes is shown below*
web.xml
=============================================================================================
<resource-env-ref>
<description>Repository</description>
<resource-env-ref-name>jcr/local</resource-env-ref-name>
<resource-env-ref-type>javax.jcr.Repository</resource-env-ref-type>
</resource-env-ref>
[Glassfish]\domains\domain1\config\domain.xml
=============================================================================================
<custom-resource res-type="javax.jcr.Repository" jndi-name="jcr/local" factory-class="org.modeshape.jcr.JndiRepositoryFactory">
<property name="repositoryName" value="Cars"></property>
<property name="auth" value="Container"></property>
<property name="configFile" value="configRepository.xml"></property>
</custom-resource>
Codes
=============================================================================================
String configUrl = "jndi:jcr/local?repositoryName=Cars";
Map<String, String> parameters = Collections.singletonMap("org.modeshape.jcr.URL", configUrl);
//Getting Repository via Repository Factory - jcr 2.0 style
for (RepositoryFactory factory : ServiceLoader.load(RepositoryFactory.class)) {
System.out.println("Trying to load Repository #" + i++ + " using: " + factory.toString()); //for debug
repository = factory.getRepository(parameters);
if (repository != null) {
break;
}
}
System.out.println("Repository = " + repository); <----------------------factory.getRepository(parameters) actually return NULL over here !
session = repository.login(); <----------------------FAIL ! Program stop here mainly because repository is NULL (Pls refer to Errors dump below)
Errors
=============================================================================================
INFO: Trying to load Repository #1 using: org.modeshape.jcr.JcrRepositoryFactory@74a7e7
INFO: JcrEngine starting...
INFO: JcrEngine started in 3681 ms
INFO: Completed starting the "Cars" repository
INFO: Repository = null <--------------------- It seem like Cars repository started but the factory return a NULL repository, not sure why ?
WARNING: StandardWrapperValve[test1]: PWC1406: Servlet.service() for servlet test1 threw exception
java.lang.NullPointerException
at test.Test1.testJndiLookup(Test1.java:144)
at test.Test1.processRequest(Test1.java:90)
at test.Test1.doGet(Test1.java:299)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:734)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1539)
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:330)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:174)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:828)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:725)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1019)
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:722)