Author: genspring
Date: Thu May 26 03:46:45 2011
New Revision: 1127780

URL: http://svn.apache.org/viewvc?rev=1127780&view=rev
Log:
OPENEJB-1558 Clean up exception handling logic in async.There are some 
requirements on the exceptions when executing async method:

1, Unchecked exception must be wrapped with EJBExcpetion before being wrraped 
with ExecutionException and throwing out.
2, All checked exception should be wrapped with ExecutionException before 
throwing out.

The client code could get the root exception from the aync method with 
ExecutionException.getCause();

Modified:
    
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/EjbObjectProxyHandler.java

Modified: 
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/EjbObjectProxyHandler.java
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/EjbObjectProxyHandler.java?rev=1127780&r1=1127779&r2=1127780&view=diff
==============================================================================
--- 
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/EjbObjectProxyHandler.java
 (original)
+++ 
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/EjbObjectProxyHandler.java
 Thu May 26 03:46:45 2011
@@ -33,6 +33,7 @@ import java.util.concurrent.TimeoutExcep
 import java.util.concurrent.atomic.AtomicBoolean;
 
 import javax.ejb.AccessLocalException;
+import javax.ejb.ConcurrentAccessTimeoutException;
 import javax.ejb.EJBAccessException;
 import javax.ejb.EJBException;
 import javax.ejb.EJBLocalObject;
@@ -356,7 +357,16 @@ public abstract class EjbObjectProxyHand
             if(canceled) {
                 throw new CancellationException();
             }
-            return target.get();
+            
+            T object = null;
+
+            try {
+                object = target.get();
+            } catch (Throwable e) {
+                handleException(e);
+            }
+
+            return object;
         }
 
         @Override
@@ -364,7 +374,37 @@ public abstract class EjbObjectProxyHand
             if (canceled) {
                 throw new CancellationException();
             }
-            return target.get(timeout, unit);
+            
+            T object = null;
+
+            try {
+                object = target.get(timeout, unit);
+            } catch (Throwable e) {
+                handleException(e);
+            }
+
+            return object;
+            
+        }
+        
+        private void handleException(Throwable e) throws ExecutionException {
+            
+            //unwarp the exception to find the root cause
+            while (e.getCause() != null) {
+                e = (Throwable) e.getCause();
+            }
+
+            boolean isExceptionUnchecked = (e instanceof Error) || (e 
instanceof RuntimeException);
+
+            // throw checked excpetion and ConcurrentAccessTimeoutException 
directly.
+            if (!isExceptionUnchecked || e instanceof EJBException) {
+                throw new ExecutionException(e);
+            }
+
+            // wrap unchecked exception with EJBException before throwing.
+            throw (e instanceof Exception) ? new ExecutionException(new 
EJBException((Exception) e))
+                    : new ExecutionException(new EJBException(new 
Exception(e)));
+            
         }
 
         @Override


Reply via email to