Skip to content

Commit

Permalink
[KARAF-2513] management boot can not process MBean without implement …
Browse files Browse the repository at this point in the history
…DynamicMBean interface

This fixes the issue. The problem was that the InvocationTargetException was't unwrapped before it was passed to the caller.
Verified with the ManagedCamelContext as reported in the bug.
Also added unit test.


git-svn-id: https://svn.apache.org/repos/asf/karaf/trunk@1544153 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
bosschaert committed Nov 21, 2013
1 parent 66cd8f8 commit 738959b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 12 deletions.
Expand Up @@ -16,16 +16,18 @@
*/
package org.apache.karaf.management.boot;

import javax.management.MBeanServer;
import javax.management.MBeanServerBuilder;
import javax.management.MBeanServerDelegate;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import javax.management.MBeanServer;
import javax.management.MBeanServerBuilder;
import javax.management.MBeanServerDelegate;

public class KarafMBeanServerBuilder extends MBeanServerBuilder {

private static volatile InvocationHandler guard;
Expand Down Expand Up @@ -60,9 +62,11 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl
}
guard.invoke(proxy, method, args);
}
return method.invoke(wrapped, args);
try {
return method.invoke(wrapped, args);
} catch (InvocationTargetException ite) {
throw ite.getCause();
}
}

}

}
Expand Up @@ -16,17 +16,21 @@
*/
package org.apache.karaf.management.boot;

import junit.framework.TestCase;
import org.easymock.EasyMock;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

import javax.management.AttributeList;
import javax.management.InstanceNotFoundException;
import javax.management.MBeanServer;
import javax.management.NotCompliantMBeanException;
import javax.management.ObjectName;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

import junit.framework.TestCase;

import org.easymock.EasyMock;


public class KarafMBeanServerBuilderTest extends TestCase {

Expand Down Expand Up @@ -148,6 +152,22 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl
}
}

public void testMBeanServerThrowsException() throws Exception {
MBeanServer mbs = EasyMock.createMock(MBeanServer.class);
EasyMock.replay(mbs);

KarafMBeanServerBuilder mbsb = new KarafMBeanServerBuilder();
MBeanServer kmbs = mbsb.newMBeanServer("test", mbs, null);

try {
kmbs.registerMBean("Foo", ObjectName.getInstance("foo.bar:type=TestObject"));
} catch (NotCompliantMBeanException ncme) {
// good
return;
}
fail("Should have thrown a NotCompliantMBeanException");
}

private Throwable getInnermostException(Throwable th) {
if (th.getCause() != null) {
return getInnermostException(th.getCause());
Expand Down

0 comments on commit 738959b

Please sign in to comment.