Author: rmannibucau Date: Sat Oct 12 15:58:08 2013 New Revision: 1531551 URL: http://svn.apache.org/r1531551 Log: TOMEE-1057 @ApplicationException even if not registered in ejb-jar.xml
Added: tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/appexception/ tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/appexception/AppExceptionTest.java Modified: tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/BeanContext.java Modified: tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/BeanContext.java URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/BeanContext.java?rev=1531551&r1=1531550&r2=1531551&view=diff ============================================================================== --- tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/BeanContext.java (original) +++ tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/BeanContext.java Sat Oct 12 15:58:08 2013 @@ -53,15 +53,8 @@ import org.apache.webbeans.portable.Inje import org.apache.webbeans.proxy.InterceptorDecoratorProxyFactory; import org.apache.xbean.recipe.ConstructionException; -import javax.ejb.EJBHome; -import javax.ejb.EJBLocalHome; -import javax.ejb.EJBLocalObject; -import javax.ejb.EJBObject; -import javax.ejb.Lock; -import javax.ejb.LockType; -import javax.ejb.MessageDrivenBean; -import javax.ejb.TimedObject; -import javax.ejb.Timer; +import javax.ejb.*; +import javax.ejb.ApplicationException; import javax.enterprise.context.ConversationScoped; import javax.enterprise.context.spi.CreationalContext; import javax.enterprise.inject.spi.Decorator; @@ -84,6 +77,7 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Set; import java.util.TreeSet; +import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.Future; @SuppressWarnings("unchecked") @@ -225,7 +219,7 @@ public class BeanContext extends Deploym private final List<InterceptorInstance> userInterceptors = new ArrayList<InterceptorInstance>(); private final List<Injection> injections = new ArrayList<Injection>(); private final Map<Class, InterfaceType> interfaces = new HashMap<Class, InterfaceType>(); - private final Map<Class, ExceptionType> exceptions = new HashMap<Class, ExceptionType>(); + private final Map<Class, ExceptionType> exceptions = new ConcurrentHashMap<Class, ExceptionType>(); private final boolean localbean; private Duration accessTimeout; @@ -527,11 +521,17 @@ public class BeanContext extends Deploym } // Unregistered - runtime exceptions are system exception and the rest are application exceptions + final Class<? extends Throwable> eClass = e.getClass(); + final ApplicationException applicationException = eClass.getAnnotation(ApplicationException.class); + if (applicationException != null) { + addApplicationException(eClass, applicationException.rollback(), applicationException.inherited()); + return getExceptionType(e); + } + if (e instanceof RuntimeException) { return ExceptionType.SYSTEM; - } else { - return ExceptionType.APPLICATION; } + return ExceptionType.APPLICATION; } public BeanContext(final String id, final Context jndiContext, final ModuleContext moduleContext, final Class beanClass, final Class mdbInterface, final Map<String, String> activationProperties) throws SystemException { Added: tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/appexception/AppExceptionTest.java URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/appexception/AppExceptionTest.java?rev=1531551&view=auto ============================================================================== --- tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/appexception/AppExceptionTest.java (added) +++ tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/appexception/AppExceptionTest.java Sat Oct 12 15:58:08 2013 @@ -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.appexception; + +import org.apache.openejb.jee.EjbJar; +import org.apache.openejb.jee.SingletonBean; +import org.apache.openejb.junit.ApplicationComposer; +import org.apache.openejb.testing.Module; +import org.junit.Test; +import org.junit.runner.RunWith; + +import javax.ejb.ApplicationException; +import javax.ejb.EJB; +import javax.ejb.Singleton; + +@RunWith(ApplicationComposer.class) +public class AppExceptionTest { + @ApplicationException + public static class RuntimeAppEx extends RuntimeException { + } + @ApplicationException + public static class EjbJarRuntimeAppEx extends RuntimeException { + } + + @Singleton + public static class Ejb { + public void runtime() { throw new RuntimeAppEx(); } + public void ejbjar() { throw new EjbJarRuntimeAppEx(); } + } + + @Module + public EjbJar jar() { + final EjbJar ejbJar = new EjbJar(); + ejbJar.addEnterpriseBean(new SingletonBean(Ejb.class).localBean()); + return ejbJar; + } + + @EJB + private Ejb ejb; + + @Test(expected = RuntimeAppEx.class) + public void runtime() { + ejb.runtime(); + } + + @Test(expected = EjbJarRuntimeAppEx.class) + public void ejbJar() { + ejb.ejbjar(); + } +}