You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by da...@apache.org on 2007/04/11 20:32:58 UTC
svn commit: r527601 - in
/incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client:
EJBHomeHandler.java EJBInvocationHandler.java EJBObjectHandler.java
Author: dain
Date: Wed Apr 11 11:32:57 2007
New Revision: 527601
URL: http://svn.apache.org/viewvc?view=rev&rev=527601
Log:
convert remote exceptions to local exceptions for business interfaces
Modified:
incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/EJBHomeHandler.java
incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/EJBInvocationHandler.java
incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/EJBObjectHandler.java
Modified: incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/EJBHomeHandler.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/EJBHomeHandler.java?view=diff&rev=527601&r1=527600&r2=527601
==============================================================================
--- incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/EJBHomeHandler.java (original)
+++ incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/EJBHomeHandler.java Wed Apr 11 11:32:57 2007
@@ -21,12 +21,11 @@
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.lang.reflect.Method;
-import java.rmi.AccessException;
import java.rmi.RemoteException;
-import javax.ejb.EJBAccessException;
import javax.ejb.EJBHome;
import javax.ejb.Handle;
+import javax.ejb.EJBException;
import org.apache.openejb.client.proxy.ProxyManager;
@@ -148,26 +147,30 @@
} catch (SystemException e) {
invalidateReference();
- throw e.getCause();
+ throw convert(e.getCause());
/*
* Application exceptions must be reported dirctly to the client. They
* do not impact the viability of the proxy.
*/
} catch (ApplicationException ae) {
- Throwable exc = (ae.getCause() != null) ? ae.getCause() : ae;
- if (exc instanceof EJBAccessException) {
- throw new AccessException(exc.getMessage());
- }
- throw exc;
+ throw convert(ae.getCause());
/*
* A system exception would be highly unusual and would indicate a sever
* problem with the container system.
*/
} catch (SystemError se) {
invalidateReference();
- throw new RemoteException("Container has suffered a SystemException", se.getCause());
+ if (remote) {
+ throw new RemoteException("Container has suffered a SystemException", se.getCause());
+ } else {
+ throw new EJBException("Container has suffered a SystemException").initCause(se.getCause());
+ }
} catch (Throwable oe) {
- throw new RemoteException("Unknown Container Exception", oe.getCause());
+ if (remote) {
+ throw new RemoteException("Unknown Container Exception", oe.getCause());
+ } else {
+ throw new EJBException("Unknown Container Exception").initCause(oe.getCause());
+ }
}
}
Modified: incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/EJBInvocationHandler.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/EJBInvocationHandler.java?view=diff&rev=527601&r1=527600&r2=527601
==============================================================================
--- incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/EJBInvocationHandler.java (original)
+++ incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/EJBInvocationHandler.java Wed Apr 11 11:32:57 2007
@@ -19,14 +19,23 @@
import java.io.Serializable;
import java.lang.reflect.Method;
import java.rmi.NoSuchObjectException;
+import java.rmi.RemoteException;
+import java.rmi.AccessException;
import java.util.HashSet;
import java.util.Hashtable;
-import java.util.Set;
-import java.security.AccessController;
import org.apache.openejb.client.proxy.InvocationHandler;
-import javax.security.auth.Subject;
+import javax.transaction.TransactionRequiredException;
+import javax.transaction.TransactionRolledbackException;
+import javax.ejb.TransactionRequiredLocalException;
+import javax.ejb.TransactionRolledbackLocalException;
+import javax.ejb.NoSuchObjectLocalException;
+import javax.ejb.AccessLocalException;
+import javax.ejb.EJBException;
+import javax.ejb.EJBAccessException;
+import javax.ejb.EJBObject;
+import javax.ejb.EJBHome;
public abstract class EJBInvocationHandler implements InvocationHandler, Serializable {
@@ -47,14 +56,18 @@
protected transient ClientMetaData client;
protected transient Object primaryKey;
+ protected final boolean remote;
public EJBInvocationHandler() {
+ remote = false;
}
public EJBInvocationHandler(EJBMetaDataImpl ejb, ServerMetaData server, ClientMetaData client) {
this.ejb = ejb;
this.server = server;
this.client = client;
+ Class remoteInterface = ejb.getRemoteInterfaceClass();
+ remote = remoteInterface != null && (EJBObject.class.isAssignableFrom(remoteInterface) || EJBHome.class.isAssignableFrom(remoteInterface));
}
public EJBInvocationHandler(EJBMetaDataImpl ejb, ServerMetaData server, ClientMetaData client, Object primaryKey) {
@@ -100,7 +113,7 @@
protected void invalidateReference() {
this.server = null;
this.client = null;
- this.ejb = null;
+// this.ejb = null;
this.inProxyMap = false;
this.isInvalidReference = true;
this.primaryKey = null;
@@ -130,5 +143,39 @@
synchronized (set) {
set.add(handler);
}
+ }
+
+ protected Throwable convert(Throwable e) {
+ if (!remote && e instanceof RemoteException) {
+ if (e instanceof TransactionRequiredException) {
+ return new TransactionRequiredLocalException(e.getMessage()).initCause(getCause(e));
+ }
+ if (e instanceof TransactionRolledbackException) {
+ return new TransactionRolledbackLocalException(e.getMessage()).initCause(getCause(e));
+ }
+ if (e instanceof NoSuchObjectException) {
+ return new NoSuchObjectLocalException(e.getMessage()).initCause(getCause(e));
+ }
+ if (e instanceof AccessException) {
+ return new AccessLocalException(e.getMessage()).initCause(getCause(e));
+ }
+ return new EJBException(e.getMessage()).initCause(getCause(e));
+ }
+
+ if (remote && e instanceof EJBAccessException) {
+ if (e.getCause() instanceof Exception) {
+ return new AccessException(e.getMessage(), (Exception) e.getCause());
+ } else {
+ return new AccessException(e.getMessage());
+ }
+ }
+ return e;
+ }
+
+ protected Throwable getCause(Throwable e) {
+ if (e != null && e.getCause() != null) {
+ return e.getCause();
+ }
+ return e;
}
}
Modified: incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/EJBObjectHandler.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/EJBObjectHandler.java?view=diff&rev=527601&r1=527600&r2=527601
==============================================================================
--- incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/EJBObjectHandler.java (original)
+++ incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/EJBObjectHandler.java Wed Apr 11 11:32:57 2007
@@ -16,16 +16,14 @@
*/
package org.apache.openejb.client;
+import org.apache.openejb.client.proxy.ProxyManager;
+
+import javax.ejb.EJBException;
+import javax.ejb.EJBObject;
import java.lang.reflect.Method;
import java.rmi.RemoteException;
-import java.rmi.AccessException;
-import java.util.List;
import java.util.ArrayList;
-
-import javax.ejb.EJBObject;
-import javax.ejb.EJBAccessException;
-
-import org.apache.openejb.client.proxy.ProxyManager;
+import java.util.List;
public abstract class EJBObjectHandler extends EJBInvocationHandler {
@@ -156,28 +154,30 @@
} catch (SystemException e) {
invalidateAllHandlers(getRegistryId());
- throw e.getCause();
+ throw convert(e.getCause());
/*
* Application exceptions must be reported dirctly to the client. They
* do not impact the viability of the proxy.
*/
} catch (ApplicationException ae) {
- Throwable exc = (ae.getCause() != null) ? ae.getCause() : ae;
- if (exc instanceof EJBAccessException) {
- if (ejb.remoteClass != null && EJBObject.class.isAssignableFrom(ejb.getRemoteInterfaceClass())) {
- throw new AccessException(exc.getMessage());
- }
- }
- throw exc;
+ throw convert(ae.getCause());
/*
* A system exception would be highly unusual and would indicate a sever
* problem with the container system.
*/
} catch (SystemError se) {
invalidateReference();
- throw new RemoteException("Container has suffered a SystemException", se.getCause());
+ if (remote) {
+ throw new RemoteException("Container has suffered a SystemException", se.getCause());
+ } else {
+ throw new EJBException("Container has suffered a SystemException").initCause(se.getCause());
+ }
} catch (Throwable oe) {
- throw new RemoteException("Unknown Container Exception: "+oe.getClass().getName()+": "+oe.getMessage(), oe.getCause());
+ if (remote) {
+ throw new RemoteException("Unknown Container Exception: "+oe.getClass().getName()+": "+oe.getMessage(), oe.getCause());
+ } else {
+ throw new EJBException("Unknown Container Exception: "+oe.getClass().getName()+": "+oe.getMessage()).initCause(oe.getCause());
+ }
}
return retValue;
}