users@glassfish.java.net

RE: _at_Resource injection for IBM MQ topic in GF V3

From: David Zhao <liang.x.zhao_at_oracle.com>
Date: Thu, 21 Jun 2012 04:59:33 -0700 (PDT)

Hi Sean,

 

By looking at the admin-object-resource nodes produced by both gui and asadmin in your domain.xml below, I suspect it may not be caused by the class-name property, but by the enabled property instead. If the admin object is created via asadmin, then there is no enabled property produced, which is true by default. If it is created via gui, then enabled="false" is added although it is displayed Enabled=true in the web page of admin gui. For an admin object which is disabled, maybe it cannot be bind to JNDI when deployment. That could be the reason why injection fails in NameNotFoundException of looking up admin object from JNDI. Could you please retry it by manually removing enabled="false" or changing it to enabled="true" in the admin-object-resource with class-name provided in domain.xml?

 

Thanks,

David Zhao

 

From: Comerford, Sean [mailto:Sean.Comerford_at_espn.com]
Sent: Thursday, June 21, 2012 9:10 AM
To: users_at_glassfish.java.net
Subject: @Resource injection for IBM MQ topic in GF V3

 

This started out as a cry for help but I figured out the answer before completing the email :-)

 

Wanted to send anyway (with answer) for the next guy trying to get @Resource injection of a Websphere MQ topic working on Glassfish V3 using IBM's wmq.jmsra resource adapter.

 

Long story short, do NOT use the admin console to create your topic's Admin Object Resource in V3 even though that worked in V2! V3 console forces the attribute class-name="com.ibm.mq.connector.outbound.MQTopicProxy" on you which results in @Resource injection of said topic not working

 

Simply use asadmin create-admin-object directly so you end up with something like this in your domain.xml:

 

            <admin-object-resource res-adapter="wmq.jmsra-7.0.1.4" res-type="javax.jms.Topic" jndi-name="jms/NBATopic">

                        <property name="baseTopicName" value="SA/NBA"></property>

                        <property name="baseQueueManagerName" value="QM_ESPN_01_DEV"></property>

            </admin-object-resource>

 

If you use the admin console you get something like this - note the class-name attribute which results in the resource injection not working (guessing that IBM class not @Resource compliant?).

 

            <admin-object-resource enabled="false" res-adapter="wmq.jmsra-7.0.1.4" res-type="javax.jms.Topic" description="" jndi-name="jms/NBATopic2"

                                    class-name="com.ibm.mq.connector.outbound.MQTopicProxy">

                        <property name="baseTopicName" value="SA/NBA"></property>

                        <property name="baseQueueManagerName" value="QM_ESPN_01_DEV"></property>

            </admin-object-resource>

 

Here's the long back story / full instructions on how to set up Glassfish to talk to Websphere MQ using the IBM RA:

Install IBM RA far to GF instance (your MQ distro should come with a file named something like wmq.jmsra-7.0.1.4.rar which can be deployed directly)
Create a connector connection pool specifying wmq.jmsra-7.0.1.4 as the resource adapter and javax.jms.TopicConnectionFactory as the definition (seems it has to be TopicConnectionFactory not generic ConnectionFactory). We set "NoTransaction" and then set the following properties: transportType; channel; hostName;, queueManager; port. The connection factory can be pinged successfully in both V2 and V3.
Create a Connector Resource pointing to the connection pool created in step 2.
Create a Connector Admin Object Resource jms/NBATopic of type javax.jms.Topic specifying the wmq.jmsra adapter and the topic + queue manager properties required by the IBM RA. NOTE*: if you try step 4 using the GF V2 admin console, all is good. If you try it using the V3 admin console, you will run into the class-name attribute problem described above and no workey - so use asadmin create-admin-object in V3!!!

Then the code to get the topic and publish to it is pretty simple and looks something like this:

 

    @Resource(mappedName = "jms/SPORTSQMTCF")

    private TopicConnectionFactory connectionFactory;

    

    @Resource(mappedName = "jms/NBATopic")

    private Topic topic;

 

   .

 

    public void send(String msg) throws Exception {

        connection = connectionFactory.createTopicConnection();

        session = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);

        messageProducer = session.createProducer(topic);

        textMessage = session.createTextMessage();

        textMessage.setText(request.getParameter("msgText"));

        messageProducer.send(textMessage);

    }

 

Hope this helps someone :-)

 

-- 
Sean Comerford
ESPN.com Site Architecture