[jboss-cvs] JBossAS SVN: r70225 - in projects/ejb3/trunk/core/src: main/java/org/jboss/ejb3/deployers and 5 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Feb 28 14:44:00 EST 2008
Author: bdecoste
Date: 2008-02-28 14:44:00 -0500 (Thu, 28 Feb 2008)
New Revision: 70225
Added:
projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/Ejb3DeploymentMBean.java
projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/test/stateful/AnnotatedAppException.java
projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/test/stateful/CheckedApplicationException.java
Modified:
projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/EJBContainer.java
projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/Ejb3Deployment.java
projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/InitialContextFactory.java
projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/deployers/Ejb3JBoss5Deployment.java
projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/service/ServiceContainer.java
projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/StatefulInstanceInterceptor.java
projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/StatefulRemoveInterceptor.java
projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateless/StatelessInstanceInterceptor.java
projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/test/stateful/EntityFacade.java
projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/test/stateful/EntityFacadeBean.java
projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/test/stateful/StatefulBean.java
projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/test/stateful/unit/RemoteUnitTestCase.java
Log:
stateful test fixes - deployment as mbean + correct retainIfException behavior for application exceptions
of course, after my update and merge everything is broken with a java.lang.NullPointerException
at org.jboss.aop.joinpoint.MethodInvocation.invokeTarget(MethodInvocation.java:121)
Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/EJBContainer.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/EJBContainer.java 2008-02-28 19:19:27 UTC (rev 70224)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/EJBContainer.java 2008-02-28 19:44:00 UTC (rev 70225)
@@ -30,6 +30,7 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
+import java.util.LinkedList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
@@ -50,7 +51,10 @@
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.LinkRef;
+import javax.naming.Name;
+import javax.naming.NameClassPair;
import javax.naming.NameNotFoundException;
+import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.Reference;
import javax.naming.StringRefAddr;
@@ -95,6 +99,7 @@
import org.jboss.injection.ResourceHandler;
import org.jboss.injection.WebServiceRefHandler;
import org.jboss.logging.Logger;
+import org.jboss.metadata.MetaData;
import org.jboss.metadata.ejb.jboss.JBossAssemblyDescriptorMetaData;
import org.jboss.metadata.ejb.jboss.JBossEnterpriseBeanMetaData;
import org.jboss.metadata.javaee.spec.Environment;
@@ -169,6 +174,8 @@
private ThreadLocalStack<BeanContext<?>> currentBean = new ThreadLocalStack<BeanContext<?>>();
+ protected boolean reinitialize = false;
+
/**
* @param name Advisor name
* @param manager Domain to get interceptor bindings from
@@ -205,6 +212,7 @@
}
this.ejbName = ejbName;
String on = createObjectName(ejbName);
+
try
{
objectName = new ObjectName(on);
@@ -732,10 +740,18 @@
}
}
+
+ protected void reinitialize()
+ {
+ super.initializeMethodChain();
+ bindEJBContext();
+ reinitialize = false;
+ }
public void create() throws Exception
{
- initializeClassContainer();
+ super.initializeClassContainer();
+
for (int i = 0; i < constructors.length; i++)
{
if (constructors[i].getParameterTypes().length == 0)
@@ -749,13 +765,16 @@
// Everything must be done in start to make sure all dependencies have been satisfied
public void start() throws Exception
{
+ if (reinitialize)
+ reinitialize();
+
initializePool();
for (EncInjector injector : encInjectors.values())
{
injector.inject(this);
}
-
+
// creating of injector array should come after injection into ENC as an ENC injector
// may add additional injectors into the injector list. An example is an extended persistence
// context which mush be created and added to the SFSB bean context.
@@ -773,7 +792,7 @@
public void stop() throws Exception
{
- encFactory.cleanupEnc(this);
+ reinitialize = true;
if (pool != null)
{
@@ -781,11 +800,19 @@
pool = null;
}
+ injectors = new ArrayList<Injector>();
+ encInjectors = new HashMap<String, EncInjector>();
+
+ InitialContextFactory.close(enc, this.initialContextProperties);
+ enc = null;
+
log.info("STOPPED EJB: " + clazz.getName() + " ejbName: " + ejbName);
}
public void destroy() throws Exception
{
+ encFactory.cleanupEnc(this);
+
super.cleanup();
}
@@ -947,7 +974,7 @@
protected void findPartitionName()
{
- Clustered clustered = (Clustered) resolveAnnotation(Clustered.class);
+ Clustered clustered = (Clustered) getAnnotation(Clustered.class);
if (clustered == null)
{
partitionName = null;
Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/Ejb3Deployment.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/Ejb3Deployment.java 2008-02-28 19:19:27 UTC (rev 70224)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/Ejb3Deployment.java 2008-02-28 19:44:00 UTC (rev 70225)
@@ -61,6 +61,7 @@
import org.jboss.logging.Logger;
import org.jboss.metadata.ejb.jboss.JBossMetaData;
import org.jboss.metadata.javaee.spec.MessageDestinationsMetaData;
+import org.jboss.system.ServiceMBeanSupport;
import org.jboss.virtual.VirtualFile;
/**
@@ -70,7 +71,7 @@
* @author adrian at jboss.org
* @version $Revision$
*/
-public abstract class Ejb3Deployment implements JavaEEModule
+public abstract class Ejb3Deployment extends ServiceMBeanSupport implements JavaEEModule, Ejb3DeploymentMBean
{
private static final Logger log = Logger.getLogger(Ejb3Deployment.class);
@@ -92,7 +93,7 @@
protected List<String> explicitEntityClasses = new ArrayList<String>();
- protected List<PersistenceUnitDeployment> persistenceUnitDeployments = new ArrayList<PersistenceUnitDeployment>();;
+ protected List<PersistenceUnitDeployment> persistenceUnitDeployments = new ArrayList<PersistenceUnitDeployment>();
protected String defaultSLSBDomain = "Stateless Bean";
@@ -118,13 +119,17 @@
protected EjbModulePersistenceUnitResolver persistenceUnitResolver;
protected MessageDestinationResolver messageDestinationResolver;
+
+ protected ObjectName objectName;
+
+ protected boolean reinitialize = false;
public Ejb3Deployment(DeploymentUnit unit, DeploymentScope deploymentScope, JBossMetaData metaData, PersistenceUnitsMetaData persistenceUnitsMetaData,
Ejb3Deployer deployer)
{
assert unit != null : "unit is null";
assert deployer != null : "deployer is null";
-
+
this.unit = unit;
this.deployer = deployer;
this.deploymentScope = deploymentScope;
@@ -339,6 +344,33 @@
ejbContainers.put(on, container);
container.processMetadata();
}
+
+ protected void registerDeployment() throws Exception
+ {
+ String on = "jboss.j2ee:jar=" + this.getName() + ",service=EJB3";
+ if (metaData != null && metaData.getEnterpriseBeans() != null && metaData.getEnterpriseBeans().getEjbJarMetaData() != null)
+ {
+ String jmxName = metaData.getEnterpriseBeans().getEjbJarMetaData().getJmxName();
+ if (jmxName != null && jmxName.trim().length() > 0)
+ on = jmxName;
+ }
+
+ objectName = new ObjectName(on);
+
+ mbeanServer.registerMBean(this, objectName);
+ }
+
+ protected void unregisterDeployment()
+ {
+ try
+ {
+ mbeanServer.unregisterMBean(objectName);
+ }
+ catch (Exception e)
+ {
+ log.debug("error trying to stop ejb deployment", e);
+ }
+ }
protected void registerEJBContainer(Container container) throws Exception
{
@@ -375,6 +407,8 @@
deploy();
initializePersistenceUnits();
+
+ registerDeployment();
log.debug("EJB3 deployment time took: " + (System.currentTimeMillis() - start));
}
@@ -391,11 +425,20 @@
throw e;
}
}
+
+ protected void reinitialize() throws Exception
+ {
+ initializePersistenceUnits();
+ reinitialize = false;
+ }
public void start() throws Exception
{
try
{
+ if (reinitialize)
+ reinitialize();
+
startPersistenceUnits();
for (Object o : ejbContainers.values())
@@ -425,6 +468,25 @@
throw ex;
}
}
+
+ public void stop() //throws Exception
+ {
+ for (ObjectName on : ejbContainers.keySet())
+ {
+ try
+ {
+ mbeanServer.unregisterMBean(on);
+ kernelAbstraction.uninstall(on.getCanonicalName());
+ }
+ catch (Exception e)
+ {
+ log.debug("error trying to stop ejb container", e);
+ }
+ }
+ stopPersistenceUnits();
+
+ reinitialize = true;
+ }
protected void deploy() throws Exception
{
@@ -625,35 +687,27 @@
log.debug("error trying to shut down persistence unit", e);
}
}
+
+ persistenceUnitDeployments = new ArrayList<PersistenceUnitDeployment>();
}
- public void stop() throws Exception
+
+
+ public void destroy() //throws Exception
{
- for (ObjectName on : ejbContainers.keySet())
+ try
{
- try
- {
- mbeanServer.unregisterMBean(on);
- kernelAbstraction.uninstall(on.getCanonicalName());
- }
- catch (Exception e)
- {
- log.debug("error trying to shut down ejb container", e);
- }
+ undeploy();
+
+ unregisterDeployment();
+ }
+ catch (Exception e)
+ {
+ log.debug("error trying to destroy ejb deployment", e);
}
- stopPersistenceUnits();
}
- public void destroy() throws Exception
- {
- undeploy();
-
- PolicyConfigurationFactory pcFactory = PolicyConfigurationFactory.getPolicyConfigurationFactory();
- PolicyConfiguration pc = pcFactory.getPolicyConfiguration(getJaccContextId(), true);
- pc.delete();
- }
-
private void undeploy()
{
for (Container container : ejbContainers.values())
Added: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/Ejb3DeploymentMBean.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/Ejb3DeploymentMBean.java (rev 0)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/Ejb3DeploymentMBean.java 2008-02-28 19:44:00 UTC (rev 70225)
@@ -0,0 +1,31 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3;
+
+/**
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ */
+public interface Ejb3DeploymentMBean extends org.jboss.system.ServiceMBean
+{
+ Container getContainer(javax.management.ObjectName name);
+}
+
Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/InitialContextFactory.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/InitialContextFactory.java 2008-02-28 19:19:27 UTC (rev 70224)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/InitialContextFactory.java 2008-02-28 19:44:00 UTC (rev 70225)
@@ -50,6 +50,14 @@
private static Context haContext = null;
private static Integer haJndiPort = null;
+ public static void close(Context context, Hashtable properties) throws NamingException
+ {
+ if (properties == null)
+ baseInitialContext = null;
+
+ context.close();
+ }
+
public static InitialContext getInitialContext() throws NamingException
{
InitialContext jndiContext;
Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/deployers/Ejb3JBoss5Deployment.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/deployers/Ejb3JBoss5Deployment.java 2008-02-28 19:19:27 UTC (rev 70224)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/deployers/Ejb3JBoss5Deployment.java 2008-02-28 19:44:00 UTC (rev 70225)
@@ -42,7 +42,7 @@
* @author adrian at jboss.org
* @version $Revision: 56592 $
*/
-public class Ejb3JBoss5Deployment extends Ejb3Deployment
+public class Ejb3JBoss5Deployment extends Ejb3Deployment
{
private static final Logger log = Logger.getLogger(Ejb3JBoss5Deployment.class);
@@ -51,6 +51,7 @@
public Ejb3JBoss5Deployment(DeploymentUnit ejb3Unit, Kernel kernel, MBeanServer mbeanServer, org.jboss.deployers.structure.spi.DeploymentUnit jbossUnit, DeploymentScope deploymentScope, JBossMetaData metaData, PersistenceUnitsMetaData persistenceUnitsMetaData, Ejb3Deployer deployer)
{
super(ejb3Unit, deploymentScope, metaData, persistenceUnitsMetaData, deployer);
+
this.jbossUnit = jbossUnit;
kernelAbstraction = new MCKernelAbstraction(kernel, mbeanServer);
Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/service/ServiceContainer.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/service/ServiceContainer.java 2008-02-28 19:19:27 UTC (rev 70224)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/service/ServiceContainer.java 2008-02-28 19:44:00 UTC (rev 70225)
@@ -76,13 +76,12 @@
{
ServiceMBeanDelegate delegate;
Object singleton;
- boolean injected;
BeanContext beanContext;
MBeanServer mbeanServer;
ObjectName delegateObjectName;
private TimerService timerService;
private Object mbean = new ServiceDelegateWrapper(this);
-
+
@SuppressWarnings("unused")
private static final Logger log = Logger.getLogger(ServiceContainer.class);
@@ -190,6 +189,15 @@
return interfaces;
}
+ protected void reinitialize()
+ {
+ super.reinitialize();
+
+ singleton = super.construct();
+
+ invokeOptionalMethod("create");
+ }
+
public void start() throws Exception
{
super.start();
@@ -229,9 +237,10 @@
// TODO: EJBTHREE-655: shouldn't happen here, but in destroy
unregisterManagementInterface();
-
- injected = false;
+ singleton = null;
+ beanContext = null;
+
super.stop();
}
@@ -478,7 +487,6 @@
popEnc();
}
}
- injected = true;
}
// Dynamic MBean implementation --------------------------------------------------
Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/StatefulInstanceInterceptor.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/StatefulInstanceInterceptor.java 2008-02-28 19:19:27 UTC (rev 70224)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/StatefulInstanceInterceptor.java 2008-02-28 19:44:00 UTC (rev 70225)
@@ -29,6 +29,7 @@
import org.jboss.aop.advice.Interceptor;
import org.jboss.aop.joinpoint.Invocation;
+import org.jboss.aop.joinpoint.MethodInvocation;
import org.jboss.ejb3.EJBContainer;
import org.jboss.ejb3.annotation.SerializedConcurrentAccess;
import org.jboss.logging.Logger;
@@ -87,7 +88,7 @@
}
catch (Exception ex)
{
- if (isApplicationException(ex.getClass(), container)) throw ex;
+ if (StatefulRemoveInterceptor.isApplicationException(ex, (MethodInvocation)invocation)) throw ex;
if (ex instanceof RuntimeException
|| ex instanceof RemoteException)
{
@@ -110,27 +111,4 @@
}
}
}
-
- public static boolean isApplicationException(Class<?> exceptionClass, EJBContainer container)
- {
- if (exceptionClass.isAnnotationPresent(ApplicationException.class))
- return true;
-
- // FIXME: use annotation only. Duplicate of TxUtil.getApplicationException, must move to EJBContainer.
- JBossAssemblyDescriptorMetaData assembly = container.getAssemblyDescriptor();
- if (assembly != null)
- {
- ApplicationExceptionsMetaData exceptions = assembly.getApplicationExceptions();
- if (exceptions != null && exceptions.size() > 0)
- {
- for(ApplicationExceptionMetaData exception : exceptions)
- {
- if (exception.getExceptionClass().equals(exceptionClass.getName()))
- return true;
- }
- }
-
- }
- return false;
- }
}
Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/StatefulRemoveInterceptor.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/StatefulRemoveInterceptor.java 2008-02-28 19:19:27 UTC (rev 70224)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/StatefulRemoveInterceptor.java 2008-02-28 19:44:00 UTC (rev 70225)
@@ -21,11 +21,13 @@
*/
package org.jboss.ejb3.stateful;
+import java.lang.reflect.Method;
import javax.transaction.Synchronization;
import javax.transaction.Transaction;
import javax.transaction.SystemException;
import javax.transaction.RollbackException;
import org.jboss.aop.advice.Interceptor;
+import org.jboss.aop.joinpoint.MethodInvocation;
import org.jboss.aop.joinpoint.Invocation;
import org.jboss.ejb3.tx.TxUtil;
import org.jboss.ejb3.BeanContext;
@@ -58,11 +60,11 @@
private StatefulContainer container;
private Object id;
- public RemoveSynchronization(StatefulContainer container, Object id, boolean removeOnException)
+ public RemoveSynchronization(StatefulContainer container, Object id, boolean retainIfException)
{
this.container = container;
this.id = id;
- this.retainIfException = removeOnException;
+ this.retainIfException = retainIfException;
}
@@ -98,8 +100,8 @@
}
catch (Throwable t)
{
- // don't remove if we're an applicationexception and retain is true
- if (TxUtil.getApplicationException(t.getClass(), invocation) != null && retainIfException) throw t;
+ // don't remove if we're an application exception and retain is true
+ if (retainIfException(retainIfException, t, (MethodInvocation)invocation)) throw t;
// otherwise, just remove it.
removeSession(invocation, true);
@@ -108,6 +110,31 @@
removeSession(invocation, false);
return rtn;
}
+
+ protected static boolean retainIfException(boolean retainIfException, Throwable t, MethodInvocation invocation)
+ {
+ if (retainIfException && isApplicationException(t, invocation))
+ return true;
+
+ return false;
+ }
+
+ // application exception is @ApplicationException or checked exception extended from Exception or RuntimeException
+ public static boolean isApplicationException(Throwable t, MethodInvocation invocation)
+ {
+ if (TxUtil.getApplicationException(t.getClass(), invocation) != null)
+ return true;
+
+ Method method = invocation.getMethod();
+ Class[] exceptionTypes = method.getExceptionTypes();
+ for (Class exceptionClass : exceptionTypes)
+ {
+ if (exceptionClass.isAssignableFrom(t.getClass()))
+ return true;
+ }
+
+ return false;
+ }
protected void removeSession(Invocation invocation, boolean exceptionThrown) throws Throwable
{
@@ -116,7 +143,6 @@
if (ctx == null || ctx.isDiscarded() || ctx.isRemoved()) return;
Object id = ejb.getId();
-
StatefulContainer container = (StatefulContainer) ejb.getAdvisor();
Transaction tx = null;
try
Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateless/StatelessInstanceInterceptor.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateless/StatelessInstanceInterceptor.java 2008-02-28 19:19:27 UTC (rev 70224)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateless/StatelessInstanceInterceptor.java 2008-02-28 19:44:00 UTC (rev 70225)
@@ -23,9 +23,10 @@
import org.jboss.aop.advice.Interceptor;
import org.jboss.aop.joinpoint.Invocation;
+import org.jboss.aop.joinpoint.MethodInvocation;
import org.jboss.ejb3.*;
import org.jboss.ejb3.pool.Pool;
-import org.jboss.ejb3.stateful.StatefulInstanceInterceptor;
+import org.jboss.ejb3.stateful.StatefulRemoveInterceptor;
import org.jboss.ejb3.tx.Ejb3TxPolicy;
import org.jboss.logging.Logger;
@@ -66,7 +67,7 @@
catch (Exception ex)
{
discard = (ex instanceof EJBException) ||
- ((ex instanceof RuntimeException || ex instanceof RemoteException) && !StatefulInstanceInterceptor.isApplicationException(ex.getClass(), container));
+ ((ex instanceof RuntimeException || ex instanceof RemoteException) && !StatefulRemoveInterceptor.isApplicationException(ex, (MethodInvocation)invocation));
throw ex;
}
finally
Added: projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/test/stateful/AnnotatedAppException.java
===================================================================
--- projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/test/stateful/AnnotatedAppException.java (rev 0)
+++ projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/test/stateful/AnnotatedAppException.java 2008-02-28 19:44:00 UTC (rev 70225)
@@ -0,0 +1,41 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.test.stateful;
+
+import javax.ejb.ApplicationException;
+
+/**
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ */
+ at ApplicationException
+public class AnnotatedAppException extends RuntimeException
+{
+ public AnnotatedAppException()
+ {
+ super();
+ }
+
+ public AnnotatedAppException(String s)
+ {
+ super(s);
+ }
+}
Added: projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/test/stateful/CheckedApplicationException.java
===================================================================
--- projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/test/stateful/CheckedApplicationException.java (rev 0)
+++ projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/test/stateful/CheckedApplicationException.java 2008-02-28 19:44:00 UTC (rev 70225)
@@ -0,0 +1,38 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.test.stateful;
+
+/**
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ */
+public class CheckedApplicationException extends RuntimeException
+{
+ public CheckedApplicationException()
+ {
+ super();
+ }
+
+ public CheckedApplicationException(String s)
+ {
+ super(s);
+ }
+}
\ No newline at end of file
Modified: projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/test/stateful/EntityFacade.java
===================================================================
--- projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/test/stateful/EntityFacade.java 2008-02-28 19:19:27 UTC (rev 70224)
+++ projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/test/stateful/EntityFacade.java 2008-02-28 19:44:00 UTC (rev 70225)
@@ -26,6 +26,11 @@
*/
public interface EntityFacade
{
+ public static enum REMOVE_EXCEPTION_TYPE
+ {
+ NONE, CHECKED, APPLICATION, RUNTIME,
+ }
+
Entity createEntity(String name);
Entity loadEntity(Long id);
@@ -33,4 +38,6 @@
void remove();
void removeWithTx();
+
+ void setThrowRemoveException(REMOVE_EXCEPTION_TYPE throwDestroyException);
}
Modified: projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/test/stateful/EntityFacadeBean.java
===================================================================
--- projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/test/stateful/EntityFacadeBean.java 2008-02-28 19:19:27 UTC (rev 70224)
+++ projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/test/stateful/EntityFacadeBean.java 2008-02-28 19:44:00 UTC (rev 70225)
@@ -50,7 +50,9 @@
EntityManager manager;
private static final Logger log = Logger.getLogger(EntityFacadeBean.class);
-
+
+ private static REMOVE_EXCEPTION_TYPE throwRemoveException = REMOVE_EXCEPTION_TYPE.NONE;
+
public Entity createEntity(String name) {
log.info("********* createEntity " + name);
Entity entity = new Entity();
@@ -59,6 +61,11 @@
return entity;
}
+ public void setThrowRemoveException(REMOVE_EXCEPTION_TYPE throwRemoveException)
+ {
+ this.throwRemoveException = throwRemoveException;
+ }
+
public Entity loadEntity(Long id) {
log.info("********* loadEntity " + id);
Entity entity = manager.find(Entity.class, id);
@@ -79,24 +86,38 @@
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
@Remove(retainIfException=true)
- public void remove()
+ public void remove() throws CheckedApplicationException
{
+ log.info("************ removing no tx");
+ if (throwRemoveException == REMOVE_EXCEPTION_TYPE.APPLICATION)
+ throw new AnnotatedAppException("From @Remove");
+
+ if (throwRemoveException == REMOVE_EXCEPTION_TYPE.CHECKED)
+ throw new CheckedApplicationException("From @Remove");
+
+ if (throwRemoveException == REMOVE_EXCEPTION_TYPE.RUNTIME)
+ throw new RuntimeException("From @Remove");
}
@Remove(retainIfException=true)
public void removeWithTx()
{
+ log.info("************ removing with tx");
+ if (throwRemoveException == REMOVE_EXCEPTION_TYPE.APPLICATION)
+ throw new AnnotatedAppException("From @Remove");
+
+ if (throwRemoveException == REMOVE_EXCEPTION_TYPE.CHECKED)
+ throw new CheckedApplicationException("From @Remove");
+
+ if (throwRemoveException == REMOVE_EXCEPTION_TYPE.RUNTIME)
+ throw new RuntimeException("From @Remove");
}
@PreDestroy
public void destroy()
{
- log.info("************ destroying");
- // throw RuntimeException
-// Object o = null;
-// o.getClass();
- throw new RuntimeException("From destroy");
+ log.info("************ destroying ");
}
}
Modified: projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/test/stateful/StatefulBean.java
===================================================================
--- projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/test/stateful/StatefulBean.java 2008-02-28 19:19:27 UTC (rev 70224)
+++ projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/test/stateful/StatefulBean.java 2008-02-28 19:44:00 UTC (rev 70225)
@@ -221,8 +221,8 @@
this.state=state;
}
+ // @Remove from xml
public void removeBean()
{
-
}
}
Modified: projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/test/stateful/unit/RemoteUnitTestCase.java
===================================================================
--- projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/test/stateful/unit/RemoteUnitTestCase.java 2008-02-28 19:19:27 UTC (rev 70224)
+++ projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/test/stateful/unit/RemoteUnitTestCase.java 2008-02-28 19:44:00 UTC (rev 70225)
@@ -33,6 +33,8 @@
import org.jboss.ejb3.ClientKernelAbstraction;
import org.jboss.ejb3.KernelAbstractionFactory;
+import org.jboss.ejb3.test.stateful.AnnotatedAppException;
+import org.jboss.ejb3.test.stateful.CheckedApplicationException;
import org.jboss.ejb3.test.stateful.ClusteredStateful;
import org.jboss.ejb3.test.stateful.ConcurrentStateful;
import org.jboss.ejb3.test.stateful.Entity;
@@ -171,6 +173,29 @@
}
}
+ // Keep this test first so we test everything after a deployment restart
+ public void testJmxName() throws Exception
+ {
+ SecurityAssociation.setPrincipal(new SimplePrincipal("somebody"));
+ SecurityAssociation.setCredential("password".toCharArray());
+
+ Stateful stateful = (Stateful)getInitialContext().lookup("Stateful");
+ assertNotNull(stateful);
+ stateful.setState("state");
+ stateful.removeBean();
+
+ ObjectName deployment = new ObjectName("test.ejb3:name=Bill,service=EJB3");
+
+ ClientKernelAbstraction kernel = KernelAbstractionFactory.getClientInstance();
+ kernel.invoke(deployment, "stop", new Object[0], new String[0]);
+ kernel.invoke(deployment, "start", new Object[0], new String[0]);
+
+ stateful = (Stateful)getInitialContext().lookup("Stateful");
+ assertNotNull(stateful);
+ stateful.setState("state");
+ stateful.removeBean();
+ }
+
public void testSmallCache() throws Exception
{
ConcurrentInvocation[] threads = new ConcurrentInvocation[5];
@@ -704,19 +729,11 @@
assertTrue(wasConcurrentException);
}
- public void testJmxName() throws Exception
- {
- ObjectName deployment = new ObjectName("test.ejb3:name=Bill,service=EJB3");
-
- ClientKernelAbstraction kernel = KernelAbstractionFactory.getClientInstance();
- kernel.invoke(deployment, "stop", new Object[0], new String[0]);
- kernel.invoke(deployment, "start", new Object[0], new String[0]);
- }
-
public void testDestroyException() throws Exception
{
EntityFacade stateful = (EntityFacade)getInitialContext().lookup("EntityFacadeBean/remote");
assertNotNull(stateful);
+ stateful.setThrowRemoveException(EntityFacade.REMOVE_EXCEPTION_TYPE.RUNTIME);
stateful.createEntity("Kalin");
try
@@ -726,7 +743,7 @@
}
catch (RuntimeException e)
{
- assertEquals("java.lang.RuntimeException: From destroy", e.getMessage());
+ System.out.println("*** caught " + e.getMessage());
}
try
@@ -736,10 +753,26 @@
}
catch(NoSuchEJBException e)
{
- // okay
+ // ok
}
- /* Wolf: the stateful is discarded
+ stateful = (EntityFacade)getInitialContext().lookup("EntityFacadeBean/remote");
+ assertNotNull(stateful);
+ stateful.setThrowRemoveException(EntityFacade.REMOVE_EXCEPTION_TYPE.CHECKED);
+ stateful.createEntity("Napa");
+
+ try
+ {
+ stateful.remove();
+ fail("should catch RuntimeException");
+ }
+ catch (CheckedApplicationException e)
+ {
+ System.out.println("*** caught " + e.getMessage());
+ }
+
+ stateful.setThrowRemoveException(EntityFacade.REMOVE_EXCEPTION_TYPE.APPLICATION);
+
stateful.createEntity("Cabernet");
try
@@ -747,17 +780,23 @@
stateful.removeWithTx();
fail("should catch RuntimeException");
}
- catch (RuntimeException e)
+ catch (AnnotatedAppException e)
{
+ System.out.println("*** caught " + e.getMessage());
}
stateful.createEntity("Bailey");
- */
+
+ stateful = (EntityFacade)getInitialContext().lookup("EntityFacadeBean/remote");
+ assertNotNull(stateful);
+ stateful.setThrowRemoveException(EntityFacade.REMOVE_EXCEPTION_TYPE.NONE);
+
}
public void testDestroyExceptionWithTx() throws Exception
{
EntityFacade stateful = (EntityFacade)getInitialContext().lookup("EntityFacadeBean/remote");
+ stateful.setThrowRemoveException(EntityFacade.REMOVE_EXCEPTION_TYPE.RUNTIME);
assertNotNull(stateful);
stateful.createEntity("Cabernet");
@@ -768,7 +807,7 @@
}
catch (RuntimeException e)
{
- assertEquals("java.lang.RuntimeException: From destroy", e.getMessage());
+ System.out.println("*** caught " + e.getMessage());
}
try
@@ -778,8 +817,11 @@
}
catch(NoSuchEJBException e)
{
- // okay
- }
+ // ok
+ }
+
+ stateful = (EntityFacade)getInitialContext().lookup("EntityFacadeBean/remote");
+ stateful.setThrowRemoveException(EntityFacade.REMOVE_EXCEPTION_TYPE.NONE);
}
public static Test suite() throws Exception
More information about the jboss-cvs-commits
mailing list