[jboss-cvs] JBossAS SVN: r77343 - in projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3: stateful and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Aug 22 03:41:34 EDT 2008
Author: ALRubinger
Date: 2008-08-22 03:41:34 -0400 (Fri, 22 Aug 2008)
New Revision: 77343
Modified:
projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/session/SessionContainer.java
projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/session/SessionSpecContainer.java
projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/StatefulContainer.java
Log:
[EJBTHREE-1462] Throw RemoveException where appropriate, centralize logic to throw proper exception based upon invocation context
Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/session/SessionContainer.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/session/SessionContainer.java 2008-08-22 07:29:40 UTC (rev 77342)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/session/SessionContainer.java 2008-08-22 07:41:34 UTC (rev 77343)
@@ -23,6 +23,8 @@
import java.io.Serializable;
import java.lang.reflect.Method;
+import java.rmi.NoSuchObjectException;
+import java.rmi.Remote;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
@@ -32,9 +34,14 @@
import java.util.Map;
import java.util.Set;
+import javax.ejb.EJBHome;
+import javax.ejb.EJBLocalHome;
+import javax.ejb.EJBLocalObject;
import javax.ejb.EJBObject;
import javax.ejb.Handle;
import javax.ejb.LocalHome;
+import javax.ejb.NoSuchEJBException;
+import javax.ejb.NoSuchObjectLocalException;
import javax.ejb.RemoteHome;
import org.jboss.aop.Dispatcher;
@@ -596,7 +603,16 @@
}
if (unadvisedMethod.getName().equals("remove"))
{
- destroySession(id);
+ try
+ {
+ destroySession(id);
+ }
+ catch(NoSuchEJBException nsee)
+ {
+ String invokingClassName = unadvisedMethod.getDeclaringClass().getName();
+ Exception newException = (Exception) this.constructProperNoSuchEjbException(nsee, invokingClassName);
+ throw newException;
+ }
return null;
}
@@ -604,6 +620,73 @@
}
/**
+ * Obtains the proper Exception to return to the caller in
+ * the event a "remove" call is made on a bean that doesn't exist.
+ *
+ * Implements EJB 3.0 Core Specification 14.3.9
+ *
+ * @param original
+ * @param invokingClassName
+ * @return
+ */
+ protected Throwable constructProperNoSuchEjbException(NoSuchEJBException original,String invokingClassName)
+ {
+ /*
+ * EJB 3.0 Core Specification 14.3.9
+ *
+ * If a client makes a call to a stateful session or entity
+ * object that has been removed, the container should throw the
+ * javax.ejb.NoSuchEJBException. If the EJB 2.1 client view is used,
+ * the container should throw the java.rmi.NoSuchObjectException
+ * (which is a subclass of java.rmi.RemoteException) to a remote client,
+ * or the javax.ejb.NoSuchObjectLocalException to a local client.
+ */
+
+ // Initialize
+ Throwable t = original;
+ ClassLoader cl = this.getClassloader();
+
+ // Obtain the actual invoked class
+ Class<?> actualInvokingClass = null;
+ try
+ {
+ actualInvokingClass = Class.forName(invokingClassName, true, cl);
+ }
+ catch (ClassNotFoundException e)
+ {
+ throw new RuntimeException("Could not obtain invoking class", e);
+ }
+
+ // If local EJB2.x Client
+ if (EJBLocalObject.class.isAssignableFrom(actualInvokingClass)
+ || EJBLocalHome.class.isAssignableFrom(actualInvokingClass))
+ {
+ t = new NoSuchObjectLocalException(original.getMessage());
+ }
+ // If remote EJB2.x Client
+ else if (Remote.class.isAssignableFrom(actualInvokingClass)
+ || EJBObject.class.isAssignableFrom(actualInvokingClass)
+ || EJBHome.class.isAssignableFrom(actualInvokingClass))
+ {
+ t = new NoSuchObjectException(original.getMessage());
+ }
+ // Business interface
+ else
+ {
+ // Take no action, this is here just for readability
+ }
+
+ // Log
+ if (log.isTraceEnabled())
+ {
+ log.trace("Throwing " + t.getClass().getName(), t);
+ }
+
+ // Return
+ return t;
+ }
+
+ /**
* Allow a container sub class to supplement an invocation. Per default nothing to supplement.
*
* @param invocation
Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/session/SessionSpecContainer.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/session/SessionSpecContainer.java 2008-08-22 07:29:40 UTC (rev 77342)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/session/SessionSpecContainer.java 2008-08-22 07:41:34 UTC (rev 77343)
@@ -12,6 +12,7 @@
import javax.ejb.EJBLocalObject;
import javax.ejb.EJBObject;
import javax.ejb.Handle;
+import javax.ejb.RemoveException;
import javax.ejb.SessionContext;
import org.jboss.aop.Advisor;
@@ -455,9 +456,8 @@
removeHandle((Handle) args[0]);
else
{
- StatefulProxyInvocationHandlerBase handler =(StatefulProxyInvocationHandlerBase) Proxy.getInvocationHandler(args[0]);
- Serializable sessionId = handler.getSessionId();
- destroySession(sessionId);
+ throw new RemoveException(
+ "EJB 3.0 Specification Violation 3.6.2.2: Session beans do not have a primary key");
}
return null;
Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/StatefulContainer.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/StatefulContainer.java 2008-08-22 07:29:40 UTC (rev 77342)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/StatefulContainer.java 2008-08-22 07:41:34 UTC (rev 77343)
@@ -1320,81 +1320,7 @@
return null;
}
}
-
- /**
- * Obtains the proper Exception to return to the caller in
- * the event a "remove" call is made on a bean that doesn't exist.
- *
- * Implements EJB 3.0 Core Specification 14.3.9
- *
- * @param original
- * @param invokingClassName
- * @return
- */
- private Throwable constructProperNoSuchEjbException(NoSuchEJBException original,String invokingClassName)
- {
- /*
- * EJB 3.0 Core Specification 14.3.9
- *
- * If a client makes a call to a stateful session or entity
- * object that has been removed, the container should throw the
- * javax.ejb.NoSuchEJBException. If the EJB 2.1 client view is used,
- * the container should throw the java.rmi.NoSuchObjectException
- * (which is a subclass of java.rmi.RemoteException) to a remote client,
- * or the javax.ejb.NoSuchObjectLocalException to a local client.
- */
-
- // Initialize
- Throwable t = original;
- ClassLoader cl = this.getClassloader();
-
- // Obtain the actual invoked class
- Class<?> actualInvokingClass = null;
- try
- {
- actualInvokingClass = Class.forName(invokingClassName, true, cl);
- }
- catch (ClassNotFoundException e)
- {
- throw new RuntimeException("Could not obtain invoking class", e);
- }
-
- // Obtain metadata
- JBossSessionBeanMetaData smd = this.getMetaData();
-
- Class<?> remoteClass = Remote.class;
- ClassLoader remoteClassloader = remoteClass.getClassLoader();
- ClassLoader classClassloader = actualInvokingClass.getClassLoader();
- // If local EJB2.x Client
- if (EJBLocalObject.class.isAssignableFrom(actualInvokingClass)
- || EJBLocalHome.class.isAssignableFrom(actualInvokingClass))
- {
- t = new NoSuchObjectLocalException(original.getMessage());
- }
- // If remote EJB2.x Client
- else if (Remote.class.isAssignableFrom(actualInvokingClass)
- || EJBObject.class.isAssignableFrom(actualInvokingClass)
- || EJBHome.class.isAssignableFrom(actualInvokingClass))
- {
- t = new NoSuchObjectException(original.getMessage());
- }
- // Business interface
- else
- {
- // Take no action, this is here just for readability
- }
-
- // Log
- if (log.isTraceEnabled())
- {
- log.trace("Throwing " + t.getClass().getName(), t);
- }
-
- // Return
- return t;
- }
-
private StatefulSessionContainerMethodInvocation buildNewInvocation(MethodInfo info,
StatefulRemoteInvocation statefulInvocation, Class<?>[] initParameterTypes,
Object[] initParameterValues)
More information about the jboss-cvs-commits
mailing list