glassfish
  1. glassfish
  2. GLASSFISH-8614

[DEA] message driven bean resource values not being set correctly

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Duplicate
    • Affects Version/s: v2.1.1
    • Fix Version/s: V3
    • Component/s: ejb_container
    • Labels:
      None
    • Environment:

      Operating System: All
      Platform: All

    • Issuezilla Id:
      8,614

      Description

      [DEA] Logging the bug on behalf of the customer
      --------------------------------------------------------------
      we have an EJB class from which we want to have two instances with different
      variables. The variable values are defined in the deployment descriptor of the
      bean with env-entry. If we let the container inject the variable values, some of
      them are initialized with null values which is not what we were expecting.

      Attached the netbeans project which showcase the issue.

      Expected Result:-
      testing.ejbeans.testmultipleejbs.TestMDB@f29c65.postConstruct(): someEnv = aString
      testing.ejbeans.testmultipleejbs.TestMDB@10277cd.postConstruct(): someEnv = aString2
      testing.ejbeans.testmultipleejbs.TestMDB@10277cd.onMessage(): someEnv =
      aString2, message = this is
      another test
      testing.ejbeans.testmultipleejbs.TestMDB@f29c65.onMessage(): someEnv = aString,
      message = this is a test

      Actual Result:-
      testing.ejbeans.testmultipleejbs.TestMDB@f29c65.postConstruct(): someEnv = aString
      testing.ejbeans.testmultipleejbs.TestMDB@10277cd.onMessage(): someEnv = null,
      message = this is
      another test
      testing.ejbeans.testmultipleejbs.TestMDB@f29c65.onMessage(): someEnv = aString,
      message = this is a test

      Obviously, the message is sent to the correct MDB instance, but the second
      instance does not pickup the configured env setting ("aString2").

      code: ejb-jar.xml
      ----------------

      <?xml version="1.0" encoding="UTF-8"?>

      <ejb-jar xmlns = "http://java.sun.com/xml/ns/javaee"
      version = "3.0"
      xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
      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>
      <ejb-name>TestMDB</ejb-name>
      <mapped-name>queue/TestMDB</mapped-name>
      <ejb-class>testing.ejbeans.testmultipleejbs.TestMDB</ejb-class>
      <transaction-type>Container</transaction-type>
      <env-entry>
      <description>Some environment variable.</description>
      <env-entry-name>someEnv</env-entry-name>
      <env-entry-type>java.lang.String</env-entry-type>
      <env-entry-value>aString</env-entry-value>
      <!--
      <injection-target>

      <injection-target-class>testing.ejbeans.testmultipleejbs.TestMDB</injection-target-class>
      <injection-target-name>someEnv</injection-target-name>
      </injection-target>
      -->
      </env-entry>
      </message-driven>
      <message-driven>
      <ejb-name>TestMDB2</ejb-name>
      <mapped-name>queue/TestMDB2</mapped-name>
      <ejb-class>testing.ejbeans.testmultipleejbs.TestMDB</ejb-class>
      <transaction-type>Container</transaction-type>
      <env-entry>
      <description>Some environment variable.</description>
      <env-entry-name>someEnv</env-entry-name>
      <env-entry-type>java.lang.String</env-entry-type>
      <env-entry-value>aString2</env-entry-value>
      <!--
      <injection-target>

      <injection-target-class>testing.ejbeans.testmultipleejbs.TestMDB2</injection-target-class>
      <injection-target-name>someEnv</injection-target-name>
      </injection-target>
      -->
      </env-entry>
      </message-driven>
      </enterprise-beans>
      </ejb-jar>

      UnitTest
      ----------------

      package testing.ejbeans.testmultipleejbs;

      import javax.jms.Connection;

      public class UnitTest_TestMDB
      extends TestCase {

      public UnitTest_TestMDB( String name ) {
      super( name );
      }

      public void testTestMDB()
      throws Exception {

      Hashtable env = new Hashtable();
      env.put(Context.INITIAL_CONTEXT_FACTORY,
      "com.sun.enterprise.naming.SerialInitContextFactory");
      env.put(Context.PROVIDER_URL,
      "localhost:1099");

      InitialContext context = new InitialContext(env);
      QueueConnectionFactory cf = (QueueConnectionFactory)
      context.lookup("jms/QueueConnectionFactory");
      Connection conn = cf.createConnection();
      Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);

      Queue queue = (Queue) context.lookup("jms/TestMDB");
      MessageProducer mp = session.createProducer(queue);
      mp.send(session.createTextMessage("this is a test"));

      Queue queue2 = (Queue) context.lookup("jms/TestMDB2");
      MessageProducer mp2 = session.createProducer(queue2);
      mp2.send(session.createTextMessage("this is another test"));
      }
      }

      EJB
      --------

      package testing.ejbeans.testmultipleejbs;

      import javax.annotation.PostConstruct;

      @MessageDriven(mappedName = "queue/TestMDB", activationConfig = {
      @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue =
      "Auto-acknowledge"),
      @ActivationConfigProperty(propertyName = "destinationType", propertyValue =
      "javax.jms.Queue")
      })
      public class TestMDB implements MessageListener {

      @Resource(name = "someEnv")
      public String someEnv;

      @PostConstruct
      public void postConstruct() {
      // InitialContext ctx;
      // try

      { // ctx = new InitialContext(); // someEnv = (String)ctx.lookup( "java:comp/env/someEnv" ); // }

      catch (NamingException ex)

      { // Logger.getLogger(TestMDB.class.getName()).log(Level.SEVERE, null, ex); // }

      System.out.println("\nStatement1:- someEnv = " + someEnv+"\n");
      }

      public

      TestMDB() {
      }

      @Override
      public void onMessage(Message message) {
      try

      { System.out.println("\n" + this.toString() + ".onMessage(): someEnv = " + someEnv + ", message = " + ((TextMessage) message).getText() + "\n"); }

      catch (JMSException e)

      { e.printStackTrace(); }

      }
      }

        Activity

        Hide
        vamsee_krishna added a comment -

        Created an attachment (id=2940)
        Netbeans project showcasing the issue

        Show
        vamsee_krishna added a comment - Created an attachment (id=2940) Netbeans project showcasing the issue
        Hide
        jthoennes added a comment -

        This looks being related to this issue:

        https://glassfish.dev.java.net/issues/show_bug.cgi?id=6653

        Perhaps the fix is similar.

        Could this please be included into GF v2.1.1?

        Thanks, Jörg

        Show
        jthoennes added a comment - This looks being related to this issue: https://glassfish.dev.java.net/issues/show_bug.cgi?id=6653 Perhaps the fix is similar. Could this please be included into GF v2.1.1? Thanks, Jörg
        Hide
        ksak added a comment -

        Duplicate of 6653.

            • This issue has been marked as a duplicate of 6653 ***
        Show
        ksak added a comment - Duplicate of 6653. This issue has been marked as a duplicate of 6653 ***

          People

          • Assignee:
            ksak
            Reporter:
            vamsee_krishna
          • Votes:
            3 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: