Bom dia,
Segundo a explicação e no Cast de XML para Objet, foi citado que deve ser implementar o Serializable em Pedido e Item.
Blz....como em outro tópico já tinha citado que não existe mais a versão para download e a mais próxima foi ActiveMq 5.12.2
Mesmo fazendo igual ao vídeo de explicação acusa que precisa Serializar. Desta vez, acho que é no servidor que precisa fazer algo..então, vou postar o ERRO e nele consta um link para avaliar..
http://activemq.apache.org/objectmessage.html
Nele diz que desencoraja o uso de Objetc e assim,tem que deixar explicito o uso. Bom, não consegui resolver ainda, por isso peço ajuda para conclusão do treinamento.
ERRO:
javax.jms.JMSException: Failed to build body from content. Serializable class not available to broker. Reason: java.lang.ClassNotFoundException: Forbidden class br.com.caelum.modelo.Pedido! 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:208) at br.com.caelum.jms.TesteConsumidorTopicoComercial$1.onMessage(TesteConsumidorTopicoComercial.java:46) at org.apache.activemq.ActiveMQMessageConsumer.dispatch(ActiveMQMessageConsumer.java:1385) at org.apache.activemq.ActiveMQSessionExecutor.dispatch(ActiveMQSessionExecutor.java:131) at org.apache.activemq.ActiveMQSessionExecutor.iterate(ActiveMQSessionExecutor.java:202) at org.apache.activemq.thread.PooledTaskRunner.runTask(PooledTaskRunner.java:133) at org.apache.activemq.thread.PooledTaskRunner$1.run(PooledTaskRunner.java:48) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) Caused by: java.lang.ClassNotFoundException: Forbidden class br.com.caelum.modelo.Pedido! 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(Unknown Source) at java.io.ObjectInputStream.readClassDesc(Unknown Source) at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source) at java.io.ObjectInputStream.readObject0(Unknown Source) at java.io.ObjectInputStream.readObject(Unknown Source) at org.apache.activemq.command.ActiveMQObjectMessage.getObject(ActiveMQObjectMessage.java:206) ... 9 more
Classes para conferencia.
public class TesteConsumidorTopicoComercial {
@SuppressWarnings("resource") public static void main(String[] args) throws Exception {
InitialContext context = new InitialContext(); ConnectionFactory factory = (ConnectionFactory) context.lookup("ConnectionFactory");
Connection connection = factory.createConnection(); connection.setClientID("comercial");
connection.start(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Topic topico = (Topic) context.lookup("loja");
MessageConsumer consumer = session.createDurableSubscriber(topico, "assinatura");
consumer.setMessageListener(new MessageListener() {
@Override public void onMessage(Message message) {
ObjectMessage objectMessage = (ObjectMessage) message;
try {
Pedido pedido = (Pedido) objectMessage.getObject(); System.out.println(pedido.getCodigo());
} catch (JMSException e) { e.printStackTrace(); } }
});
new Scanner(System.in).nextLine();
session.close(); connection.close(); context.close(); } }
@SuppressWarnings("resource") public static void main(String[] args) throws Exception {
InitialContext context = new InitialContext(); ConnectionFactory factory = (ConnectionFactory) context.lookup("ConnectionFactory");
Connection connection = factory.createConnection(); connection.start(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Destination topico = (Destination) context.lookup("loja");
MessageProducer producer = session.createProducer(topico);
Pedido pedido = new PedidoFactory().geraPedidoComValores();
Message message = session.createObjectMessage(pedido);
/* StringWriter writer = new StringWriter(); JAXB.marshal(pedido, writer); String xml = writer.toString();
Message message = session.createTextMessage(xml); */
//message.setBooleanProperty("ebook", true); producer.send(message);
session.close(); connection.close(); context.close(); } }
Vou colocar só o inicio do Pedido e Item para ver que tem Serializable
@XmlRootElement @XmlAccessorType(XmlAccessType.FIELD) public class Pedido implements Serializable {
private static final long serialVersionUID = 1L;
private Integer codigo;
... }
@XmlAccessorType(XmlAccessType.FIELD) public class Item implements Serializable{
private static final long serialVersionUID = 1L;