GlassFish Server Open Source Edition 3.0.1 (build 22)
NetBeans IDE 6.9 (Build 201006101454)
Java: 1.6.0_21; Java HotSpot(TM) 64-Bit Server VM 17.0-b16
System: Linux version 2.6.32.21-168.fc12.x86_64 running on amd64; UTF-8; en_US (nb)
My code attempts to send a JMS message to the server after an entity object has been updated. When I check the server.log I see the following warning and the message is never posted:
[#|2010-10-01T10:22:53.112+0000|WARNING|glassfish3.0.1|SimpleMessageBean|_ThreadID=17;_ThreadName=Thread-1;|Message of wrong type: com.sun.messaging.jmq.jmsclient.ObjectMessageImpl|#]
I also checked the log in the imqbroker instance but saw nothing to indicate that anything is wrong there.
This is the code I am using to send the message:
public Customer update(Customer customer) {
Customer updated = em.merge(customer);
try
{
sendJMSMessageToNotificationQueue(updated);
}
catch (JMSException ex)
{
Logger.getLogger(CustomerSessionBean.class.getName()).log(Level.SEVERE, null, ex);
}
System.out.println("Customer updated in CustomerSessionBean!");
return updated;
}
private Message createJMSMessageForjmsNotificationQueue(Session session, Object messageData) throws JMSException {
ObjectMessage tm = session.createObjectMessage();
tm.setObject((Serializable)messageData);
return tm;
}
private void sendJMSMessageToNotificationQueue(Object messageData) throws JMSException {
Connection connection = null;
Session session = null;
try {
connection = notificationQueueFactory.createConnection();
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer messageProducer = session.createProducer(notificationQueue);
messageProducer.send(createJMSMessageForjmsNotificationQueue(session, messageData));
} finally {
if (session != null) {
try {
session.close();
} catch (JMSException e) {
Logger.getLogger(this.getClass().getName()).log(Level.WARNING, "Cannot close session", e);
}
}
if (connection != null) {
connection.close();
}
}
}
The Customer entity is defined as follows:
public class Customer implements Serializable {
...
}
And my MDB is defined as follows:
@MessageDriven(mappedName = "jms/NotificationQueue", activationConfig =
{
@ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue")
})
public class NotificationBean implements MessageListener
{
public NotificationBean()
{
}
@Override
public void onMessage(Message message)
{
try
{
Object msgObj = ((ObjectMessage)message).getObject();
if (msgObj != null)
{
Customer customer = (Customer)msgObj;
System.out.println("Customer with the following details has been updated:");
StringBuilder sb = new StringBuilder();
sb.append("Customer ID=");
sb.append(customer.getCustomerId());
sb.append(", ");
sb.append("Name=");
sb.append(customer.getName());
sb.append(", ");
sb.append("Email=");
sb.append(customer.getEmail());
System.out.println(sb.toString());
}
}
catch (JMSException ex)
{
Logger.getLogger(NotificationBean.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
I am new to JMS but not seeing any indication of what may be wrong here (the log warning notwithstanding) I am currently at a loss in solving this problem.
Can anyone offer some suggestions?
Many Thanks.
[Message sent by forum member 'wnorman']
http://forums.java.net/jive/thread.jspa?messageID=484127