I’m sure I’m going about this in completely the wrong way, but can someone point out the error in the code below…
MBeanServer server = (MBeanServer) MBeanServerFactory.findMBeanServer (null).get (0);
ObjectName mBean = new ObjectName ("Catalina:type=DataSource,path=/<context>,host=localhost,class=javax.sql.DataSource,name=\"<name>\"");
String [] params = {"<username>", "<password>"};
Connection myConnection = (Connection) server.invoke (mBean, "getConnection", params, null);
Statement myStatement = myConnection.createStatement ();
String myResult = myStatement.executeQuery ("SELECT 1 FROM DUAL;").toString ();
myConnection.close ();
The problem is occurring when I try to instantiate the Connection object by invoking the getConnection method on my MBean. I receive the following error…
Aug 6, 2012 8:46:03 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet jsp threw exception
java.lang.IllegalArgumentException: Inconsistent arguments and signature
at org.apache.tomcat.util.modeler.ManagedBean.getInvoke(ManagedBean.java:578)
at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:289)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(Unknown Source)
at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(Unknown Source)
What am I doing wrong?
I see you are doing:
You are passing in
nullfor the param signature array which I don’t think is allowed. To quote the javadocs fromMbeanServer.invoke(...):This array should hold the class names of the method parameters you are trying to invoke and they must match precisely. Primitive types should be passed in as the string
"int","long", … while class types as"java.util.Date","java.lang.String", …So I think you need to pass in something like: