jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r901228 - in /jackrabbit/trunk: jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/JcrUtils.java jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/repository/RmiRepositoryFactory.java
Date Wed, 20 Jan 2010 15:15:07 GMT
Author: jukka
Date: Wed Jan 20 15:15:06 2010
New Revision: 901228

URL: http://svn.apache.org/viewvc?rev=901228&view=rev
Log:
JCR-2459: Improved error reporting from JcrUtils.getRepository

Report some more details when failing to access repositories

Modified:
    jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/JcrUtils.java
    jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/repository/RmiRepositoryFactory.java

Modified: jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/JcrUtils.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/JcrUtils.java?rev=901228&r1=901227&r2=901228&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/JcrUtils.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/JcrUtils.java
Wed Jan 20 15:15:06 2010
@@ -139,8 +139,14 @@
                     log.append(": declined");
                 }
             } catch (Exception e) {
-                log.append(": ");
-                log.append(e.getMessage());
+                log.append(": failed");
+                for (Throwable c = e; c != null; c = c.getCause()) {
+                    log.append(newline);
+                    log.append("        because of ");
+                    log.append(c.getClass().getSimpleName());
+                    log.append(": ");
+                    log.append(c.getMessage());
+                }
             }
         }
         log.append(newline);

Modified: jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/repository/RmiRepositoryFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/repository/RmiRepositoryFactory.java?rev=901228&r1=901227&r2=901228&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/repository/RmiRepositoryFactory.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/repository/RmiRepositoryFactory.java
Wed Jan 20 15:15:06 2010
@@ -16,10 +16,16 @@
  */
 package org.apache.jackrabbit.rmi.repository;
 
+import java.io.IOException;
 import java.io.InputStream;
 import java.io.ObjectInputStream;
+import java.net.MalformedURLException;
 import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
 import java.rmi.Naming;
+import java.rmi.NotBoundException;
+import java.rmi.RemoteException;
 import java.util.Hashtable;
 import java.util.Map;
 
@@ -27,6 +33,7 @@
 import javax.jcr.RepositoryException;
 import javax.jcr.RepositoryFactory;
 import javax.naming.InitialContext;
+import javax.naming.NamingException;
 
 import org.apache.jackrabbit.rmi.client.ClientAdapterFactory;
 import org.apache.jackrabbit.rmi.remote.RemoteRepository;
@@ -39,45 +46,100 @@
     @SuppressWarnings("unchecked")
     public Repository getRepository(Map parameters) throws RepositoryException {
         if (parameters != null && parameters.containsKey(REPOSITORY_URI)) {
-            Object parameter = parameters.get(REPOSITORY_URI);
+            URI uri;
             try {
-                URI uri = new URI(parameter.toString().trim());
-                String scheme = uri.getScheme();
-                if ("rmi".equalsIgnoreCase(scheme)) {
-                    return getRepository((RemoteRepository) Naming.lookup(
-                            uri.getSchemeSpecificPart()));
-                } else if ("jndi".equalsIgnoreCase(scheme)) {
-                    Hashtable environment = new Hashtable(parameters);
-                    environment.remove(REPOSITORY_URI);
-                    Object value = new InitialContext(environment).lookup(
-                            uri.getSchemeSpecificPart());
-                    if (value instanceof RemoteRepository) {
-                        return getRepository((RemoteRepository) value);
-                    } else {
-                        return null;
-                    }
-                } else {
-                    InputStream stream = uri.toURL().openStream();
-                    try {
-                        Object remote =
-                            new ObjectInputStream(stream).readObject();
-                        if (remote instanceof RemoteRepository) {
-                            return getRepository((RemoteRepository) remote);
-                        } else {
-                            return null;
-                        }
-                    } finally {
-                        stream.close();
-                    }
-                }
-            } catch (Exception e) {
+                uri = new URI(parameters.get(REPOSITORY_URI).toString().trim());
+            } catch (URISyntaxException e) {
                 return null;
             }
+
+            String scheme = uri.getScheme();
+            if ("rmi".equalsIgnoreCase(scheme)) {
+                return getRmiRepository(uri.getSchemeSpecificPart());
+            } else if ("jndi".equalsIgnoreCase(scheme)) {
+                Hashtable environment = new Hashtable(parameters);
+                environment.remove(REPOSITORY_URI);
+                return getJndiRepository(
+                        uri.getSchemeSpecificPart(), environment);
+            } else {
+                try {
+                    return getUrlRepository(uri.toURL());
+                } catch (MalformedURLException e) {
+                    return null;
+                }
+            }
         } else {
             return null;
         }
     }
 
+    private Repository getUrlRepository(URL url) throws RepositoryException {
+        try {
+            InputStream stream = url.openStream();
+            try {
+                Object remote = new ObjectInputStream(stream).readObject();
+                if (remote instanceof RemoteRepository) {
+                    return getRepository((RemoteRepository) remote);
+                } else {
+                    throw new RepositoryException(
+                            "The resource at URL " + url
+                            + " is not a remote repository stub: "
+                            + remote);
+                }
+            } finally {
+                stream.close();
+            }
+        } catch (ClassNotFoundException e) {
+            throw new RepositoryException(
+                    "The resource at URL " + url
+                    + " requires a class that is not available", e);
+        } catch (IOException e) {
+            throw new RepositoryException(
+                    "Failed to read the resource at URL " + url, e);
+        }
+    }
+
+    @SuppressWarnings("unchecked")
+    private Repository getJndiRepository(String name, Hashtable environment)
+            throws RepositoryException {
+        try {
+            Object value = new InitialContext(environment).lookup(name);
+            if (value instanceof RemoteRepository) {
+                return getRepository((RemoteRepository) value);
+            } else {
+                throw new RepositoryException(
+                        "The JNDI resource " + name
+                        + " is not a remote repository stub: " + value);
+            }
+        } catch (NamingException e) {
+            throw new RepositoryException(
+                    "Failed to look up the JNDI resource " + name, e);
+        }
+    }
+
+    private Repository getRmiRepository(String name)
+            throws RepositoryException {
+        try {
+            Object value = Naming.lookup(name);
+            if (value instanceof RemoteRepository) {
+                return getRepository((RemoteRepository) value);
+            } else {
+                throw new RepositoryException(
+                        "The RMI resource " + name
+                        + " is not a remote repository stub: " + value);
+            }
+        } catch (NotBoundException e) {
+            throw new RepositoryException(
+                    "RMI resource " + name + " not found", e);
+        } catch (MalformedURLException e) {
+            throw new RepositoryException(
+                    "Invalid RMI name: " + name, e);
+        } catch (RemoteException e) {
+            throw new RepositoryException(
+                    "Failed to look up the RMI resource " + name, e);
+        }
+    }
+
     private Repository getRepository(RemoteRepository remote) {
         return new ClientAdapterFactory().getRepository(remote);
     }



Mime
View raw message