Repository: tomee
Updated Branches:
  refs/heads/tomee-1.7.x 63a1d1036 -> 00ef270de


OPENEJB-2111 application exception support for @Asynchronous - backport


Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/00ef270d
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/00ef270d
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/00ef270d

Branch: refs/heads/tomee-1.7.x
Commit: 00ef270de449be5b1698bdf1935bde3aee7bfc59
Parents: 63a1d10
Author: Romain Manni-Bucau <[email protected]>
Authored: Mon Mar 16 19:49:09 2015 +0100
Committer: Romain Manni-Bucau <[email protected]>
Committed: Mon Mar 16 19:49:23 2015 +0100

----------------------------------------------------------------------
 .../apache/openejb/async/AsynchronousPool.java  | 13 ++++
 .../core/asynch/AsyncAppExceptionTest.java      | 70 ++++++++++++++++++++
 2 files changed, 83 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/00ef270d/container/openejb-core/src/main/java/org/apache/openejb/async/AsynchronousPool.java
----------------------------------------------------------------------
diff --git 
a/container/openejb-core/src/main/java/org/apache/openejb/async/AsynchronousPool.java
 
b/container/openejb-core/src/main/java/org/apache/openejb/async/AsynchronousPool.java
index acb9806..0f01cd0 100644
--- 
a/container/openejb-core/src/main/java/org/apache/openejb/async/AsynchronousPool.java
+++ 
b/container/openejb-core/src/main/java/org/apache/openejb/async/AsynchronousPool.java
@@ -18,6 +18,8 @@
 package org.apache.openejb.async;
 
 import org.apache.openejb.AppContext;
+import org.apache.openejb.BeanContext;
+import org.apache.openejb.core.ExceptionType;
 import org.apache.openejb.core.ThreadContext;
 import org.apache.openejb.loader.Options;
 import org.apache.openejb.util.DaemonThreadFactory;
@@ -231,6 +233,17 @@ public class AsynchronousPool {
                 throw new ExecutionException(e);
             }
 
+            final ThreadContext tc = ThreadContext.getThreadContext();
+            if (tc != null) {
+                final BeanContext bc = tc.getBeanContext();
+                if (bc != null) {
+                    final ExceptionType exceptionType = bc.getExceptionType(e);
+                    if (exceptionType == ExceptionType.APPLICATION) {
+                        throw new ExecutionException(Exception.class.cast(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)));

http://git-wip-us.apache.org/repos/asf/tomee/blob/00ef270d/container/openejb-core/src/test/java/org/apache/openejb/core/asynch/AsyncAppExceptionTest.java
----------------------------------------------------------------------
diff --git 
a/container/openejb-core/src/test/java/org/apache/openejb/core/asynch/AsyncAppExceptionTest.java
 
b/container/openejb-core/src/test/java/org/apache/openejb/core/asynch/AsyncAppExceptionTest.java
new file mode 100644
index 0000000..fda0a17
--- /dev/null
+++ 
b/container/openejb-core/src/test/java/org/apache/openejb/core/asynch/AsyncAppExceptionTest.java
@@ -0,0 +1,70 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openejb.core.asynch;
+
+import org.apache.openejb.jee.WebApp;
+import org.apache.openejb.junit.ApplicationComposer;
+import org.apache.openejb.testing.Classes;
+import org.apache.openejb.testing.Module;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+import javax.ejb.ApplicationException;
+import javax.ejb.Asynchronous;
+import javax.ejb.EJB;
+import javax.ejb.Singleton;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+@RunWith(ApplicationComposer.class)
+public class AsyncAppExceptionTest {
+    @EJB
+    private MyAsync async;
+
+    @Module
+    @Classes(innerClassesAsBean = true)
+    public WebApp war() {
+        return new WebApp();
+    }
+
+    @Test
+    public void run() {
+        try {
+            async.letItFail().get();
+        } catch (final InterruptedException e) {
+            Thread.interrupted();
+            fail();
+        } catch (final ExecutionException e) {
+            assertTrue(MyException.class.isInstance(e.getCause()));
+        }
+    }
+
+    @Singleton
+    public static class MyAsync {
+        @Asynchronous
+        public Future<Boolean> letItFail() throws MyException {
+            throw new MyException();
+        }
+    }
+
+    @ApplicationException
+    public static class MyException extends RuntimeException {
+    }
+}

Reply via email to