这是JMX bean调用(失败):
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);
抛出异常:
java.rmi.UnmarshalException: error unmarshalling return; nested exception is:
java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException: org.apache.cxf.jaxrs.impl.ResponseIm
查看我的代码时,调用的函数是:
import javax.ws.rs.core.Response;
@ManagedOperation
public Response example() throws GeneralException {
//do some things with the response object
...
return response.build();
}
根据我的理解,我遇到的问题是抽象类javax.ws.rs.core.Response没有序列化。
任何想法如何绕过这个问题?
答案 0 :(得分:1)
JMX使用java序列化来传输参数和操作结果。即使该类为Serializable
,您也需要在客户端的类路径中使用它。
除了添加将对象呈现为String的操作之外,没有其他解决方案。如果运气好,可以使用toString()
,但如果对象没有覆盖Object.toString()
,则必须自行滚动。