ActiveMQ XStream ForbiddenClassException

ActiveMQ XStream ForbiddenClassException

我在 java 应用程序中使用 ActiveMQ 5.16.2 作为代理和客户端 5.16.1。有时我会在循环中遇到此错误:

---- Debugging information ----
cause-exception     : com.thoughtworks.xstream.security.ForbiddenClassException
cause-message       : java.io.IOException
class               : org.apache.activemq.command.ExceptionResponse
required-type       : org.apache.activemq.command.ExceptionResponse
converter-type      : 
com.thoughtworks.xstream.converters.reflection.ReflectionConverter
path                : /org.apache.activemq.command.ExceptionResponse/exception
line number         : 5
version             : 1.4.15
-------------------------------
    at org.apache.activemq.util.IOExceptionSupport.create(IOExceptionSupport.java:34)
    at org.apache.activemq.transport.http.HttpClientTransport.run(HttpClientTransport.java:205)
    at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: com.thoughtworks.xstream.converters.ConversionException: 
---- Debugging information ----
cause-exception     : com.thoughtworks.xstream.security.ForbiddenClassException
cause-message       : java.io.IOException
class               : org.apache.activemq.command.ExceptionResponse
required-type       : org.apache.activemq.command.ExceptionResponse
converter-type      : com.thoughtworks.xstream.converters.reflection.ReflectionConverter
path                : /org.apache.activemq.command.ExceptionResponse/exception
line number         : 5
version             : 1.4.15
-------------------------------
    at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:77)
    at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:72)
    at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:66)
    at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:50)
    at com.thoughtworks.xstream.core.TreeUnmarshaller.start(TreeUnmarshaller.java:134)
    at com.thoughtworks.xstream.core.AbstractTreeMarshallingStrategy.unmarshal(AbstractTreeMarshallingStrategy.java:32)
    at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:1409)
    at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:1388)
    at com.thoughtworks.xstream.XStream.fromXML(XStream.java:1273)
    at com.thoughtworks.xstream.XStream.fromXML(XStream.java:1264)
    at org.apache.activemq.transport.xstream.XStreamWireFormat.unmarshalText(XStreamWireFormat.java:66)
    at org.apache.activemq.transport.util.TextWireFormat.unmarshal(TextWireFormat.java:56)
    at org.apache.activemq.transport.http.HttpClientTransport.run(HttpClientTransport.java:196)
... 1 common frames omitted
Caused by: com.thoughtworks.xstream.security.ForbiddenClassException: java.io.IOException
   at com.thoughtworks.xstream.security.NoTypePermission.allows(NoTypePermission.java:26)
   at com.thoughtworks.xstream.mapper.SecurityMapper.realClass(SecurityMapper.java:74)
   at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:125)
   at com.thoughtworks.xstream.mapper.CachingMapper.realClass(CachingMapper.java:47)
   at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doUnmarshal(AbstractReflectionConverter.java:420)
   at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshal(AbstractReflectionConverter.java:277)
   at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:72)
... 13 common frames omitted

我在 5.16.0 时已经有类似的错误 XStream,在 5.16.1 中更正,但现在是另一个错误。

我尝试使用 5.16.2 客户端,但出现相同的错误:

--- Debugging information ----
cause-exception     : 
com.thoughtworks.xstream.security.ForbiddenClassException
cause-message       : java.io.IOException
class               : org.apache.activemq.command.ExceptionResponse
required-type       : org.apache.activemq.command.ExceptionResponse
converter-type      : com.thoughtworks.xstream.converters.reflection.ReflectionConverter
path                : /org.apache.activemq.command.ExceptionResponse/exception
line number         : 5
version             : 1.4.16
-------------------------------

客户端异常。我们正在使用 XStream,因为客户端通过 HTTP 连接,并且根据 the documentation.

,此用例的客户端需要 XStream

此应用程序已经 运行 在 TCP 中使用了很长时间,但我们也必须在 HTTPS 中使用它。由于我们一直在测试 HTTPS,我们遇到了一些奇怪的行为,测试由于 XStream 错误而失败,但其他 HTTPS 调用没有问题。我只是想弄清楚为什么切换到 HTTPS 会导致此问题。

在我看来 XStream 正在尝试处理来自代理的 OpenWire org.apache.activemq.command.ExceptionResponse 消息。此消息包含一个序列化的 java.io.IOException 并且 XStream 无法转换它,因为它期望一个 XML 有效负载。这就是为什么异常说:

Caused by: com.thoughtworks.xstream.security.ForbiddenClassException: java.io.IOException

ForbiddenClassException 是 XStream 为响应无法转换的 java.io.IOException 而抛出的异常。

首先不清楚是什么触发了 java.io.IOException,因此值得调查(例如查看代理日志)。 XStream 失败本身似乎是一个错误。但是,我不确定 HTTP/S 传输的维护情况如何,因此可能不会很快提供错误修复(如果有的话)。您可以尝试从 ActiveMQ 5.x(即“经典”)迁移到 ActiveMQ Artemis which also supports HTTP/S.