Search code examples
javatomcatserializationrmijmx

Java RMI UnmarsharledException in tomcat web application


I am trying to query a JMX MBeanServer running in a Tomcat WebApplication. I'm seeing the following error while getting the list of attributes for a MBean

java.rmi.UnmarshalException: error unmarshalling return; nested exception is:
    java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException: org.apache.catalina.core.StandardContext
    at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:191)
    at com.sun.jmx.remote.internal.PRef.invoke(Unknown Source)
    at javax.management.remote.rmi.RMIConnectionImpl_Stub.getAttributes(Unknown Source)
    at javax.management.remote.rmi.RMIConnector$RemoteMBeanServerConnection.getAttributes(RMIConnector.java:927)

Am I doing anything wrong in my web application. I have tested my JMX client against many other java apps and have never come across this error. Will be helpful if someone has already come across this exception.

edit:

Found the bug

Bean: Catalina:name="ajp-bio-8009",type=ThreadPool
~~~~~
Attributes
.....
maxThreads:200
sSLEnabled:false
keystorePass:null
localPort:8009
connectionCount:1
currentThreadCount:0
keepAliveTimeout:-1
threadPriority:5
keyPass:null
useComet:false
soLinger:-1
sslEnabledProtocolsArray:[Ljava.lang.String;@3d1a70a7
socketProperties:java.rmi.UnmarshalException: error unmarshalling
...
java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException: org.apache.tomcat.util.net.SocketProperties

Solution

  • Your getAttributes() method returns a type StandardContext which is neither Serializable nor an exported remote object. So when the server went to write the return value, it incurred a NotSerializableException.

    You seem to be trying to get the application context or its attributes remotely?