Information
Technologies
Decompiled Java File
package com.acme.anvil.service.jms;
import com.acme.anvil.vo.LogEvent;
import java.util.Properties;
import javax.jms.JMSException;
import javax.jms.ObjectMessage;
import javax.jms.Queue;
import javax.jms.QueueConnection;
import javax.jms.QueueConnectionFactory;
import javax.jms.QueueSender;
import javax.jms.QueueSession;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.apache.log4j.Logger;
import weblogic.transaction.ClientTransactionManager;
import weblogic.transaction.Transaction;
import weblogic.transaction.TransactionHelper;
public class LogEventPublisher {
private static final Logger LOG = Logger.getLogger(LogEventPublisher.class);
private static final String QUEUE_JNDI_NAME = "jms/LogEventQueue";
private static final String QUEUE_FACTORY_JNDI_NAME = "jms/LogEventQueue";
public static void publishLogEvent(LogEvent log) {
ClientTransactionManager ctm = TransactionHelper.getTransactionHelper().getTransactionManager();
Transaction saveTx = null;
try {
saveTx = ctm.forceSuspend();
try {
Context e = getContext();
QueueSession session = getQueueSession(e);
Queue queue = getQueue(e);
QueueSender sender = session.createSender(queue);
ObjectMessage logMsg = session.createObjectMessage(log);
sender.send(logMsg);
} catch (JMSException var12) {
LOG.error("Exception sending message.", var12);
} catch (NamingException var13) {
LOG.error("Exception looking up required resource.", var13);
}
} finally {
ctm.forceResume(saveTx);
}
}
private static Context getContext() throws NamingException {
Properties environment = new Properties();
environment.put("java.naming.factory.initial", "weblogic.jndi.WLInitialContextFactory");
environment.put("java.naming.provider.url", "t3://localhost:7001");
InitialContext context = new InitialContext(environment);
return context;
}
private static Queue getQueue(Context context) throws NamingException {
return (Queue)context.lookup("jms/LogEventQueue");
}
private static QueueSession getQueueSession(Context context) throws JMSException, NamingException {
QueueConnectionFactory cf = (QueueConnectionFactory)context.lookup("jms/LogEventQueue");
QueueConnection connection = cf.createQueueConnection();
return (QueueSession)connection.createSession(false, 1);
}
}