dain 2004/02/13 15:21:07
Modified: modules/kernel/src/java/org/apache/geronimo/gbean/jmx
FastMethodInvoker.java GBeanMBean.java
GBeanMBeanOperation.java
modules/kernel/src/java/org/apache/geronimo/kernel
Kernel.java
modules/kernel/src/java/org/apache/geronimo/kernel/config
Configuration.java
Log:
Unwrap JMX exceptions so caller gets pure exceptions.
Revision Changes Path
1.2 +13 -2
incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/FastMethodInvoker.java
Index: FastMethodInvoker.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/FastMethodInvoker.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- FastMethodInvoker.java 12 Jan 2004 01:38:55 -0000 1.1
+++ FastMethodInvoker.java 13 Feb 2004 23:21:07 -0000 1.2
@@ -55,6 +55,7 @@
*/
package org.apache.geronimo.gbean.jmx;
+import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import net.sf.cglib.reflect.FastClass;
@@ -73,6 +74,16 @@
}
public Object invoke(Object target, Object[] arguments) throws Exception
{
- return method.invoke(target, arguments);
+ try {
+ return method.invoke(target, arguments);
+ } catch (InvocationTargetException e) {
+ Throwable cause = e.getTargetException();
+ if (cause instanceof Exception) {
+ throw (Exception) cause;
+ } else if (cause instanceof Error) {
+ throw (Error) cause;
+ }
+ throw e;
+ }
}
}
1.9 +10 -1
incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanMBean.java
Index: GBeanMBean.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanMBean.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- GBeanMBean.java 12 Feb 2004 17:21:42 -0000 1.8
+++ GBeanMBean.java 13 Feb 2004 23:21:07 -0000 1.9
@@ -56,6 +56,7 @@
package org.apache.geronimo.gbean.jmx;
import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
@@ -286,6 +287,14 @@
}
try {
target = constructor.newInstance(parameters);
+ } catch (InvocationTargetException e) {
+ Throwable targetException = e.getTargetException();
+ if(targetException instanceof Exception) {
+ throw (Exception)targetException;
+ } else if(targetException instanceof Error) {
+ throw (Error)targetException;
+ }
+ throw e;
} catch (IllegalArgumentException e) {
log.warn("Constructor mismatch for "+returnValue, e);
throw e;
1.5 +3 -1
incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanMBeanOperation.java
Index: GBeanMBeanOperation.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanMBeanOperation.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- GBeanMBeanOperation.java 18 Jan 2004 01:22:42 -0000 1.4
+++ GBeanMBeanOperation.java 13 Feb 2004 23:21:07 -0000 1.5
@@ -191,6 +191,8 @@
try {
Thread.currentThread().setContextClassLoader(gmbean.getClassLoader());
return methodInvoker.invoke(gmbean.getTarget(), arguments);
+ } catch (Exception e) {
+ throw new ReflectionException(e);
} catch (Throwable throwable) {
throw new ReflectionException(new
InvocationTargetException(throwable));
} finally {
1.18 +23 -29
incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/Kernel.java
Index: Kernel.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/Kernel.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- Kernel.java 12 Feb 2004 18:22:55 -0000 1.17
+++ Kernel.java 13 Feb 2004 23:21:07 -0000 1.18
@@ -68,20 +68,15 @@
import java.util.Map;
import javax.management.InstanceAlreadyExistsException;
import javax.management.InstanceNotFoundException;
-import javax.management.ListenerNotFoundException;
-import javax.management.MBeanException;
-import javax.management.MBeanNotificationInfo;
+import javax.management.JMException;
+import javax.management.JMRuntimeException;
import javax.management.MBeanRegistrationException;
import javax.management.MBeanServer;
import javax.management.MBeanServerFactory;
import javax.management.MalformedObjectNameException;
import javax.management.NotCompliantMBeanException;
-import javax.management.NotificationBroadcaster;
-import javax.management.NotificationFilter;
-import javax.management.NotificationListener;
-import javax.management.ObjectName;
-import javax.management.ReflectionException;
import javax.management.NotificationBroadcasterSupport;
+import javax.management.ObjectName;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -113,7 +108,7 @@
*
* @version $Revision$ $Date$
*/
-public class Kernel extends NotificationBroadcasterSupport implements
Serializable, KernelMBean{
+public class Kernel extends NotificationBroadcasterSupport implements
Serializable, KernelMBean {
/**
* The JMX name used by a Kernel to register itself when it boots.
@@ -382,37 +377,36 @@
public void startGBean(ObjectName name) throws
InstanceNotFoundException, InvalidConfigException {
try {
mbServer.invoke(name, "start", null, null);
- } catch (MBeanException e) {
- // start is not supposed to throw anything
- // todo it can now throw Exception and we should let that through
- throw new InvalidConfigException("Invalid GBean configuration
for " + name, e);
- } catch (ReflectionException e) {
- // @todo this is a bad exception - we should dig the cause out
of the RE.ITE
- throw new InvalidConfigException("Invalid GBean configuration
for " + name, e);
+ } catch (JMException e) {
+ Throwable cause = e;
+ while ((cause instanceof JMException || cause instanceof
JMRuntimeException) && cause.getCause() != null) {
+ cause = cause.getCause();
+ }
+ throw new InvalidConfigException("Invalid GBean configuration
for " + name, cause);
}
}
public void startRecursiveGBean(ObjectName name) throws
InstanceNotFoundException, InvalidConfigException {
try {
mbServer.invoke(name, "startRecursive", null, null);
- } catch (MBeanException e) {
- // start is not supposed to throw anything
- // todo it can now throw Exception and we should let that through
- throw new InvalidConfigException("Invalid GBean configuration
for " + name, e);
- } catch (ReflectionException e) {
- // @todo this is a bad exception - we should dig the cause out
of the RE.ITE
- throw new InvalidConfigException("Invalid GBean configuration
for " + name, e);
+ } catch (JMException e) {
+ Throwable cause = e;
+ while ((cause instanceof JMException || cause instanceof
JMRuntimeException) && cause.getCause() != null) {
+ cause = cause.getCause();
+ }
+ throw new InvalidConfigException("Invalid GBean configuration
for " + name, cause);
}
}
public void stopGBean(ObjectName name) throws InstanceNotFoundException,
InvalidConfigException {
try {
mbServer.invoke(name, "stop", null, null);
- } catch (MBeanException e) {
- // stop is not supposed to throw anything
- throw new InvalidConfigException("Invalid GBean configuration
for " + name, e);
- } catch (ReflectionException e) {
- throw new InvalidConfigException("Invalid GBean configuration
for " + name, e);
+ } catch (JMException e) {
+ Throwable cause = e;
+ while ((cause instanceof JMException || cause instanceof
JMRuntimeException) && cause.getCause() != null) {
+ cause = cause.getCause();
+ }
+ throw new InvalidConfigException("Invalid GBean configuration
for " + name, cause);
}
}
1.11 +15 -4
incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/config/Configuration.java
Index: Configuration.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/config/Configuration.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- Configuration.java 12 Feb 2004 18:20:24 -0000 1.10
+++ Configuration.java 13 Feb 2004 23:21:07 -0000 1.11
@@ -66,15 +66,16 @@
import java.net.URI;
import java.net.URL;
import java.net.URLClassLoader;
+import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
-import java.util.Arrays;
import javax.management.AttributeNotFoundException;
import javax.management.InvalidAttributeValueException;
+import javax.management.JMRuntimeException;
import javax.management.MBeanException;
import javax.management.MBeanServer;
import javax.management.ObjectName;
@@ -92,8 +93,8 @@
import org.apache.geronimo.gbean.jmx.GBeanMBean;
import org.apache.geronimo.gbean.jmx.GBeanMBeanContext;
import org.apache.geronimo.kernel.Kernel;
-import org.apache.geronimo.kernel.repository.Repository;
import org.apache.geronimo.kernel.repository.MissingDependencyException;
+import org.apache.geronimo.kernel.repository.Repository;
/**
* A Configuration represents a collection of runnable services that can be
@@ -208,7 +209,17 @@
ObjectName name = (ObjectName) entry.getKey();
GBeanMBean gbean = (GBeanMBean) entry.getValue();
log.trace("Registering GBean " + name);
- mbServer.registerMBean(gbean, name);
+ try {
+ mbServer.registerMBean(gbean, name);
+ } catch (JMRuntimeException e) {
+ Throwable cause = e.getCause();
+ if (cause instanceof Exception) {
+ throw (Exception) cause;
+ } else if (cause instanceof Error) {
+ throw (Error) cause;
+ }
+ throw e;
+ }
mbServer.invoke(Kernel.DEPENDENCY_SERVICE, "addDependency", new
Object[]{name, context.getObjectName()}, new
String[]{ObjectName.class.getName(), ObjectName.class.getName()});
}