7 Replies Latest reply on Aug 19, 2014 3:49 AM by gagagogo

    How to pass parameters through the deployment descriptor to MDB ?

    gagagogo

      Good day!

      I have a wildfly-8.1.0.CR1, mdb like this:

       

      public class PBX implements MessageListener
      {
       @Resource(name="host")
        private String host;
      
        @Resource(name="port")
        private String port;
      
        @Resource(name="login")
        private String login;
      
        @Resource(name="password")
        private String password;
      
      
      
        @Override
        public void onMessage(Message message) {
        try {
        System.out.println(((TextMessage)message).getText());
        } catch (JMSException e) {
        e.printStackTrace();
        }
      
        }
      
      }
      

      and also, deployment descriptor 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"
      xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
      http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd"
      version="3.0">
        <enterprise-beans>
        <message-driven>
        <ejb-name>PBXE1</ejb-name>
        <ejb-class>org.test.PBX</ejb-class>
        <activation-config>
        <activation-config-property>
        <activation-config-property-name>destination</activation-config-property-name>
        <activation-config-property-value>queues.test.PBX1</activation-config-property-value>
        </activation-config-property>
        <activation-config-property>
        <activation-config-property-name>destinationType</activation-config-property-name>
        <activation-config-property-value>javax.jms.Queue</activation-config-property-value>
        </activation-config-property>
        <activation-config-property>
        <activation-config-property-name>acknowledgeMode</activation-config-property-name>
        <activation-config-property-value>Auto-acknowledge</activation-config-property-value>
        </activation-config-property>
        </activation-config>
        <env-entry>
        <env-entry-name>host</env-entry-name>
        <env-entry-type>java.lang.String</env-entry-type>
        <env-entry-value>127.0.0.1</env-entry-value>
        </env-entry>
        <env-entry>
        <env-entry-name>port</env-entry-name>
        <env-entry-type>java.lang.String</env-entry-type>
        <env-entry-value>22</env-entry-value>
        </env-entry>
        <env-entry>
        <env-entry-name>login</env-entry-name>
        <env-entry-type>java.lang.String</env-entry-type>
        <env-entry-value>user</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>pass</env-entry-value>
        </env-entry>
        </message-driven>
        </enterprise-beans>
      </ejb-jar>
      

       

      And it works. Now I want to add one more instance of this class that listens to another queue, and give him the other connection settings. But only works without the setting <env-entry> twice. Can i pass different values of env-entry for evry instance ?

        • 1. Re: How to pass parameters through the deployment descriptor to MDB ?
          jaikiran

          I don't fully understand the question. Can you post the changes that you did and ran into problems with? That might give me a clue what the question is about.

          • 2. Re: Re: How to pass parameters through the deployment descriptor to MDB ?
            gagagogo

            The bottom line is that I have 2 devices that are equivalent. And each of them must listen to its message queue. So I wrote to them 1 mdb and created 2 instances of it. Each of which listens his queue. And it works. However, now I need to pass "device connection settings" to each instance. To do this, I want to use the property env-entry in the deployment descriptor (ejb-jar.xml). But it does not work. Here is the descriptor:

             

            <?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"
            xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
            http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd"
            version="3.0">
              <enterprise-beans>
              <message-driven>
              <ejb-name>PBXE1</ejb-name>
              <ejb-class>org.test.PBX</ejb-class>
              <activation-config>
              <activation-config-property>
              <activation-config-property-name>destination</activation-config-property-name>
              <activation-config-property-value>queues.test.PBX1</activation-config-property-value>
              </activation-config-property>
              <activation-config-property>
              <activation-config-property-name>destinationType</activation-config-property-name>
              <activation-config-property-value>javax.jms.Queue</activation-config-property-value>
              </activation-config-property>
              <activation-config-property>
              <activation-config-property-name>acknowledgeMode</activation-config-property-name>
              <activation-config-property-value>Auto-acknowledge</activation-config-property-value>
              </activation-config-property>
              </activation-config>
              <env-entry>
              <env-entry-name>host</env-entry-name>
              <env-entry-type>java.lang.String</env-entry-type>
              <env-entry-value>127.0.0.1</env-entry-value>
              </env-entry>
              <env-entry>
              <env-entry-name>port</env-entry-name>
              <env-entry-type>java.lang.String</env-entry-type>
              <env-entry-value>22</env-entry-value>
              </env-entry>
              <env-entry>
              <env-entry-name>login</env-entry-name>
              <env-entry-type>java.lang.String</env-entry-type>
              <env-entry-value>user</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>pass</env-entry-value>
              </env-entry>
              </message-driven>
            
              <message-driven>
              <ejb-name>PBXE2</ejb-name>
              <ejb-class>org.test.PBX</ejb-class>
              <activation-config>
              <activation-config-property>
              <activation-config-property-name>destination</activation-config-property-name>
              <activation-config-property-value>queues.test.PBX2</activation-config-property-value>
              </activation-config-property>
              <activation-config-property>
              <activation-config-property-name>destinationType</activation-config-property-name>
              <activation-config-property-value>javax.jms.Queue</activation-config-property-value>
              </activation-config-property>
              <activation-config-property>
              <activation-config-property-name>acknowledgeMode</activation-config-property-name>
              <activation-config-property-value>Auto-acknowledge</activation-config-property-value>
              </activation-config-property>
              </activation-config>
              <env-entry>
              <env-entry-name>host</env-entry-name>
              <env-entry-type>java.lang.String</env-entry-type>
              <env-entry-value>127.0.0.2</env-entry-value>
              </env-entry>
              <env-entry>
              <env-entry-name>port</env-entry-name>
              <env-entry-type>java.lang.String</env-entry-type>
              <env-entry-value>22</env-entry-value>
              </env-entry>
              <env-entry>
              <env-entry-name>login</env-entry-name>
              <env-entry-type>java.lang.String</env-entry-type>
              <env-entry-value>user</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>pass</env-entry-value>
              </env-entry>
              </message-driven>
            
            
              </enterprise-beans>
            </ejb-jar>
            

             

            Sorry I forgot to attach it in the first post.

            But may be this should to go another way ?

            • 3. Re: How to pass parameters through the deployment descriptor to MDB ?
              jaikiran

              What you have and what you are trying to do is the right way to do it and it should work. When you say it doesn't work, what exactly happens? Is there any code you use to look up those env entries and you are seeing some unexpected value? What does the code look like? Are there any exceptions? What does the entire exception stacktrace look like, if any?

              • 4. Re: How to pass parameters through the deployment descriptor to MDB ?
                jaikiran

                By the way, even though it shouldn't be related to the topic at hand, I would recommend using the latest available 8.1.0.Final release instead of 8.1.0.CR1 http://wildfly.org/downloads/

                1 of 1 people found this helpful
                • 5. Re: How to pass parameters through the deployment descriptor to MDB ?
                  gagagogo

                  Thanks for reply.

                  As i understand that's because every instance try to register variable with the same jndi name. But it's already set. And i don't know how workaround this. This log when i try to deploy:


                  2014-08-15 11:08:10,000 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-3) MSC000001: Failed to start service jboss.deployment.unit."PBXAdapter.war".INSTALL: org.jboss.msc.service.StartException in service jboss.deployment.unit."PBXAdapter.war".INSTALL: JBAS018733: Failed to process phase INSTALL of deployment "PBXAdapter.war"

                    at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:166) [wildfly-server-8.1.0.CR1.jar:8.1.0.CR1]

                    at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1948) [jboss-msc-1.2.2.Final.jar:1.2.2.Final]

                    at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1881) [jboss-msc-1.2.2.Final.jar:1.2.2.Final]

                    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_55]

                    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_55]

                    at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_55]

                  Caused by: java.lang.IllegalArgumentException: JBAS011053: Incompatible conflicting binding at java:comp/env/host source: org.jboss.as.ee.component.EnvEntryInjectionSource@cfc

                    at org.jboss.as.ee.component.deployers.ModuleJndiBindingProcessor.addJndiBinding(ModuleJndiBindingProcessor.java:224)

                    at org.jboss.as.ee.component.deployers.ModuleJndiBindingProcessor.deploy(ModuleJndiBindingProcessor.java:126)

                    at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:159) [wildfly-server-8.1.0.CR1.jar:8.1.0.CR1]

                    ... 5 more

                   

                   

                  2014-08-15 11:08:10,000 ERROR [org.jboss.as.controller.management-operation] (DeploymentScanner-threads - 1) JBAS014613: Operation ("full-replace-deployment") failed - address: ([]) - failure description: {

                      "JBAS014671: Failed services" => {"jboss.deployment.unit.\"PBXAdapter.war\".INSTALL" => "org.jboss.msc.service.StartException in service jboss.deployment.unit.\"PBXAdapter.war\".INSTALL: JBAS018733: Failed to process phase INSTALL of deployment \"PBXAdapter.war\"

                      Caused by: java.lang.IllegalArgumentException: JBAS011053: Incompatible conflicting binding at java:comp/env/host source: org.jboss.as.ee.component.EnvEntryInjectionSource@cfc"},

                      "JBAS014771: Services with missing/unavailable dependencies" => ["jboss.deployment.unit.\"PBXAdapter.war\".weld.weldClassIntrospector is missing [jboss.deployment.unit.\"PBXAdapter.war\".beanmanager]"]

                  }

                  2014-08-15 11:08:10,265 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 1) JBAS018565: Replaced deployment "PBXAdapter.war" with deployment "PBXAdapter.war"

                  2014-08-15 11:08:10,265 INFO  [org.jboss.as.controller] (DeploymentScanner-threads - 1) JBAS014774: Service status report

                  JBAS014777:   Services which failed to start:      service jboss.deployment.unit."PBXAdapter.war".INSTALL

                        service jboss.deployment.unit."PBXAdapter.war".INSTALL: org.jboss.msc.service.StartException in service jboss.deployment.unit."PBXAdapter.war".INSTALL: JBAS018733: Failed to process phase INSTALL of deployment "PBXAdapter.war"

                   


                  • 6. Re: How to pass parameters through the deployment descriptor to MDB ?
                    jaikiran

                    It looks like you are deploying the bean through a war module. The EJB 3.1 spec (section 20.4) explicitly states that you will run into this specific issue since the component namespace is shared for such beans:

                     

                    A .jar file in WEB-INF/lib that contains enterprise beans is not considered an independent Java EE

                    “module” in the way that a .war file, stand-alone ejb-jar file, or an .ear-level ejb-jar file is

                    considered a module. Such a .jar does not define its own module name or its own namespace for

                    ejb-names, environment dependencies, persistence units, etc. All such namespaces are scoped to the

                    enclosing .war file. In that sense, the packaging of enterprise bean classes in a WEB-INF/lib .jar is

                    merely a convenience. It is semantically equivalent to packaging the classes within

                    WEB-INF/classes.

                    ...

                     

                    In a .war file, there is a single component naming environment shared between all the compo-

                    nents(web, enterprise bean, etc.) defined by the module. Each enterprise bean defined by the .war file

                    shares this single component environment namespace with all other enterprise beans defined by the

                    .war file and with all other web components defined by the .war file.

                    ...

                    The Bean Developer should be aware of this name scoping behavior when selecting names of environ-

                    ment dependencies for enterprise beans packaged within a .war file. Unlike enterprise beans packaged

                    in an ejb-jar file outside a .war, names of environment entries defined by an enterprise bean inside

                    a .war can clash with names defined by other components. Likewise, enterprise beans packaged in a

                    .war file have visiblity to all environment entries defined by any other components in the .war file,

                    including any entries defined within web.xml. This is also true of the advanced case that the

                    ejb-jar.xml file is used to define multiple bean components based on the same bean class. Extra

                    caution should be used when configuring environment dependencies for such bean components.

                     

                     

                    You just have to change your packaging to a .ear file (containing .war and a .jar) to get past this.

                    • 7. Re: How to pass parameters through the deployment descriptor to MDB ?
                      gagagogo

                      jaikiran pai you are the great) Thanks! That's resolve my question.