Improve session proxy exception handling
authorMathieu Baudier <mbaudier@argeo.org>
Thu, 28 Apr 2011 07:45:31 +0000 (07:45 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Thu, 28 Apr 2011 07:45:31 +0000 (07:45 +0000)
ASSIGNED - bug 17: Generalize agent management and registration beyond JMS
https://bugzilla.argeo.org/show_bug.cgi?id=17

git-svn-id: https://svn.argeo.org/commons/trunk@4483 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

server/runtime/org.argeo.server.jcr/src/main/java/org/argeo/jcr/ThreadBoundJcrSessionFactory.java

index 4e9e0a759d51f7e1b44110f3cc6e2acbdbe7a9a0..003bcc69b552fd956e5db28b8efd27e72f81237b 100644 (file)
@@ -17,6 +17,7 @@
 package org.argeo.jcr;
 
 import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.lang.reflect.Proxy;
 import java.util.ArrayList;
@@ -224,7 +225,7 @@ public abstract class ThreadBoundJcrSessionFactory {
        protected class JcrSessionInvocationHandler implements InvocationHandler {
 
                public Object invoke(Object proxy, Method method, Object[] args)
-                               throws Throwable {
+                               throws Throwable, RepositoryException {
                        Session threadSession = session.get();
                        if (threadSession == null) {
                                if ("logout".equals(method.getName()))// no need to login
@@ -235,7 +236,16 @@ public abstract class ThreadBoundJcrSessionFactory {
                        }
 
                        preCall(threadSession);
-                       Object ret = method.invoke(threadSession, args);
+                       Object ret;
+                       try {
+                               ret = method.invoke(threadSession, args);
+                       } catch (InvocationTargetException e) {
+                               Throwable cause = e.getCause();
+                               if (cause instanceof RepositoryException)
+                                       throw (RepositoryException) cause;
+                               else
+                                       throw cause;
+                       }
                        if ("logout".equals(method.getName())) {
                                session.remove();
                                Thread thread = Thread.currentThread();