User: juhalindfors
Date: 02/01/24 14:13:33
Modified:src/main/org/jboss/mx/interceptor
StandardMBeanInterceptor.java
InvocationException.java
Log:
fixed exception handling
Revision ChangesPath
1.5 +73 -17
jmx/src/main/org/jboss/mx/interceptor/StandardMBeanInterceptor.java
Index: StandardMBeanInterceptor.java
===
RCS file:
/cvsroot/jboss/jmx/src/main/org/jboss/mx/interceptor/StandardMBeanInterceptor.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- StandardMBeanInterceptor.java 2001/12/13 00:04:15 1.4
+++ StandardMBeanInterceptor.java 2002/01/24 22:13:33 1.5
@@ -18,7 +18,9 @@
import javax.management.MBeanOperationInfo;
import javax.management.ReflectionException;
import javax.management.RuntimeErrorException;
+import javax.management.RuntimeMBeanException;
import javax.management.MBeanException;
+import javax.management.AttributeNotFoundException;
import javax.management.loading.DefaultLoaderRepository;
import org.jboss.mx.server.StandardMBeanInvoker;
@@ -32,7 +34,7 @@
* @see org.jboss.mx.server.StandardMBean
*
* @author mailto:[EMAIL PROTECTED]";>Juha Lindfors.
- * @version $Revision: 1.4 $
+ * @version $Revision: 1.5 $
*
*/
public class StandardMBeanInterceptor
@@ -40,19 +42,20 @@
{
// Attributes
- private Map methodMap = new HashMap();
- private Class invocationInterface;
- private MBeanInfo info;
- private Object resource;
+ private Map methodMap = new HashMap();
+ private Class invocationInterface = null;
+ private MBeanInfo info = null;
+ private Object resource = null;
// Constructors --
public StandardMBeanInterceptor(Object resource, MBeanInfo info) throws
ReflectionException
{
super("Standard MBean Interceptor");
+ this.info = info;
this.resource = resource;
this.invocationInterface = StandardMBeanInvoker.getMBeanInterface(resource);
-
+
MBeanOperationInfo[] operations = info.getOperations();
for (int i = 0; i < operations.length; ++i)
@@ -68,6 +71,8 @@
strBuf.append(params[j].getType());
}
+// FIXME: separate operation and attribute maps!
+
methodMap.put(name + strBuf.toString(), invocationInterface.getMethod(
name, getSignatureAsClassArray(params,
resource.getClass().getClassLoader(;
}
@@ -184,35 +189,86 @@
// Interceptor overrides --
public Object invoke(Invocation invocation) throws InvocationException
{
+ Method method = null;
+
try
{
- Method m = (Method)methodMap.get(invocation.getOperationWithSignature());
- return m.invoke(resource, invocation.getArgs());
+ method = (Method)methodMap.get(invocation.getOperationWithSignature());
+ return method.invoke(resource, invocation.getArgs());
}
+
catch (IllegalAccessException e)
{
- throw new InvocationException(e, "Illegal access to method " +
invocation.getName());
+ throw new InvocationException(new ReflectionException(e,"Illegal access to
method " + method.getName()));
}
+
catch (IllegalArgumentException e)
{
- throw new InvocationException(e, "Illegal operation arguments in " +
invocation.getName() + ": " + e.getMessage());
+ throw new InvocationException(new ReflectionException(e,
+ "Illegal arguments for " + ((invocation.getInvocationType() ==
Invocation.ATTRIBUTE)
+? "attribute "
+: "operation ")
++ invocation.getName()
++ ": " + e.getMessage())
+ );
}
+
catch (InvocationTargetException e)
{
- if (e.getTargetException() instanceof Exception)
- {
-Exception e2 = (Exception)e.getTargetException();
-throw new InvocationException(e2, "Operation " + invocation.getName() +
" on MBean " + info.getClassName() + " has thrown an exception: " + e2.toString());
+ // exception or error from the MBean implementation ('business exception')
+
+ if (e.getTargetException() instanceof RuntimeException)
+ {
+// runtime exceptions from mbean wrapped in RuntimeMBeanException
+throw new Inv