You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by rm...@apache.org on 2015/03/16 19:48:45 UTC

[1/2] tomee git commit: OPENEJB-2111 application exception support for @Asynchronous

Repository: tomee
Updated Branches:
  refs/heads/master ca3f6a239 -> 85649d332


OPENEJB-2111 application exception support for @Asynchronous


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

Branch: refs/heads/master
Commit: dd003ce08a901394d70b050b4df459808b5360e6
Parents: ca3f6a2
Author: Romain Manni-Bucau <rm...@apache.org>
Authored: Mon Mar 16 19:46:40 2015 +0100
Committer: Romain Manni-Bucau <rm...@apache.org>
Committed: Mon Mar 16 19:48:37 2015 +0100

----------------------------------------------------------------------
 .../apache/openejb/async/AsynchronousPool.java   | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/dd003ce0/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 7c6cc36..925671b 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,14 +18,14 @@
 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;
 import org.apache.openejb.util.Duration;
 import org.apache.openejb.util.ExecutorBuilder;
 
-import javax.ejb.EJBException;
-import javax.ejb.NoSuchEJBException;
 import java.rmi.NoSuchObjectException;
 import java.util.concurrent.BlockingQueue;
 import java.util.concurrent.Callable;
@@ -38,6 +38,8 @@ import java.util.concurrent.ThreadPoolExecutor;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeoutException;
 import java.util.concurrent.atomic.AtomicBoolean;
+import javax.ejb.EJBException;
+import javax.ejb.NoSuchEJBException;
 
 /**
  * @version $Rev$ $Date$
@@ -226,11 +228,22 @@ public class AsynchronousPool {
 
             final boolean isExceptionUnchecked = e instanceof Error || e instanceof RuntimeException;
 
-            // throw checked excpetion and EJBException directly.
+            // throw checked exception and EJBException directly.
             if (!isExceptionUnchecked || e instanceof EJBException) {
                 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)));


[2/2] tomee git commit: OPENEJB-2111 application exception support for @Asynchronous - test

Posted by rm...@apache.org.
OPENEJB-2111 application exception support for @Asynchronous - test


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

Branch: refs/heads/master
Commit: 85649d3322ab42c198eb8b8f6f604e9ba44a6e32
Parents: dd003ce
Author: Romain Manni-Bucau <rm...@apache.org>
Authored: Mon Mar 16 19:46:51 2015 +0100
Committer: Romain Manni-Bucau <rm...@apache.org>
Committed: Mon Mar 16 19:48:38 2015 +0100

----------------------------------------------------------------------
 .../core/asynch/AsyncAppExceptionTest.java      | 64 ++++++++++++++++++++
 1 file changed, 64 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/85649d33/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..4e5074c
--- /dev/null
+++ b/container/openejb-core/src/test/java/org/apache/openejb/core/asynch/AsyncAppExceptionTest.java
@@ -0,0 +1,64 @@
+/**
+ * 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.junit.ApplicationComposer;
+import org.apache.openejb.testing.Classes;
+import org.junit.Assert;
+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;
+
+@Classes(innerClassesAsBean = true)
+@RunWith(ApplicationComposer.class)
+public class AsyncAppExceptionTest {
+    @EJB
+    private MyAsync async;
+
+    @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 {
+    }
+}