users@glassfish.java.net

Resource Injection in MDB in cluster fails

From: Daniel Cavalcanti <dhcavalcanti_at_gmail.com>
Date: Mon, 27 Aug 2007 14:23:43 -0400

Hi,
I have a MDB inside an EJB project packaged inside an enterprise
application.
I have two MDB with a few environment resources defined inside of
ejb-jar.xml. Both beans use the same implementing class...
Here is the ejb-jar.xml:

<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance" version="3.0"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd">
    <enterprise-beans>
        <message-driven>
            <display-name>InitialDestination_RequestQueue</display-name>
            <ejb-name>InitialDestination_RequestQueue</ejb-name>
            <mapped-name>jms/InitialDestination</mapped-name>
            <ejb-class>com.localmatters.flexiq.collector.router.RouterBean
</ejb-class>
            <messaging-type>javax.jms.MessageListener</messaging-type>
            <transaction-type>Container</transaction-type>
            <activation-config>
                <activation-config-property>

<activation-config-property-name>messageSelector</activation-config-property-name>

<activation-config-property-value>team='collector'</activation-config-property-value>
                </activation-config-property>
            </activation-config>
            <env-entry>
                <env-entry-name>username</env-entry-name>
                <env-entry-type>java.lang.String</env-entry-type>
                <env-entry-value>guest</env-entry-value>
            </env-entry>
            <env-entry>
                <env-entry-name>password</env-entry-name>
                <env-entry-type>java.lang.String</env-entry-type>
                <env-entry-value>guest</env-entry-value>
            </env-entry>
            <env-entry>
                <env-entry-name>outgoing-destination-jndi</env-entry-name>
                <env-entry-type>java.lang.String</env-entry-type>
                <env-entry-value>jms/RequestQueue</env-entry-value>
            </env-entry>
            <env-entry>
                <env-entry-name>persist</env-entry-name>
                <env-entry-type>java.lang.Boolean</env-entry-type>
                <env-entry-value>true</env-entry-value>
            </env-entry>
        </message-driven>
        <message-driven>
            <display-name>InitialDestination_WorkstationQueue</display-name>
            <ejb-name>InitialDestination_WorkstationQueue</ejb-name>
            <mapped-name>jms/InitialDestination</mapped-name>
            <ejb-class>com.localmatters.flexiq.collector.router.RouterBean
</ejb-class>
            <messaging-type>javax.jms.MessageListener</messaging-type>
            <transaction-type>Container</transaction-type>
            <activation-config>
                <activation-config-property>

<activation-config-property-name>messageSelector</activation-config-property-name>

<activation-config-property-value>team='workstation'</activation-config-property-value>
                </activation-config-property>
            </activation-config>
            <env-entry>
                <env-entry-name>username</env-entry-name>
                <env-entry-type>java.lang.String</env-entry-type>
                <env-entry-value>guest</env-entry-value>
            </env-entry>
            <env-entry>
                <env-entry-name>password</env-entry-name>
                <env-entry-type>java.lang.String</env-entry-type>
                <env-entry-value>guest</env-entry-value>
            </env-entry>
            <env-entry>
                <env-entry-name>outgoing-destination-jndi</env-entry-name>
                <env-entry-type>java.lang.String</env-entry-type>
                <env-entry-value>jms/WorkstationQueue</env-entry-value>
            </env-entry>
            <env-entry>
                <env-entry-name>persist</env-entry-name>
                <env-entry-type>java.lang.Boolean</env-entry-type>
                <env-entry-value>true</env-entry-value>
            </env-entry>
        </message-driven>
    </enterprise-beans>
</ejb-jar>

And here is the implementing class (parts ommitted):

/**
 * Entity class RouterBean
 *
 * @author Daniel
 */
public class RouterBean
    implements MessageListener {

    //
**********************************************************************
    // Instance variables
    //
**********************************************************************

    // Logging facility
*****************************************************

    /**
     * The class logger.
     */
    private Log log = LogFactory.getLog(getClass());

    // JMS resources
********************************************************

    @Resource(mappedName="jms/CollectorConnectionFactory")
    private ConnectionFactory connectionFactory;

    @Resource()
    private MessageDrivenContext messageDrivenContext;

    private Connection connection;

    // Injected resources
***************************************************

    @Resource(name="username")
    private String username;

    @Resource(name="password")
    private String password;

    @Resource(name="outgoing-destination-jndi")
    private String outgoingDestinationJndi;

    @Resource(name="persist")
    private boolean persist;

    // Server resources
*****************************************************

    private InitialContext ic;

    //
**********************************************************************
    // Constructors
    //
**********************************************************************

    /**
     * Creates a new instance of RouterBean.
     */
    public RouterBean() {
        log.trace("Creating router bean.");
    }

    //
**********************************************************************
    // Life-cycle methods
    //
**********************************************************************

    /**
     * Initialized the bean.
     */
    @PostConstruct()
    private void init() {

        //
******************************************************************
        // Log initial parameters
        //
******************************************************************

        if (log.isTraceEnabled()) {

            final String endl = System.getProperty("line.separator", "\n");
            StringBuilder buf = new StringBuilder();

            buf.append("Initializing collector router bean.").append(endl);
            buf.append("The following producer parameters
apply:").append(endl);
            buf.append("jms-username..............:
").append(username).append(endl);
            buf.append("persist...................:
").append(persist).append(endl);
            buf.append("outgoing-destination-jndi.:
").append(outgoingDestinationJndi).append(endl);

            log.debug(buf.toString());

        }

        //
******************************************************************
        // Establish JMS connectivity
        //
******************************************************************

       ...

    }

    ...

}


The username, password, outgoingDestinationJndi, and persist resources are
NOT injected.
Here is the relevant log file parts:

[#|2007-08-27T14:08:
32.179-0400|FINEST|sun-appserver9.1|com.localmatters.flexiq.collector.router.RouterBean|_ThreadID=26;_ThreadName=p:
thread-pool-1; w: 18;ClassName=
com.localmatters.flexiq.collector.router.RouterBean;MethodName=<init>;_RequestID=10e65c45-1a33-4b1f-be95-8c755ec9a63c;|Creating
router bean.|#]

[#|2007-08-27T14:08:
32.182-0400|FINE|sun-appserver9.1|com.localmatters.flexiq.collector.router.RouterBean|_ThreadID=26;_ThreadName=p:
thread-pool-1; w: 18;ClassName=
com.localmatters.flexiq.collector.router.RouterBean;MethodName=init;_RequestID=10e65c45-1a33-4b1f-be95-8c755ec9a63c;|Initializing
collector router bean.
The following producer parameters apply:
jms-username..............: null
persist...................: false
outgoing-destination-jndi.: null
|#]

[#|2007-08-27T14:08:
32.182-0400|FINEST|sun-appserver9.1|com.localmatters.flexiq.collector.router.RouterBean|_ThreadID=26;_ThreadName=p:
thread-pool-1; w: 18;ClassName=
com.localmatters.flexiq.collector.router.RouterBean;MethodName=init;_RequestID=10e65c45-1a33-4b1f-be95-8c755ec9a63c;|Getting
server initial context.|#]

[#|2007-08-27T14:08:
32.182-0400|FINEST|sun-appserver9.1|com.localmatters.flexiq.collector.router.RouterBean|_ThreadID=26;_ThreadName=p:
thread-pool-1; w: 18;ClassName=
com.localmatters.flexiq.collector.router.RouterBean;MethodName=init;_RequestID=10e65c45-1a33-4b1f-be95-8c755ec9a63c;|Establishing
connection to JMS broker.|#]

[#|2007-08-27T14:08:
32.183-0400|FINEST|sun-appserver9.1|com.localmatters.flexiq.collector.router.RouterBean|_ThreadID=26;_ThreadName=p:
thread-pool-1; w: 18;ClassName=
com.localmatters.flexiq.collector.router.RouterBean;MethodName=init;_RequestID=10e65c45-1a33-4b1f-be95-8c755ec9a63c;|Collector
router bean started successfully.|#]

Am I missing something or is this a bug?

thanks,
Daniel.