Index: jackrabbit-webapp/src/main/java/org/apache/jackrabbit/j2ee/RepositoryAccessServlet.java =================================================================== --- jackrabbit-webapp/src/main/java/org/apache/jackrabbit/j2ee/RepositoryAccessServlet.java (revision 554615) +++ jackrabbit-webapp/src/main/java/org/apache/jackrabbit/j2ee/RepositoryAccessServlet.java (working copy) @@ -67,8 +67,13 @@ * the initialized initial context */ private InitialContext jndiContext; - + /** + * if this is set we try to get a Repository from the ServletContext + */ + private String repositoryContextAttributeName; + + /** * the repository */ private Repository repository; @@ -87,6 +92,9 @@ throw new ServletException("Only one repository access servlet allowed per web-app."); } getServletContext().setAttribute(CTX_PARAM_THIS, this); + + repositoryContextAttributeName = getServletConfig().getInitParameter("repository.context.attribute.name"); + log.info("RepositoryAccessServlet initialized."); } @@ -96,7 +104,13 @@ * @return this servlet */ private static RepositoryAccessServlet getInstance(ServletContext ctx) { - return (RepositoryAccessServlet) ctx.getAttribute(CTX_PARAM_THIS); + final RepositoryAccessServlet instance = (RepositoryAccessServlet) ctx.getAttribute(CTX_PARAM_THIS); + if(instance==null) { + throw new IllegalStateException( + "No RepositoryAccessServlet instance in ServletContext, RepositoryAccessServlet servlet not initialized?" + ); + } + return instance; } /** @@ -236,6 +250,25 @@ return null; } } + + /** + * If our config said so, try to retrieve a Repository from the ServletContext + */ + protected Repository getRepositoryByContextAttribute() { + Repository result = null; + if(repositoryContextAttributeName!=null) { + result = (Repository)getServletContext().getAttribute(repositoryContextAttributeName); + + if(log.isDebugEnabled()) { + if(result!=null) { + log.debug("Got Repository from ServletContext attribute '" + repositoryContextAttributeName + "'"); + } else { + log.debug("ServletContext attribute '" + repositoryContextAttributeName + "' does not provide a Repository"); + } + } + } + return result; + } /** * Return the fully qualified name of the class providing the client @@ -257,6 +290,10 @@ public Repository getRepository() { try { if (repository == null) { + // try to get via context attribute + repository = getRepositoryByContextAttribute(); + } + if (repository == null) { // try to retrieve via jndi repository = getRepositoryByJNDI(); } Index: jackrabbit-webapp/src/main/webapp/WEB-INF/web.xml =================================================================== --- jackrabbit-webapp/src/main/webapp/WEB-INF/web.xml (revision 554615) +++ jackrabbit-webapp/src/main/webapp/WEB-INF/web.xml (working copy) @@ -149,6 +149,17 @@ places the one in the bootstrap-config wins. +