jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cko...@apache.org
Subject svn commit: r1422975 - in /jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi: client/SafeClientRepository.java repository/RmiRepositoryFactory.java
Date Mon, 17 Dec 2012 15:17:10 GMT
Author: ckoell
Date: Mon Dec 17 15:17:08 2012
New Revision: 1422975

URL: http://svn.apache.org/viewvc?rev=1422975&view=rev
Log:
JCR-3459 RmiRepositoryFactory regression, invalid stream header

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

Modified: jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/client/SafeClientRepository.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/client/SafeClientRepository.java?rev=1422975&r1=1422974&r2=1422975&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/client/SafeClientRepository.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/client/SafeClientRepository.java
Mon Dec 17 15:17:08 2012
@@ -53,7 +53,7 @@ public abstract class SafeClientReposito
     public SafeClientRepository(LocalAdapterFactory factory) {
         super(factory);
         try {
-            remote = getRemoteRepository();
+            remote = getRemoteRepository(true);
         } catch (RemoteException e) {
             remote = new BrokenRemoteRepository(e);
         }
@@ -68,13 +68,34 @@ public abstract class SafeClientReposito
     protected abstract RemoteRepository getRemoteRepository()
             throws RemoteException;
 
+    /**
+     * Method to obtain the remote remote repository.
+     * If initialize is true and a RepositoryException will be thrown no {@link BrokenRemoteRepository}
+     * will be created. 
+     *
+     * @return remote repository
+     * @throws RemoteException if the remote repository could not be accessed
+     */
+    protected RemoteRepository getRemoteRepository(boolean initialize)
+            throws RemoteException {
+        if (initialize) {
+            try {
+                return getRemoteRepository();
+            } catch (RemoteException e) {
+                throw new RemoteRuntimeException(e);
+            }
+        } else {
+            return getRemoteRepository();
+        }
+    }
+
     /** {@inheritDoc} */
     public synchronized String getDescriptor(String name) {
         try {
             return remote.getDescriptor(name);
         } catch (RemoteException e1) {
             try {
-                remote = getRemoteRepository();
+                remote = getRemoteRepository(false);
                 return remote.getDescriptor(name);
             } catch (RemoteException e2) {
                 remote = new BrokenRemoteRepository(e2);
@@ -89,7 +110,7 @@ public abstract class SafeClientReposito
             return remote.getDescriptorKeys();
         } catch (RemoteException e1) {
             try {
-                remote = getRemoteRepository();
+                remote = getRemoteRepository(false);
                 return remote.getDescriptorKeys();
             } catch (RemoteException e2) {
                 remote = new BrokenRemoteRepository(e2);
@@ -105,7 +126,7 @@ public abstract class SafeClientReposito
             return remote.login(credentials, workspace);
         } catch (RemoteException e1) {
             try {
-                remote = getRemoteRepository();
+                remote = getRemoteRepository(false);
                 return remote.login(credentials, workspace);
             } catch (RemoteException e2) {
                 remote = new BrokenRemoteRepository(e2);
@@ -142,7 +163,7 @@ public abstract class SafeClientReposito
             return remote.getDescriptorValue(key);
         } catch (RemoteException e1) {
             try {
-                remote = getRemoteRepository();
+                remote = getRemoteRepository(false);
                 return remote.getDescriptorValue(key);
             } catch (RemoteException e2) {
                 remote = new BrokenRemoteRepository(e2);
@@ -157,7 +178,7 @@ public abstract class SafeClientReposito
             return remote.getDescriptorValues(key);
         } catch (RemoteException e1) {
             try {
-                remote = getRemoteRepository();
+                remote = getRemoteRepository(false);
                 return remote.getDescriptorValues(key);
             } catch (RemoteException e2) {
                 remote = new BrokenRemoteRepository(e2);
@@ -172,7 +193,7 @@ public abstract class SafeClientReposito
             return remote.isSingleValueDescriptor(key);
         } catch (RemoteException e1) {
             try {
-                remote = getRemoteRepository();
+                remote = getRemoteRepository(false);
                 return remote.isSingleValueDescriptor(key);
             } catch (RemoteException e2) {
                 remote = new BrokenRemoteRepository(e2);
@@ -187,7 +208,7 @@ public abstract class SafeClientReposito
             return remote.isStandardDescriptor(key);
         } catch (RemoteException e1) {
             try {
-                remote = getRemoteRepository();
+                remote = getRemoteRepository(false);
                 return remote.isStandardDescriptor(key);
             } catch (RemoteException e2) {
                 remote = new BrokenRemoteRepository(e2);

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=1422975&r1=1422974&r2=1422975&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
Mon Dec 17 15:17:08 2012
@@ -77,113 +77,99 @@ public class RmiRepositoryFactory implem
 
     private Repository getUrlRepository(final URL url)
             throws RepositoryException {
-        return new SafeClientRepositoryUrl(url, new ClientAdapterFactory());
+        return new RmiSafeClientRepository(new ClientAdapterFactory()) {
+
+            @Override
+            protected RemoteRepository getRemoteRepository() throws RemoteException {
+                try {
+                    InputStream stream = url.openStream();
+                    try {
+                        Object remote = new ObjectInputStream(stream).readObject();
+                        if (remote instanceof RemoteRepository) {
+                            return (RemoteRepository) remote;
+                        } else {
+                            throw new RemoteException("The resource at URL " + url
+                                    + " is not a remote repository stub: " + remote);
+                        }
+                    } finally {
+                        if (stream != null) {
+                            stream.close();
+                        }
+                    }
+                } catch (ClassNotFoundException e) {
+                    throw new RemoteException("The resource at URL " + url
+                            + " requires a class that is not available", e);
+                } catch (IOException e) {
+                    throw new RemoteException("Failed to read the resource at URL "
+                            + url, e);
+                }
+            }
+        };
     }
 
     @SuppressWarnings("rawtypes")
     private Repository getJndiRepository(final String name,
             final Hashtable environment) throws RepositoryException {
-        return new SafeClientRepositoryJndi(name, environment,
-                new ClientAdapterFactory());
-    }
-
-    private Repository getRmiRepository(final String name)
-            throws RepositoryException {
-        return new SafeClientRepositoryName(name, new ClientAdapterFactory());
-    }
-
-    private static class SafeClientRepositoryUrl extends SafeClientRepository {
-
-        private final URL url;
+        return new RmiSafeClientRepository(new ClientAdapterFactory()) {
 
-        public SafeClientRepositoryUrl(URL url, LocalAdapterFactory factory) {
-            super(factory);
-            this.url = url;
-        }
-
-        @Override
-        protected RemoteRepository getRemoteRepository() throws RemoteException {
-            try {
-                InputStream stream = url.openStream();
+            @Override
+            protected RemoteRepository getRemoteRepository() throws RemoteException {
                 try {
-                    Object remote = new ObjectInputStream(stream).readObject();
-                    if (remote instanceof RemoteRepository) {
-                        return (RemoteRepository) remote;
+                    Object value = new InitialContext(environment).lookup(name);
+                    if (value instanceof RemoteRepository) {
+                        return (RemoteRepository) value;
                     } else {
-                        throw new RemoteException("The resource at URL " + url
-                                + " is not a remote repository stub: " + remote);
+                        throw new RemoteException("The JNDI resource " + name
+                                + " is not a remote repository stub: " + value);
                     }
-                } finally {
-                    stream.close();
+                } catch (NamingException e) {
+                    throw new RemoteException(
+                            "Failed to look up the JNDI resource " + name, e);
                 }
-            } catch (ClassNotFoundException e) {
-                throw new RemoteException("The resource at URL " + url
-                        + " requires a class that is not available", e);
-            } catch (IOException e) {
-                throw new RemoteException("Failed to read the resource at URL "
-                        + url, e);
             }
-        }
+        };
     }
 
-    @SuppressWarnings("rawtypes")
-    private static class SafeClientRepositoryJndi extends SafeClientRepository {
-
-        private final String name;
-        private final Hashtable environment;
-
-        public SafeClientRepositoryJndi(String name, Hashtable environment,
-                LocalAdapterFactory factory) {
-            super(factory);
-            this.name = name;
-            this.environment = environment;
-        }
+    private Repository getRmiRepository(final String name)
+            throws RepositoryException {
+        return new RmiSafeClientRepository(new ClientAdapterFactory()) {
 
-        @Override
-        protected RemoteRepository getRemoteRepository() throws RemoteException {
-            try {
-                Object value = new InitialContext(environment).lookup(name);
-                if (value instanceof RemoteRepository) {
-                    return (RemoteRepository) value;
-                } else {
-                    throw new RemoteException("The JNDI resource " + name
-                            + " is not a remote repository stub: " + value);
+            @Override
+            protected RemoteRepository getRemoteRepository() throws RemoteException {
+                try {
+                    Object value = Naming.lookup(name);
+                    if (value instanceof RemoteRepository) {
+                        return (RemoteRepository) value;
+                    } else {
+                        throw new RemoteException("The RMI resource " + name
+                                + " is not a remote repository stub: " + value);
+                    }
+                } catch (NotBoundException e) {
+                    throw new RemoteException(
+                            "RMI resource " + name + " not found", e);
+                } catch (MalformedURLException e) {
+                    throw new RemoteException("Invalid RMI name: " + name, e);
+                } catch (RemoteException e) {
+                    throw new RemoteException("Failed to look up the RMI resource "
+                            + name, e);
                 }
-            } catch (NamingException e) {
-                throw new RemoteException(
-                        "Failed to look up the JNDI resource " + name, e);
             }
-        }
+        };
     }
 
-    private static class SafeClientRepositoryName extends SafeClientRepository {
+    /**
+     * Basic SafeClientRepository for the different lookup types of a rmi repository
+     */
+    private static class RmiSafeClientRepository extends SafeClientRepository {
 
-        private final String name;
-
-        public SafeClientRepositoryName(String name, LocalAdapterFactory factory) {
+        public RmiSafeClientRepository(LocalAdapterFactory factory) {
             super(factory);
-            this.name = name;
         }
 
         @Override
         protected RemoteRepository getRemoteRepository() throws RemoteException {
-            try {
-                Object value = Naming.lookup(name);
-                if (value instanceof RemoteRepository) {
-                    return (RemoteRepository) value;
-                } else {
-                    throw new RemoteException("The RMI resource " + name
-                            + " is not a remote repository stub: " + value);
-                }
-            } catch (NotBoundException e) {
-                throw new RemoteException(
-                        "RMI resource " + name + " not found", e);
-            } catch (MalformedURLException e) {
-                throw new RemoteException("Invalid RMI name: " + name, e);
-            } catch (RemoteException e) {
-                throw new RemoteException("Failed to look up the RMI resource "
-                        + name, e);
-            }
+            return null;
         }
+
     }
 }



Mime
View raw message