users@glassfish.java.net

Re: _at_Resource injection for IBM MQ topic in GF V3

From: Comerford, Sean <Sean.Comerford_at_espn.com>
Date: Thu, 21 Jun 2012 15:00:05 -0400

PS – I think you know this, but the enabled check box in the GUI for both JMS destinations and admin object resources is busted.

It shows as checked even when the underlying XML element clearly has enabled="false" and checking or unchecking the box, while persisted throughout the GUI, does NOT have any effect on the actual domain config.

---
Sean Comerford
ESPN.com Architecture & Platforms
From: Sean Comerford <Sean.Comerford_at_espn.com<mailto:Sean.Comerford_at_espn.com>>
Reply-To: "users_at_glassfish.java.net<mailto:users_at_glassfish.java.net>" <users_at_glassfish.java.net<mailto:users_at_glassfish.java.net>>
Date: Thu, 21 Jun 2012 14:28:15 -0400
To: "users_at_glassfish.java.net<mailto:users_at_glassfish.java.net>" <users_at_glassfish.java.net<mailto:users_at_glassfish.java.net>>
Subject: Re: @Resource injection for IBM MQ topic in GF V3
David,
You are correct – I thought it had been marked disabled b/c something was wrong.
Also, when I tested using the built in Glassfish JMS provider / jmsra, this worked immediately after adding the topic via the GUI console.
But now I realize I was doing it a little differently in the GUI:
If you use Resources -> JMS Resources -> Destination Resources -> New the underlying admin-object-resource is created with no enabled attribute which (as you said) means it IS enabled.
However, if you use Resources -> Connectors -> Admin Object Resources -> New the enabled="false" attribute is added to the underlying admin-object-resource.
Simply removing that fixes the issue independent of the class-name attribute. So while the class-name attar is not required, it's not causing a problem – it's the enabled="false" which seems completely obvious in retrospect :-)
--
Sean Comerford
ESPN.com Site Architecture
From: David Zhao <liang.x.zhao_at_oracle.com<mailto:liang.x.zhao_at_oracle.com>>
Reply-To: "users_at_glassfish.java.net<mailto:users_at_glassfish.java.net>" <users_at_glassfish.java.net<mailto:users_at_glassfish.java.net>>
Date: Thu, 21 Jun 2012 07:59:33 -0400
To: "users_at_glassfish.java.net<mailto:users_at_glassfish.java.net>" <users_at_glassfish.java.net<mailto:users_at_glassfish.java.net>>
Subject: RE: @Resource injection for IBM MQ topic in GF V3
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<mailto: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:
 1.  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)
 2.  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.
 3.  Create a Connector Resource pointing to the connection pool created in step 2.
 4.  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