Author: rmannibucau
Date: Wed Mar 13 09:52:28 2013
New Revision: 1455853

URL: http://svn.apache.org/r1455853
Log:
OPENEJB-2005 allowing to merge all app exceptions through 
openejb.propagate.application-exceptions=true

Modified:
    
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java

Modified: 
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
URL: 
http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java?rev=1455853&r1=1455852&r2=1455853&view=diff
==============================================================================
--- 
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
 (original)
+++ 
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
 Wed Mar 13 09:52:28 2013
@@ -206,6 +206,7 @@ public class Assembler extends Assembler
     public static final String OPENEJB_URL_PKG_PREFIX = 
IvmContext.class.getPackage().getName();
     public static final Logger logger = 
Logger.getInstance(LogCategory.OPENEJB_STARTUP, Assembler.class);
     public static final String OPENEJB_JPA_DEPLOY_TIME_ENHANCEMENT_PROP = 
"openejb.jpa.deploy-time-enhancement";
+    public static final String PROPAGATE_APPLICATION_EXCEPTIONS = 
"openejb.propagate.application-exceptions";
     private static final String GLOBAL_UNIQUE_ID = "global";
     public static final String TIMER_STORE_CLASS = "timerStore.class";
 
@@ -741,6 +742,12 @@ public class Assembler extends Assembler
 
             final List<BeanContext> allDeployments = initEjbs(classLoader, 
appInfo, appContext, injections, new ArrayList<BeanContext>(), null);
 
+            if ("true".equalsIgnoreCase(SystemInstance.get()
+                    .getProperty(PROPAGATE_APPLICATION_EXCEPTIONS,
+                            
appInfo.properties.getProperty(PROPAGATE_APPLICATION_EXCEPTIONS, "false")))) {
+                propagateApplicationExceptions(appInfo, classLoader, 
allDeployments);
+            }
+
             new CdiBuilder().build(appInfo, appContext, allDeployments);
 
             ensureWebBeansContext(appContext);
@@ -859,6 +866,25 @@ public class Assembler extends Assembler
         }
     }
 
+    private void propagateApplicationExceptions(final AppInfo appInfo, final 
ClassLoader classLoader, final List<BeanContext> allDeployments) {
+        for (final BeanContext context : allDeployments) {
+            if (BeanContext.Comp.class.equals(context.getBeanClass())) {
+                continue;
+            }
+
+            for (final EjbJarInfo jar : appInfo.ejbJars) {
+                for (final ApplicationExceptionInfo exception : 
jar.applicationException) {
+                    try {
+                        final Class<?> exceptionClass = 
classLoader.loadClass(exception.exceptionClass);
+                        context.addApplicationException(exceptionClass, 
exception.rollback, exception.inherited);
+                    } catch (final Exception e) {
+                        // no-op: not a big deal since by jar config is 
respected, mainly means propagation didn't work because of classloader 
constraints
+                    }
+                }
+            }
+        }
+    }
+
     private void resumePersistentSchedulers(final AppContext appContext) {
         final Scheduler globalScheduler = 
SystemInstance.get().getComponent(Scheduler.class);
         final Collection<Scheduler> schedulers = new ArrayList<Scheduler>();


Reply via email to