Java JMX invoking method returning javax.ws.rs.core.Response object not working (get NotSerializableException)

StackOverflow https://stackoverflow.com/questions/18378784

Question

This is the JMX bean invoke (that fails) :

import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;
import javax.ws.rs.core.Response;
MBeanServerConnection mbeanConn

//some code going on ...    
...

response = (Response) mbeanConn.invoke(myBean,"example", null, null);

It throws the exception :

java.rmi.UnmarshalException: error unmarshalling return; nested exception is: 
    java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException: org.apache.cxf.jaxrs.impl.ResponseIm

When looking in my code the function that is invoked is :

  import javax.ws.rs.core.Response;

   @ManagedOperation
   public Response example() throws GeneralException {
    //do some things with the response object
    ...
    return response.build();
   }

From my understanding I have a problem that the abstract class javax.ws.rs.core.Response isn't Serialized.

Any ideas how to bypass this problem ?

Was it helpful?

Solution

JMX uses java serialization to transfer arguments and operation results. Even if the class was Serializable you'd need it on the client's classpath.

There is no solution except adding an operation that renders the object as, say, a String. If you are lucky, you can use toString() but if the object hasn't overridden Object.toString(), you'll have to roll your own.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top