jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r543779 - in /jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons: repository/JNDIRepository.java repository/JNDIRepositoryFactory.java servlet/JNDIRepositoryServlet.java
Date Sat, 02 Jun 2007 20:31:58 GMT
Author: jukka
Date: Sat Jun  2 13:31:57 2007
New Revision: 543779

URL: http://svn.apache.org/viewvc?view=rev&rev=543779
Log:
JCR-956: Changed the JNDI repository proxy to use lazy loading only for the lookup within
a JNDI context, not for instantiating the JNDI context itself. Otherwise clients in different
threads or in different class loaders (for example when accessing the repository proxy from
another webapp) may end up using separate JNDI contexts.

Modified:
    jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/repository/JNDIRepository.java
    jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/repository/JNDIRepositoryFactory.java
    jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/servlet/JNDIRepositoryServlet.java

Modified: jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/repository/JNDIRepository.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/repository/JNDIRepository.java?view=diff&rev=543779&r1=543778&r2=543779
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/repository/JNDIRepository.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/repository/JNDIRepository.java
Sat Jun  2 13:31:57 2007
@@ -16,7 +16,7 @@
  */
 package org.apache.jackrabbit.commons.repository;
 
-import java.util.Hashtable;
+import javax.naming.Context;
 
 /**
  * Proxy for a repository bound in JNDI. The configured repository is
@@ -30,11 +30,11 @@
     /**
      * Creates a proxy for a repository in the given JNDI location.
      *
-     * @param environment JNDI environment settings
+     * @param context JNDI context
      * @param name JNDI name of the proxied repository
      */
-    public JNDIRepository(Hashtable environment, String name) {
-        super(new JNDIRepositoryFactory(environment, name));
+    public JNDIRepository(Context context, String name) {
+        super(new JNDIRepositoryFactory(context, name));
     }
 
 }

Modified: jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/repository/JNDIRepositoryFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/repository/JNDIRepositoryFactory.java?view=diff&rev=543779&r1=543778&r2=543779
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/repository/JNDIRepositoryFactory.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/repository/JNDIRepositoryFactory.java
Sat Jun  2 13:31:57 2007
@@ -16,11 +16,9 @@
  */
 package org.apache.jackrabbit.commons.repository;
 
-import java.util.Hashtable;
-
 import javax.jcr.Repository;
 import javax.jcr.RepositoryException;
-import javax.naming.InitialContext;
+import javax.naming.Context;
 import javax.naming.NamingException;
 
 /**
@@ -29,9 +27,9 @@
 public class JNDIRepositoryFactory implements RepositoryFactory {
 
     /**
-     * JNDI environment settings.
+     * JNDI context from which to look up the repository.
      */
-    private final Hashtable environment;
+    private final Context context;
 
     /**
      * JNDI name of the repository.
@@ -41,11 +39,11 @@
     /**
      * Creates a factory for looking up a repository from JNDI.
      *
-     * @param environment JNDI environment settings
+     * @param context JNDI context
      * @param name JNDI name of the repository
      */
-    public JNDIRepositoryFactory(Hashtable environment, String name) {
-        this.environment = environment;
+    public JNDIRepositoryFactory(Context context, String name) {
+        this.context = context;
         this.name = name;
     }
 
@@ -57,7 +55,7 @@
      */
     public Repository getRepository() throws RepositoryException {
         try {
-            Object repository = new InitialContext(environment).lookup(name);
+            Object repository = context.lookup(name);
             if (repository instanceof Repository) {
                 return (Repository) repository;
             } else if (repository == null) {

Modified: jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/servlet/JNDIRepositoryServlet.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/servlet/JNDIRepositoryServlet.java?view=diff&rev=543779&r1=543778&r2=543779
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/servlet/JNDIRepositoryServlet.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/servlet/JNDIRepositoryServlet.java
Sat Jun  2 13:31:57 2007
@@ -21,6 +21,8 @@
 
 import javax.jcr.Repository;
 import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.servlet.ServletException;
 
 import org.apache.jackrabbit.commons.repository.JNDIRepository;
 
@@ -63,19 +65,25 @@
      *
      * @return JNDI repository proxy
      */
-    protected Repository getRepository() {
-        String location = Repository.class.getName().replace('.', '/');
-        Hashtable environment = new Hashtable();
-        Enumeration names = getInitParameterNames();
-        while (names.hasMoreElements()) {
-            String name = (String) names.nextElement();
-            if (name.equals("location")) {
-                location = getInitParameter(name);
-            } else if (!name.equals(Repository.class.getName())) {
-                environment.put(name, getInitParameter(name));
+    protected Repository getRepository() throws ServletException {
+        try {
+            String location = Repository.class.getName().replace('.', '/');
+            Hashtable environment = new Hashtable();
+            Enumeration names = getInitParameterNames();
+            while (names.hasMoreElements()) {
+                String name = (String) names.nextElement();
+                if (name.equals("location")) {
+                    location = getInitParameter(name);
+                } else if (!name.equals(Repository.class.getName())) {
+                    environment.put(name, getInitParameter(name));
+                }
             }
+            return new JNDIRepository(
+                    new InitialContext(environment), location);
+        } catch (NamingException e) {
+            throw new ServletException(
+                    "Repository not found: Invalid JNDI context", e);
         }
-        return new JNDIRepository(environment, location);
     }
 
 }



Mime
View raw message