RepositoryAccessServlet fails to get jndi.name
----------------------------------------------

                 Key: JCR-2935
                 URL: https://issues.apache.org/jira/browse/JCR-2935
             Project: Jackrabbit Content Repository
          Issue Type: Bug
          Components: config, jackrabbit-webapp
    Affects Versions: 2.2.4
            Reporter: Gustavo Orair
            Priority: Trivial


The RepositoryAccessServlet provided in JackRabbit WebApp lookup for a 
repository.name instead of jndi.name.
By default both variables has the same value, if the user doesn't customize 
WEB-INF/template/bootstrap.properties or config/jackrabbit/boostrap.properties 
Jackrabbit works.

Otherwise, if the user customize bootstrap.properties causing jndi.name has a 
different value compared to repository.name the servlet will register the JNDI 
perfectly but will fail to lookup for the resource.

An example of a config/jackrabbit/bootstrap.properties that will fail is:
#bootstrap properties for the repository startup servlet.
#Wed Mar 30 12:35:24 BRT 2011
jndi.name=jcr/RepositorioJCR
repository.home=/scratch/jcr/repositorios/coletaCVM
jndi.enabled=true
rmi.enabled=false
repository.name=RepositorioJCR
repository.config=/scratch/jcr/repositorios/coletaCVM/repository.xml

Note: jndi.name and repository.name has different values.

To fix this issue one should edit the getRepositoryByJNDI() function at 
http://svn.apache.org/repos/asf/jackrabbit/trunk/jackrabbit-webapp/src/main/java/org/apache/jackrabbit/j2ee/RepositoryAccessServlet.java.

    /**
     * Checks if the repository is available via JNDI and returns it.
     * @return the repository or <code>null</code>
     * @throws ServletException if this servlet is not properly configured.
     */
    private Repository getRepositoryByJNDI() throws ServletException {
        BootstrapConfig config = getConfig();
        if (!config.getJndiConfig().isValid() || 
!config.getJndiConfig().enabled()) {
            return null;
        }
        // acquire via JNDI
        String repositoryName = config.getRepositoryName();
        InitialContext ctx = getInitialContext();
        if (ctx == null) {
            return null;
        }
        try {
            Repository r = (Repository) ctx.lookup(repositoryName);
            log.info("Acquired repository via JNDI.");
            return r;
        } catch (NamingException e) {
            log.error("Error while retrieving repository using JNDI (name={})", 
repositoryName, e);
            return null;
        }
    }

Change the line 
        String repositoryName = config.getRepositoryName();
To:
        String repositoryName = config.getJndiConfig().getJndiName();


--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to