Red Hat Application Migration Toolkit
package com.redhat.sample.config; import com.redhat.sample.consumer.SampleConsumer; import java.util.Hashtable; import java.util.logging.Logger; import javax.jms.Destination; import javax.jms.JMSException; import javax.jms.Queue; import javax.jms.QueueConnection; import javax.jms.QueueConnectionFactory; import javax.jms.QueueSession; import javax.naming.InitialContext; import javax.naming.NamingException; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.jms.annotation.EnableJms; import org.springframework.jms.core.JmsTemplate; import org.springframework.jms.listener.DefaultMessageListenerContainer; import org.springframework.jms.listener.MessageListenerContainer; import org.springframework.web.servlet.config.annotation.EnableWebMvc; import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; @EnableWebMvc @EnableJms @Configuration @ComponentScan({"com.redhat.sample"}) public class SpringConfig extends WebMvcConfigurerAdapter { private static final Logger LOG = Logger.getLogger(SpringConfig.class.getName()); private static final String ICF_NAME = "weblogic.jndi.WLInitialContextFactory"; private static final String CF_NAME = "weblogic.examples.ejb30.QueueConnectionFactory"; private String jmsBrokerUrl = "t3://localhost:7001"; private String queueName = "weblogic.examples.ejb30.ExampleQueue"; private InitialContext ctx; private QueueConnectionFactory qcf = null; private QueueConnection qc = null; private QueueSession session = null; private Queue dest = null; @Bean public QueueConnectionFactory connectionFactory() { Hashtable<String, String> props = new Hashtable(); props.put("java.naming.factory.initial", "weblogic.jndi.WLInitialContextFactory"); props.put("java.naming.provider.url", this.jmsBrokerUrl); try { this.ctx = new InitialContext(props); LOG.severe("Got InitialContext " + this.ctx.toString()); this.qcf = (QueueConnectionFactory)this.ctx.lookup("weblogic.examples.ejb30.QueueConnectionFactory"); LOG.severe("Got QueueConnectionFactory " + this.qcf); this.dest = (Queue)this.ctx.lookup(this.queueName); LOG.severe("Queue-Impl_Class: " + this.dest.getClass().getName()); this.qc = this.qcf.createQueueConnection(); LOG.severe("Got QueueConnection " + this.qc); this.session = this.qc.createQueueSession(false, 1); LOG.severe("Got QueueSession " + this.session); } catch (NamingException | JMSException var3) { LOG.severe("JMS initialization error: " + var3.getMessage()); LOG.severe("JMS initialization error in session" + var3); } return this.qcf; } @Bean public JmsTemplate jmsTemplate() { JmsTemplate jmsTemplate = new JmsTemplate(); jmsTemplate.setConnectionFactory(this.connectionFactory()); jmsTemplate.setDefaultDestination(this.defaultDestination()); return jmsTemplate; } @Bean public MessageListenerContainer msgListenerContainer() { DefaultMessageListenerContainer msgListenerContainer = new DefaultMessageListenerContainer(); msgListenerContainer.setConnectionFactory(this.connectionFactory()); msgListenerContainer.setDestination(this.defaultDestination()); msgListenerContainer.setMessageListener(new SampleConsumer()); return msgListenerContainer; } @Bean public Destination defaultDestination() { return this.dest; } }