When I try to send Date
object in MapMessage
using JMS on Glassfish 3.1 Open MQ I get the following error:
javax.jms.MessageFormatException: [C4017]: Invalid message format.
Following is the code for how I am trying to send the Date
object in MapMessage
:
public class JSenderMockClient {
public static void main(String[] args) {
try {
//using jndiContext to get ConnectionFactory, Queue, Session and stuff
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = session.createProducer(destination);
MapMessage mapMessage = session.createMapMessage();
mapMessage.setObject("now", new Date());
producer.send(mapMessage);
System.out.println("MapMessage \"now\" sent..");
} catch (Throwable ex) {
//just in case stuff
} finally {
//closing session and connection
}
}
}
Could someone help me understand why am I getting this exception?
Thanks.
I think MapMessage only support Strings and primitives. You could serialize the date to a string, or you could use an ObjectMessage.
To serialize the date, you could use SimpleDateFormat