You'll
need to use an ObjectMessasge, not a TextMessage, since the message consists of
a LogEvent object.
-----Original Message-----
From: Peter Cipriano [mailto:[EMAIL PROTECTED]
Sent: Friday, October 24, 2003 8:31 AM
To: [EMAIL PROTECTED]
Subject: JMSAppender and the onMessage Impl
I have a working log4j configuration for the File Appenders. With a bit of help from this newsgroup I got the most of the JMSAppender working using Websphere 5 with a MDB. log4j is moving the data to the Websphere embedded Queue (Topic) however when the onMessage impl of my MDB tried to convert the sent log4j message passed in I get a Class cast exception.
The weird thing is if I use a straight topic call it works fine:
String msg = "Test Message";
topicPublisher.publish(msg);
Here is a code snipet. I have looked at other posts and have seen this type of usage. Not sure why I am different here
public void onMessage(javax.jms.Message message) {
try{
...
// Class Cast exception on the following line only from log4j
TextMessage textMessage = null;
textMessage = (TextMessage)message;
if(printStream==null){
setPrintStream(getLogFileName());
}
String msg = textMessage.getText();
if (!msg.equals("")){
printStream.println(msg);
printStream.flush();
}
}catch(JMSException e){
...
System.out.println(e.getLocalizedMessage());
}
}
# Log4j Properties
#------------------
log4j.rootLogger= DEBUG, JMS1
log4j.appender.JMS1 = org.apache.log4j.net.JMSAppender
log4j.appender.JMS1.TopicBindingName = jms/ESMTOPIC
log4j.appender.JMS1.TopicConnectionFactoryBindingName = jms/ESMTCF
log4j.appender.JMS1.layout = org.apache.log4j.PatternLayout
log4j.appender.JMS1.layout.ConversionPattern = [%-20d{M/d/yy HH:mm:ss.sss z}] %-25t:%-5p %-30c - %m%n
Right now I commented out the TestMessage lines and just log the actual object. I have to at least prove to the powers at be I am logging something.
MS Message class: jms_object
JMSType: null
JMSDeliveryMode: 2
JMSExpiration: 0
JMSPriority: 4
JMSMessageID: ID:414d51205741535f6c6f63616c686f737e43993f20000a01
JMSTimestamp: 1067008958020
JMSCorrelationID:ID:414d51205741535f6c6f63616c686f737e43993f20000804
JMSDestination: topic://MYTOPIC?brokerVersion=1
JMSReplyTo: null
JMSRedelivered: false
JMS_IBM_PutDate:20031024
JMSXAppID:WAS_localhost_server1
JMS_IBM_Format:
JMS_IBM_PutApplType:26
JMS_IBM_MsgType:8
JMSXUserID:Administrato
JMS_IBM_PutTime:15223814
JMSXDeliveryCount:1
class org.apache.log4j.spi.LoggingEvent
JMS Message class: jms_object
JMSType: null
JMSDeliveryMode: 2
JMSExpiration: 0
JMSPriority: 4
JMSMessageID: ID:414d51205741535f6c6f63616c686f737e43993f20000a03
JMSTimestamp: 1067008958200
JMSCorrelationID:ID:414d51205741535f6c6f63616c686f737e43993f20000804
JMSDestination: topic://MYTOPIC?brokerVersion=1
JMSReplyTo: null
JMSRedelivered: false
JMS_IBM_PutDate:20031024
JMSXAppID:WAS_localhost_server1
JMS_IBM_Format:
JMS_IBM_PutApplType:26
JMS_IBM_MsgType:8
JMSXUserID:Administrato
JMS_IBM_PutTime:15223821
JMSXDeliveryCount:1
class org.apache.log4j.spi.LoggingEvent
Regards,
Peter Cipriano
Staff Software Engineer