Unable to execute methods on MBean proxy
eldiosyeldiablo Jul 19, 2005 6:48 PMI have implemented a simple MBean and tested it using the JMX Console but I get an error when I try to execute any method programatically from my ejb session.
The error is
[STDOUT] java.lang.reflect.UndeclaredThrowableException 18:39:36,931 INFO [STDOUT] at $Proxy57.getDbDriver(Unknown Source) 18:39:36,932 INFO [STDOUT] at com.relevant.e3.ejb.item.ItemBO.getDbDriverMBean(ItemBO.java:41) 18:39:36,932 INFO [STDOUT] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 18:39:36,932 INFO [STDOUT] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 18:39:36,932 INFO [STDOUT] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 18:39:36,932 INFO [STDOUT] at java.lang.reflect.Method.invoke(Method.java:585) 18:39:36,932 INFO [STDOUT] at com.relevant.e3.ejb.businesscontroller.BusinessController.execute(BusinessController.java:293) 18:39:36,932 INFO [STDOUT] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 18:39:36,933 INFO [STDOUT] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 18:39:36,933 INFO [STDOUT] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 18:39:36,933 INFO [STDOUT] at java.lang.reflect.Method.invoke(Method.java:585) 18:39:36,933 INFO [STDOUT] at org.jboss.invocation.Invocation.performCall(Invocation.java:345) 18:39:36,933 INFO [STDOUT] at org.jboss.ejb.StatefulSessionContainer$ContainerInterceptor.invoke(StatefulSessionContainer.java:584) 18:39:36,933 INFO [STDOUT] at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:123) 18:39:36,933 INFO [STDOUT] at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:185) 18:39:36,933 INFO [STDOUT] at org.jboss.ejb.plugins.StatefulSessionInstanceInterceptor.invoke(StatefulSessionInstanceInterceptor.java:294) 18:39:36,933 INFO [STDOUT] at org.jboss.ejb.plugins.CallValidationInterceptor.invoke(CallValidationInterceptor.java:48) 18:39:36,934 INFO [STDOUT] at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:105) 18:39:36,934 INFO [STDOUT] at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:313) 18:39:36,934 INFO [STDOUT] at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:146) 18:39:36,934 INFO [STDOUT] at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:192) 18:39:36,934 INFO [STDOUT] at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invoke(ProxyFactoryFinderInterceptor.java:122) 18:39:36,934 INFO [STDOUT] at org.jboss.ejb.SessionContainer.internalInvoke(SessionContainer.java:624) 18:39:36,934 INFO [STDOUT] at org.jboss.ejb.Container.invoke(Container.java:870) 18:39:36,934 INFO [STDOUT] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 18:39:36,934 INFO [STDOUT] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 18:39:36,935 INFO [STDOUT] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 18:39:36,935 INFO [STDOUT] at java.lang.reflect.Method.invoke(Method.java:585) 18:39:36,935 INFO [STDOUT] at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:144) 18:39:36,935 INFO [STDOUT] at org.jboss.mx.server.Invocation.dispatch(Invocation.java:80) 18:39:36,935 INFO [STDOUT] at org.jboss.mx.server.Invocation.invoke(Invocation.java:72) 18:39:36,935 INFO [STDOUT] at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:249) 18:39:36,935 INFO [STDOUT] at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:642) 18:39:36,935 INFO [STDOUT] at org.jboss.invocation.jrmp.server.JRMPInvoker$MBeanServerAction.invoke(JRMPInvoker.java:805) 18:39:36,935 INFO [STDOUT] at org.jboss.invocation.jrmp.server.JRMPInvoker.invoke(JRMPInvoker.java:406) 18:39:36,935 INFO [STDOUT] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 18:39:36,936 INFO [STDOUT] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 18:39:36,936 INFO [STDOUT] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 18:39:36,936 INFO [STDOUT] at java.lang.reflect.Method.invoke(Method.java:585) 18:39:36,936 INFO [STDOUT] at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:294) 18:39:36,936 INFO [STDOUT] at sun.rmi.transport.Transport$1.run(Transport.java:153) 18:39:36,936 INFO [STDOUT] at java.security.AccessController.doPrivileged(Native Method) 18:39:36,936 INFO [STDOUT] at sun.rmi.transport.Transport.serviceCall(Transport.java:149) 18:39:36,936 INFO [STDOUT] at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460) 18:39:36,936 INFO [STDOUT] at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701) 18:39:36,937 INFO [STDOUT] at java.lang.Thread.run(Thread.java:595) 18:39:36,939 INFO [STDOUT] Caused by: javax.management.InstanceNotFoundException: com.relevant:name=E3Settings is not registered. 18:39:36,939 INFO [STDOUT] at org.jboss.mx.server.registry.BasicMBeanRegistry.get(BasicMBeanRegistry.java:509) 18:39:36,940 INFO [STDOUT] at org.jboss.mx.server.MBeanServerImpl.getAttribute(MBeanServerImpl.java:533) 18:39:36,940 INFO [STDOUT] at javax.management.MBeanServerInvocationHandler.invoke(MBeanServerInvocationHandler.java:175) 18:39:36,940 INFO [STDOUT] ... 46 more
The code to retrieve the MBean reference is
protected final E3SettingsMBean getServerSettings() { E3SettingsMBean mbean = null; //target MBean ObjectName objectName = null; try { objectName = new ObjectName("com.relevant:name=E3Settings"); } catch (MalformedObjectNameException e) { return null; } if (objectName != null) { //find the local MBeanServer // MBeanServer server = MBeanServerLocator.locateJBoss(); MBeanServer server = ManagementFactory.getPlatformMBeanServer(); // Get a type-safe dynamic proxy mbean = (E3SettingsMBean)MBeanServerInvocationHandler.newProxyInstance( server, objectName, E3SettingsMBean.class, false); // Use the proxy String dbURL = mbean.getDbURL(); mbean.sayHello(); } return mbean; }
The MBean interface is
package com.relevant.e3.ejb.resource; import org.jboss.system.ServiceMBean; public interface E3SettingsMBean extends ServiceMBean { public void sayHello(); public int add(int x, int y); public String getDbDriver(); public void setDbDriver(String driver); public String getDbURL(); public void setDbURL(String url); public String getDbUser(); public void setDbUser(String user); public String getDbPassword(); public void setDbPassword(String password); }
The implementation of the interface is..
package com.relevant.e3.ejb.resource; import javax.management.*; import org.apache.log4j.Logger; import org.jboss.system.ServiceMBeanSupport; public class E3Settings extends ServiceMBeanSupport //public class E3Settings extends NotificationBroadcasterSupport implements E3SettingsMBean { protected static Logger logger; private static final String DEFAULT_DBDRIVER = "net.sourceforge.jtds.jdbc.Driver"; private String dbDriver = DEFAULT_DBDRIVER; private static final String DEFAULT_DBURL = "jdbc:jtds:sqlserver://sql2003:1433/patbiz"; private String dbURL = DEFAULT_DBURL; private static final String DEFAULT_DBUSER = "java"; private String dbUser = DEFAULT_DBUSER; private static final String DEFAULT_DBPASSWORD = "java"; private String dbPassword = DEFAULT_DBPASSWORD; private String name="E3Settings"; //Used for notifications private long sequenceNumber = 1; public E3Settings() { if (logger == null) { logger = Logger.getLogger(E3Settings.class); } } /** * Testing java docs * @jmx Testing * @jmx.desc Testing jmx.desc */ public void sayHello() { System.out.println("hello, world"); } public int add(int x, int y) { return x + y; } public String getDbDriver() { return dbDriver; } /** * Sets the database connection string for the MBean. * @jmx.desc * * @param Value to set the database connection string to. */ public synchronized void setDbDriver(String driver) { String oldStr = dbDriver; dbDriver = driver; logger.debug("dbDriver now " + dbDriver); Notification n = new AttributeChangeNotification(this, sequenceNumber++, System.currentTimeMillis(), "dbDriver changed", "DbDriver", "int", oldStr, dbDriver); sendNotification(n); } public String getDbURL() { return dbURL; } public synchronized void setDbURL(String url) { String oldStr = dbURL; dbURL = url; logger.debug("dbURL now " + dbURL); Notification n = new AttributeChangeNotification(this, sequenceNumber++, System.currentTimeMillis(), "dbURL changed", "DbURL", "int", oldStr, dbURL); sendNotification(n); } public String getDbUser() { return dbUser; } public synchronized void setDbUser(String user) { String oldStr = dbUser; dbUser = user; logger.debug("dbUser now " + dbUser); Notification n = new AttributeChangeNotification(this, sequenceNumber++, System.currentTimeMillis(), "dbUser changed", "DbUser", "int", oldStr, dbUser); sendNotification(n); } public String getDbPassword() { return dbPassword; } public synchronized void setDbPassword(String password) { String oldStr = dbPassword; dbPassword = password; logger.debug("dbPassword now " + dbPassword); Notification n = new AttributeChangeNotification(this, sequenceNumber++, System.currentTimeMillis(), "dbPassword changed", "DbPassword", "int", oldStr, dbPassword); sendNotification(n); } //The lifecycle protected void startService() throws Exception { log.info("Starting with message= E3Settings"); } protected void stopService() throws Exception { log.info("Stopping with message= E3Settings"); } }
The jboss-service.xml file is..
<?xml version="1.0" encoding="UTF-8"?> <server> <mbean code="com.relevant.e3.ejb.resource.E3Settings" name="com.relevant:service=E3Settings"> <!-- A plain attribute --> <attribute name="DbDriver">net.sourceforge.jtds.jdbc.Driver</attribute> <attribute name="DbURL">jdbc:jtds:sqlserver://sql2003:1433/patbiz</attribute> <attribute name="DbUser">java</attribute> <attribute name="DbPassword">java</attribute> </mbean> </server>
Again sorry for the long post but I'm sure someone would have asked for one of the above files if I had left them out.
Thank you,
-David