I need to write a stateless session bean which I want to deploy to WLS 10.3.3. The session bean should be able to send a text message to a known JMS queue which is created through the WLS console. Therefore i wrote the following code:
package com.mycompany.ejb;
import javax.annotation.Resource;
import javax.ejb.*;
import javax.jms.*;
@Stateless
@TransactionManagement(TransactionManagementType.CONTAINER)
public class MyEjb{
@Resource(name = "jmsConnectionFactory")
private ConnectionFactory jmsConnectionFactory;
@Resource(name = "queue1")
private Destination queue1;
public MyEjb(){}
public void sendMsgToQueue(String payload, ConnectionFactory connFactory, Destination destination) throws Exception{
if(payload == null)
throw new IllegalArgumentException("Message payload is null");
if(connFactory == null)
throw new IllegalArgumentException("Connection factory is null");
if(destination == null)
throw new IllegalArgumentException("Message destination is null");
Connection connection = connFactory.createConnection();
Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
MessageProducer messageProducer = session.createProducer(destination);
TextMessage textMessage = session.createTextMessage();
textMessage.setText(payload);
messageProducer.send(textMessage);
}
}
What I need to do now is to provide a valid weblogic-ejb-jar.xml with a resource-ref to jndi-name mapping. Could someone please provide an example for weblogic-ejb-jar.xml with the following mapping:
- jmsConnectionFactory should be bound to a connection factory with jndi-name com.mycompany.jmsXAConnFactory
- queue1 should be bound to a queue with jndi-name com.mycompany.jmsQueue1