0
votes

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
1

1 Answers

0
votes

weblogic-ejb-jar.xml that worked for me:

<?xml version='1.0' encoding='UTF-8'?>
<weblogic-ejb-jar xmlns="http://xmlns.oracle.com/weblogic/weblogic-ejb-jar" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xsi:schemaLocation="http://xmlns.oracle.com/weblogic/weblogic-ejb-jar http://xmlns.oracle.com/weblogic/weblogic-ejb-jar/1.0/weblogic-ejb-jar.xsd ">
    <weblogic-enterprise-bean>
        <ejb-name>MyEjb</ejb-name>
        <stateless-session-descriptor></stateless-session-descriptor>
        <resource-description>
            <res-ref-name>jmsConnectionFactory</res-ref-name>
            <jndi-name>com.mycompany.jmsXAConnFactory</jndi-name>
        </resource-description>
        <resource-env-description>
            <resource-env-ref-name>queue1</resource-env-ref-name>
            <jndi-name>com.mycompany.jmsQueue1</jndi-name>
        </resource-env-description>
    </weblogic-enterprise-bean>
</weblogic-ejb-jar>