[jboss-cvs] JBossAS SVN: r63300 - in trunk/ejb3/src: main/org/jboss/ejb3/deployers and 5 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Jun 1 08:53:04 EDT 2007
Author: wolfc
Date: 2007-06-01 08:53:04 -0400 (Fri, 01 Jun 2007)
New Revision: 63300
Added:
trunk/ejb3/src/resources/test/ejbthree959/META-INF/jboss.xml
trunk/ejb3/src/test/org/jboss/ejb3/test/ejbthree959/Status.java
trunk/ejb3/src/test/org/jboss/ejb3/test/ejbthree959/StatusBean.java
Modified:
trunk/ejb3/src/main/org/jboss/ejb3/Ejb3DescriptorHandler.java
trunk/ejb3/src/main/org/jboss/ejb3/deployers/EJBRegistrationDeployer.java
trunk/ejb3/src/main/org/jboss/ejb3/interceptor/InterceptorInfoRepository.java
trunk/ejb3/src/resources/META-INF/ejb3-deployers-beans.xml
trunk/ejb3/src/test/org/jboss/ejb3/test/ejbthree959/MyStateful.java
trunk/ejb3/src/test/org/jboss/ejb3/test/ejbthree959/MyStatefulBean.java
trunk/ejb3/src/test/org/jboss/ejb3/test/ejbthree959/unit/EJB21TestCase.java
Log:
EJBTHREE-959: merged from Branch_4_2
Modified: trunk/ejb3/src/main/org/jboss/ejb3/Ejb3DescriptorHandler.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/Ejb3DescriptorHandler.java 2007-06-01 12:38:44 UTC (rev 63299)
+++ trunk/ejb3/src/main/org/jboss/ejb3/Ejb3DescriptorHandler.java 2007-06-01 12:53:04 UTC (rev 63300)
@@ -366,7 +366,7 @@
addInterfaces(container, enterpriseBean);
- addDescriptorAnnotations(container, enterpriseBean, ejbName);
+ addDescriptorAnnotations(container, enterpriseBean, ejbName, true);
return container;
}
@@ -721,8 +721,21 @@
}
}
+ /**
+ * Add descriptor annotations on non stateful session beans.
+ *
+ * @param container
+ * @param enterpriseBean
+ * @param ejbName
+ * @throws Exception
+ */
+ private void addDescriptorAnnotations(EJBContainer container, EnterpriseBean enterpriseBean, String ejbName) throws Exception
+ {
+ addDescriptorAnnotations(container, enterpriseBean, ejbName, false);
+ }
+
private void addDescriptorAnnotations(EJBContainer container,
- EnterpriseBean enterpriseBean, String ejbName) throws Exception
+ EnterpriseBean enterpriseBean, String ejbName, boolean isStateful) throws Exception
{
// EJBTHREE-936: TODO: another wicked patch: jndi-name might mean local-jndi-name
// TODO: Make sure this is done after addInterfaces!
@@ -746,10 +759,20 @@
addEjbAnnotations(container, enterpriseBean);
- addEjb21Annotations(container);
+ addEjb21Annotations(container, isStateful);
}
- private void addEjb21Annotations(EJBContainer container) throws Exception
+ /**
+ * EJB3 4.3.5
+ * On a 2.1 session bean the ejbRemove is treated as PreDestroy, ejbActivate as PostActivate,
+ * and ejbPassivate as PrePassivate. If it is a stateless session bean the ejbCreate is treated
+ * as PostConstruct, if it is stateful the ejbCreate is treated as Init.
+ *
+ * @param container
+ * @param enterpriseBean
+ * @throws Exception
+ */
+ private void addEjb21Annotations(EJBContainer container, boolean isStateful) throws Exception
{
Class[] interfaces = ejbClass.getInterfaces();
for (Class beanInterface : interfaces)
@@ -764,8 +787,15 @@
// EJB3 4.6.2: The class may implement the ejbCreate method(s).
if(hasMethod(ejbClass, "ejbCreate"))
{
- annotation = new PostConstructImpl();
- annotationClass = javax.annotation.PostConstruct.class;
+ if(isStateful)
+ {
+ annotation = new InitImpl();
+ }
+ else
+ {
+ annotation = new PostConstructImpl();
+ }
+ annotationClass = annotation.annotationType();
method.setMethodName("ejbCreate");
addAnnotations(annotationClass, annotation, container, method);
}
Modified: trunk/ejb3/src/main/org/jboss/ejb3/deployers/EJBRegistrationDeployer.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/deployers/EJBRegistrationDeployer.java 2007-06-01 12:38:44 UTC (rev 63299)
+++ trunk/ejb3/src/main/org/jboss/ejb3/deployers/EJBRegistrationDeployer.java 2007-06-01 12:53:04 UTC (rev 63300)
@@ -115,16 +115,6 @@
this.defaultPersistenceProperties = defaultPersistenceProperties;
}
- public boolean getRelaxedSignatureChecking()
- {
- return InterceptorInfoRepository.getRelaxedSignatureChecking();
- }
-
- public void setRelaxedSignatureChecking(boolean b)
- {
- InterceptorInfoRepository.setRelaxedSignatureChecking(b);
- }
-
public void deploy(DeploymentUnit unit) throws DeploymentException
{
try
Modified: trunk/ejb3/src/main/org/jboss/ejb3/interceptor/InterceptorInfoRepository.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/interceptor/InterceptorInfoRepository.java 2007-06-01 12:38:44 UTC (rev 63299)
+++ trunk/ejb3/src/main/org/jboss/ejb3/interceptor/InterceptorInfoRepository.java 2007-06-01 12:53:04 UTC (rev 63300)
@@ -30,6 +30,7 @@
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
+import javax.ejb.CreateException;
import javax.ejb.PostActivate;
import javax.ejb.PrePassivate;
import javax.interceptor.AroundInvoke;
@@ -39,6 +40,7 @@
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
+import java.rmi.RemoteException;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
@@ -73,8 +75,6 @@
private InterceptorSorter sorter = new InterceptorSorter();
- private static boolean relaxedSignatureChecking = false;
-
public InterceptorInfoRepository()
{
}
@@ -510,14 +510,23 @@
}
}
- private static boolean checkForRuntimeExceptions(Class<?> exceptions[])
+ private static boolean checkExceptions(Class<?> allowedExceptions[], Method method)
{
- boolean isRuntime = true;
- for(Class<?> exceptionClass : exceptions)
+ for(Class<?> exception : method.getExceptionTypes())
{
- isRuntime &= RuntimeException.class.isAssignableFrom(exceptionClass);
+ boolean isAllowed = false;
+ for(Class<?> allowed : allowedExceptions)
+ {
+ if(allowed.isAssignableFrom(exception))
+ isAllowed = true;
+ }
+ if(!isAllowed)
+ {
+ log.warn("Illegal exception '" + exception.getName() + "' in lifecycle signature (EJB3 12.4.2): " + method);
+ return false;
+ }
}
- return isRuntime;
+ return true;
}
public static boolean checkValidBusinessSignature(Method method)
@@ -560,43 +569,38 @@
return false;
}
+ /**
+ * EJB3 12.4
+ * Lifecycle methods may throw runtime exceptions, but not application exceptions.
+ * Note that for 2.1 beans CreateException (on ejbCreate) and RemoteException should pass.
+ *
+ * @param method
+ * @return
+ */
public static boolean checkValidBeanLifecycleSignature(Method method)
{
int modifiers = method.getModifiers();
if (method.getName().equals("ejbCreate"))
{
- // for public void ejbCreate() throws javax.ejb.CreateException
+ // for public void ejbCreate(...) throws javax.ejb.CreateException
if (!Modifier.isStatic(modifiers) && method.getReturnType().equals(Void.TYPE)
- && method.getParameterTypes().length == 0 && method.getExceptionTypes().length <= 1)
+ && method.getExceptionTypes().length <= 1)
+ {
+ if(!checkExceptions(new Class<?>[] { RuntimeException.class, CreateException.class, RemoteException.class }, method))
+ return false;
return true;
+ }
}
else if (!Modifier.isStatic(modifiers) && method.getReturnType().equals(Void.TYPE)
&& method.getParameterTypes().length == 0)
{
- if(relaxedSignatureChecking)
- {
- return checkForRuntimeExceptions(method.getExceptionTypes());
- }
- else
- {
- return method.getExceptionTypes().length == 0;
- }
+ if(!checkExceptions(new Class<?>[] { RuntimeException.class, RemoteException.class }, method))
+ return false;
+ return true;
}
return false;
}
- public static boolean getRelaxedSignatureChecking()
- {
- return relaxedSignatureChecking;
- }
-
- public static void setRelaxedSignatureChecking(boolean b)
- {
- relaxedSignatureChecking = b;
-
- log.trace("EJBTHREE-947: relaxed signature checking set to " + b);
- }
-
public static String simpleType(Class type)
{
Class ret = type;
@@ -775,13 +779,6 @@
{
if (!signatureValidator.checkValidLifecycle(method))
{
- // FIXME: JBCTS-322
- // This is just a hack that prevents the RTE below. Please fix appropriately.
- if (ann.annotationType() == PostConstruct.class && method.getName().equals("ejbCreate"))
- {
- return method;
- }
-
throw new RuntimeException("@" + ann.annotationType().getName()
+ " annotated method has the wrong signature - " + method + " (EJB3 12.4)");
}
Modified: trunk/ejb3/src/resources/META-INF/ejb3-deployers-beans.xml
===================================================================
--- trunk/ejb3/src/resources/META-INF/ejb3-deployers-beans.xml 2007-06-01 12:38:44 UTC (rev 63299)
+++ trunk/ejb3/src/resources/META-INF/ejb3-deployers-beans.xml 2007-06-01 12:53:04 UTC (rev 63300)
@@ -106,7 +106,6 @@
<value>servlets-webdav.jar</value>
</set>
</property>
- <property name="relaxedSignatureChecking">true</property>
<depends>AspectLibrary</depends>
</bean>
<bean name="EJBStage2Deployer" class="org.jboss.ejb3.deployers.EJBStage2Deployer">
Copied: trunk/ejb3/src/resources/test/ejbthree959/META-INF/jboss.xml (from rev 63298, branches/Branch_4_2/ejb3/src/resources/test/ejbthree959/META-INF/jboss.xml)
===================================================================
--- trunk/ejb3/src/resources/test/ejbthree959/META-INF/jboss.xml (rev 0)
+++ trunk/ejb3/src/resources/test/ejbthree959/META-INF/jboss.xml 2007-06-01 12:53:04 UTC (rev 63300)
@@ -0,0 +1,16 @@
+<?xml version="1.0"?>
+<jboss
+ xmlns="http://java.sun.com/xml/ns/javaee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
+ http://www.jboss.org/j2ee/schema/jboss_5_0.xsd"
+ version="3.0">
+ <enterprise-beans>
+ <session>
+ <ejb-name>MyStateful</ejb-name>
+ <cache-config>
+ <idle-timeout-seconds>5</idle-timeout-seconds>
+ </cache-config>
+ </session>
+ </enterprise-beans>
+</jboss>
Property changes on: trunk/ejb3/src/resources/test/ejbthree959/META-INF/jboss.xml
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Modified: trunk/ejb3/src/test/org/jboss/ejb3/test/ejbthree959/MyStateful.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/ejbthree959/MyStateful.java 2007-06-01 12:38:44 UTC (rev 63299)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/ejbthree959/MyStateful.java 2007-06-01 12:53:04 UTC (rev 63300)
@@ -31,6 +31,7 @@
*/
public interface MyStateful extends EJBObject
{
+ void checkCtx();
String sayHi();
void setName(String name);
}
Modified: trunk/ejb3/src/test/org/jboss/ejb3/test/ejbthree959/MyStatefulBean.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/ejbthree959/MyStatefulBean.java 2007-06-01 12:38:44 UTC (rev 63299)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/ejbthree959/MyStatefulBean.java 2007-06-01 12:53:04 UTC (rev 63300)
@@ -28,6 +28,8 @@
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
+import org.jboss.logging.Logger;
+
/**
* A 2.1 stateful bean.
*
@@ -38,6 +40,8 @@
{
private static final long serialVersionUID = 1L;
+ private static final Logger log = Logger.getLogger(MyStatefulBean.class);
+
@SuppressWarnings("unused")
private SessionContext ctx;
@@ -47,18 +51,29 @@
public void ejbActivate() throws EJBException, RemoteException
{
+ log.info("activate");
+
+ StatusBean.activateCalls++;
}
public void ejbPassivate() throws EJBException, RemoteException
{
+ log.info("passivate");
+
+ StatusBean.passivateCalls++;
}
public void ejbRemove() throws EJBException, RemoteException
{
+ log.info("remove");
+
+ StatusBean.removeCalls++;
}
public void setSessionContext(SessionContext ctx) throws EJBException, RemoteException
{
+ log.info("set session context");
+
this.ctx = ctx;
}
@@ -66,22 +81,36 @@
public void ejbCreate() throws CreateException, RemoteException
{
+ log.info("create");
+
+ checkCtx();
+
+ StatusBean.createCalls++;
}
- public void ejbPostCreate() throws CreateException, RemoteException
- {
- }
-
public void ejbCreate(String name) throws CreateException, RemoteException
{
+ log.info("create '" + name + "'");
+
setName(name);
+
+ checkCtx();
+
+ StatusBean.createCalls++;
}
- public void ejbPostCreate(String name) throws CreateException, RemoteException
- {
+ /* actual stuff */
+
+ private void assertTrue(String msg, boolean condition)
+ {
+ if(!condition)
+ throw new RuntimeException(msg);
}
- /* actual stuff */
+ public void checkCtx()
+ {
+ assertTrue("ctx is not set", ctx != null);
+ }
public String sayHi()
{
Copied: trunk/ejb3/src/test/org/jboss/ejb3/test/ejbthree959/Status.java (from rev 63298, branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/ejbthree959/Status.java)
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/ejbthree959/Status.java (rev 0)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/ejbthree959/Status.java 2007-06-01 12:53:04 UTC (rev 63300)
@@ -0,0 +1,44 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.ejbthree959;
+
+import javax.ejb.Remote;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+ at Remote
+public interface Status
+{
+ int getActivateCalls();
+
+ int getCreateCalls();
+
+ int getPassivateCalls();
+
+ int getRemoveCalls();
+
+ void reset();
+}
Property changes on: trunk/ejb3/src/test/org/jboss/ejb3/test/ejbthree959/Status.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Copied: trunk/ejb3/src/test/org/jboss/ejb3/test/ejbthree959/StatusBean.java (from rev 63298, branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/ejbthree959/StatusBean.java)
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/ejbthree959/StatusBean.java (rev 0)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/ejbthree959/StatusBean.java 2007-06-01 12:53:04 UTC (rev 63300)
@@ -0,0 +1,67 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.ejbthree959;
+
+import javax.ejb.Stateless;
+
+/**
+ * Dirty bean to check status of MyStatefulBean
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+ at Stateless
+public class StatusBean implements Status
+{
+ static int activateCalls;
+ static int createCalls;
+ static int passivateCalls;
+ static int removeCalls;
+
+ public int getActivateCalls()
+ {
+ return activateCalls;
+ }
+
+ public int getCreateCalls()
+ {
+ return createCalls;
+ }
+
+ public int getPassivateCalls()
+ {
+ return passivateCalls;
+ }
+
+ public int getRemoveCalls()
+ {
+ return removeCalls;
+ }
+
+ public void reset()
+ {
+ activateCalls = 0;
+ createCalls = 0;
+ removeCalls = 0;
+ passivateCalls = 0;
+ }
+}
Property changes on: trunk/ejb3/src/test/org/jboss/ejb3/test/ejbthree959/StatusBean.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Modified: trunk/ejb3/src/test/org/jboss/ejb3/test/ejbthree959/unit/EJB21TestCase.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/ejbthree959/unit/EJB21TestCase.java 2007-06-01 12:38:44 UTC (rev 63299)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/ejbthree959/unit/EJB21TestCase.java 2007-06-01 12:53:04 UTC (rev 63300)
@@ -21,12 +21,15 @@
*/
package org.jboss.ejb3.test.ejbthree959.unit;
+import javax.ejb.NoSuchEJBException;
+import javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;
import junit.framework.Test;
import org.jboss.ejb3.test.ejbthree959.MyStateful;
import org.jboss.ejb3.test.ejbthree959.MyStatefulHome;
+import org.jboss.ejb3.test.ejbthree959.Status;
import org.jboss.test.JBossTestCase;
@@ -44,25 +47,84 @@
super(name);
}
+ private MyStatefulHome getMyStatefulHome() throws Exception
+ {
+ return (MyStatefulHome) PortableRemoteObject.narrow(getInitialContext().lookup("MyStateful/home"), MyStatefulHome.class);
+ }
+
+ private Status getStatus() throws Exception
+ {
+ return (Status) getInitialContext().lookup("StatusBean/remote");
+ }
+
public void testCreateNoArgs() throws Exception
{
- MyStatefulHome home = (MyStatefulHome) PortableRemoteObject.narrow(getInitialContext().lookup("MyStateful/home"), MyStatefulHome.class);
+ MyStatefulHome home = getMyStatefulHome();
MyStateful bean = home.create();
bean.setName("testCreateNoArgs");
String expected = "Hi testCreateNoArgs";
String actual = bean.sayHi();
assertEquals(expected, actual);
+ bean.remove();
}
public void testCreateWithArgs() throws Exception
{
- MyStatefulHome home = (MyStatefulHome) PortableRemoteObject.narrow(getInitialContext().lookup("MyStateful/home"), MyStatefulHome.class);
+ MyStatefulHome home = getMyStatefulHome();
MyStateful bean = home.create("testCreateWithArgs");
String expected = "Hi testCreateWithArgs";
String actual = bean.sayHi();
assertEquals(expected, actual);
+ bean.remove();
}
+ public void testCtx() throws Exception
+ {
+ MyStatefulHome home = getMyStatefulHome();
+ MyStateful bean = home.create();
+ bean.checkCtx();
+ bean.remove();
+ }
+
+ public void testLifeCycle() throws Exception
+ {
+ Status status = getStatus();
+ status.reset();
+
+ MyStatefulHome home = getMyStatefulHome();
+ MyStateful bean = home.create();
+
+ assertEquals(1, status.getCreateCalls());
+
+ bean.setName("testLifeCycle");
+ String expected = "Hi testLifeCycle";
+ String actual = bean.sayHi();
+ assertEquals(expected, actual);
+
+ sleep(10000);
+
+ assertEquals(1, status.getPassivateCalls());
+
+ actual = bean.sayHi();
+ assertEquals(expected, actual);
+
+ assertEquals(1, status.getActivateCalls());
+
+ bean.remove();
+
+ assertEquals(1, status.getRemoveCalls());
+
+ try
+ {
+ bean.sayHi();
+ fail("expected no such ejb exception");
+ }
+ catch(NoSuchEJBException e)
+ {
+ // good
+ }
+ }
+
public static Test suite() throws Exception
{
return getDeploySetup(EJB21TestCase.class, "ejbthree959.jar");
More information about the jboss-cvs-commits
mailing list