反序列化JMS ObjectMessage时从Log4j获取IllegalStateException

ecr0jaav  于 2022-11-06  发布在  其他
关注(0)|答案(2)|浏览(165)

我有一个将日志消息发送到JMS应用程序,(ActiveMQ)和一个使用日志消息的进程将日志消息放入数据库。它与log4j1.x一起工作。升级到log4j 2后,使用相同版本的ActiveMQ(编译和运行时都是Java 8)。我可以看到Topic中的消息,但是在消费者中的反序列化过程中抛出了以下异常。在生成器和使用者上部署相同的类编译版本。
救命啊!

java.lang.IllegalArgumentException: readObject requires a FilteredObjectInputStream or an ObjectInputStream that accepts an ObjectInputFilter
    at org.apache.logging.log4j.util.SortedArrayStringMap.readObject(SortedArrayStringMap.java:591)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:1185)
    at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2345)
    at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2236)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1692)
    at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2454)
    at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2378)
    at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2236)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1692)
    at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2454)
    at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2378)
    at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2236)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1692)
    at java.io.ObjectInputStream.readObject(ObjectInputStream.java:508)
    at java.io.ObjectInputStream.readObject(ObjectInputStream.java:466)
  **at org.apache.activemq.command.ActiveMQObjectMessage.getObject(ActiveMQObjectMessage.java:177)**
    at org.apache.activemq.command.ActiveMQObjectMessage.toString(ActiveMQObjectMessage.java:199)
    at java.lang.String.valueOf(String.java:2994)
    at java.lang.StringBuilder.append(StringBuilder.java:137)
  **at com.abc.common.jms.JMSConsumer.onMessage(JMSConsumer.java:106)**
    at org.apache.activemq.ActiveMQMessageConsumer.dispatch(ActiveMQMessageConsumer.java:1021)
    at org.apache.activemq.ActiveMQSessionExecutor.dispatch(ActiveMQSessionExecutor.java:122)
    at org.apache.activemq.ActiveMQSessionExecutor.iterate(ActiveMQSessionExecutor.java:192)
    at org.apache.activemq.thread.PooledTaskRunner.runTask(PooledTaskRunner.java:122)
    at org.apache.activemq.thread.PooledTaskRunner$1.run(PooledTaskRunner.java:43)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:750)
toiithl6

toiithl61#

FilteredObjectInputStream是Log4j-api中的一个类。在ActiveMQ类路径中需要它才能在Java 8中进行反序列化。在Java 9或更高版本中,不需要FilteredObjectInputStream,因为Log4jLogEvent将调用ObjectInputStream上的setObjectInputFilter来执行相同的安全检查。
请注意,Log4j团队强烈建议不要使用Java序列化。

jfgube3f

jfgube3f2#

发现log4j 2已被更改为与Java 9兼容的vis-a-vis序列化/反序列化。将运行时环境更改为Java 9,并且运行正常。
有什么办法可以运行Java 8?

相关问题