EJB3 MessageDrivenBean создает исключение. Этот класс не может быть сериализован как полезная нагрузка ObjectMessage при использовании внешней очереди ActiveMQ. - PullRequest
0 голосов
/ 15 февраля 2019

Я использую управляемый сообщениями bean-компонент с @MessageDriven для использования внешней очереди ActiveMQ в контейнере Docker, а для полезной нагрузки ObjectMessage требуется использование Java Pojo (ArquivoRetornoDTO).

Итак, при вызове метода onMessage выдается это исключение:

ClassNotFoundException: Forbidden class foo.bar.ArquivoRetornoDTO! 
This class is not trusted to be serialized as ObjectMessage payload. 
Please take a look at http://activemq.apache.org/objectmessage.html for more information on how to configure trusted classes.

В документах на http://activemq.apache.org/objectmessage.html, есть такой пример:

ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("tcp://localhost:61616");
factory.setTrustAllPackages(true);

Но в моемкод, я использую бин, управляемый сообщениями, вот так:

@MessageDriven(activationConfig = {
    @ActivationConfigProperty(propertyName = "destination", propertyValue = PreloadArquivoRetornoItemSinteticoQueue.JNDI_QUEUE),
    @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
    @ActivationConfigProperty(propertyName = "maxSession", propertyValue = "1"),
    @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge")})
@ResourceAdapter("activemq-rar")
public class PreloadArquivoRetornoItemSinteticoQueue implements MessageListener {

    public static final String JNDI_QUEUE = "java:/jms/preloadArquivoRetornoItemSinteticoQueue";

    @Override
        public void onMessage(final Message message) {
            final ObjectMessage objectMessage = (ObjectMessage) message;

            final ArquivoRetornoDTO arquivoRetornoDTO = (ArquivoRetornoDTO) objectMessage.getObject();
        }
}

Я уже выполнил предложенную конфигурацию в документации для производителей, однако я не знаю, как это сделать для потребителей, так как я не делаюиспользуйте фабрику соединений activemq, но управляемый сообщениями компонент.

Для производителей я добавил следующие переменные среды для экземпляра докера:

JAVA_OPTS: "-Dorg.apache.activemq.SERIALIZABLE_PACKAGES=*"

И можно отправлять сообщения, но неполучить.Итак, где я могу определить управляемый сообщениями setTrustAllPackages=true?

Окружение:

  • Wildfly 15.0.1 Final
  • ActiveMQ5.15.8

Адаптер ресурсов в standalone-full.xml:

        <subsystem xmlns="urn:jboss:domain:resource-adapters:5.0">
            <resource-adapters>
                <resource-adapter id="activemq-rar">
                    <archive>activemq-rar-5.15.8.rar</archive>
                    <transaction-support>XATransaction</transaction-support>
                    <config-property name="UseInboundSession">false</config-property>
                    <config-property name="Password">activemqadmin</config-property>
                    <config-property name="UserName">activemqadmin</config-property>
                    <config-property name="ServerUrl">tcp://activemq:61616</config-property>
                    <connection-definitions>
                        <connection-definition class-name="org.apache.activemq.ra.ActiveMQManagedConnectionFactory" jndi-name="java:/jms/odinConnectionFactory" enabled="true" pool-name="ConnectionFactory">
                            <xa-pool>
                                <min-pool-size>1</min-pool-size>
                                <max-pool-size>20</max-pool-size>
                                <prefill>false</prefill>
                                <is-same-rm-override>false</is-same-rm-override>
                            </xa-pool>
                        </connection-definition>
                    </connection-definitions>
                    <admin-objects>
                        <admin-object class-name="org.apache.activemq.command.ActiveMQQueue" jndi-name="java:/jms/preloadArquivoRetornoItemSinteticoQueue" use-java-context="true" pool-name="PreloadArquivoRetornoItemSinteticoQueue">
                            <config-property name="PhysicalName">jms/preloadArquivoRetornoItemSinteticoQueue</config-property>
                        </admin-object>
                    </admin-objects>
                </resource-adapter>
            </resource-adapters>
        </subsystem>

Исключение:

java.lang.ClassNotFoundException: Forbidden class
foo.bar.ArquivoRetornoDTO! This class is not
trusted to be serialized as ObjectMessage payload. Please take a look at
http://activemq.apache.org/objectmessage.html for more information on how to
configure trusted classes.    at
org.apache.activemq.util.ClassLoadingAwareObjectInputStream.checkSecurity(ClassLoadingAwareObjectInputStream.java:112)    at
org.apache.activemq.util.ClassLoadingAwareObjectInputStream.resolveClass(ClassLoadingAwareObjectInputStream.java:57)    at
java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1868)    at
java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1751)    at
java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2042)    at
java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1573)    at
java.io.ObjectInputStream.readObject(ObjectInputStream.java:431)    at
org.apache.activemq.command.ActiveMQObjectMessage.getObject(ActiveMQObjectMessage.java:211)
[wrapped] javax.jms.JMSException: Failed to build body from content. 
Serializable class not available to broker. Reason:
java.lang.ClassNotFoundException: Forbidden class
foo.bar.ArquivoRetornoDTO! This class is not
trusted to be serialized as ObjectMessage payload. Please take a look at
http://activemq.apache.org/objectmessage.html for more information on how to
configure trusted classes.    at 
org.apache.activemq.util.JMSExceptionSupport.create(JMSExceptionSupport.java:36)    at 
org.apache.activemq.command.ActiveMQObjectMessage.getObject(ActiveMQObjectMessage.java:213)    at
foo.bar.PreloadArquivoRetornoItemSinteticoQueue.onMessage(PreloadArquivoRetornoItemSinteticoQueue.java:61)    at
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)    at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)    at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)…

1 Ответ

0 голосов
/ 16 февраля 2019

После двух изнурительных дней я решил проблему, настроив системное свойство в Singleton:

@Singleton
@Startup
public class InicializadorCargaDadosIniciais implements Serializable {

@PostConstruct
    public void create() {

        System.setProperty("org.apache.activemq.SERIALIZABLE_PACKAGES", "*");
        System.setProperty("org.apache.activemq.artemis.jms.deserialization.whitelist", "*");
}
}
...