I'm monitoring, via JMX, a servlet running in Tomcat with another servlet running in the same instance of Tomcat. When I setup the get()s to return standard Java datatypes( String, int, byte[], etc. ), this works fine. But when I use a user-defined class, I get a ClassCastException which gives this message:
java.lang.ClassCastException: blah.My_UserDefinedClass cannot be cast to blah.My_UserDefinedClass
I'm fairly sure this is because of the different class loaders at the instrumentation and at the management layer ( the monitored servlet and the monitoring servlet, respectively ). I've double-checked the .jar file that contains the user-defined class for each servlet and both jar files are identical to each other.
I'm using standard MBeans, and have set up the monitored servlet to return this attribute:
public interface MyMonitorMBean
{
public My_UserDefinedClass getAllData();
}
implementation:
public class MyMonitor implements MyMonitorMBean
{
private My_UserDefinedClass mAllData;
@Override
public My_UserDefinedClass getAllData()
{
return mAllData;
}
}
Code in management servlet to access this data:
private void getAllDataFromMBean()
{
try
{
// this line generates the ClassCastException
My_UserDefinedClass allData = (My_UserDefinedClass)mMBS.getAttribute( mObjectName, "AllData" );
}
catch( Exception e )
{
}
}
While I could generate multiple get()s with each sending a standard Java datatype, I would like to build/use my own POD/POJO class that encapsulates all of the various standard bits and bobs ( which are standard Java datatypes ) that I want to send back so that I can get my data in a single call.
Any thoughts?
Thanks,
Bill
Using tomcat7, java6, windows xp, 32bit