8 Replies Latest reply on Aug 2, 2007 2:47 AM by aroppone

    EJBs and XML-RPCs

    aroppone

      Hi,

      I'm very new to JBoss and EJBs, but I've task to make EJB that connects to eXist XML database via XML-RPC (don't know if it is the best way). The problem is that I wouldn't like to hard code the URL. Is there a way to give EJBs initialization parameters like in web apps (web.xml)?

        • 1. Re: EJBs and XML-RPCs
          ejb3workshop

          I suggest you take a look at chapter 16 in the Final EJB3 Specification. (ejb-3_0-fr-spec-ejbcore.pdf)

          <enterprise-beans>
          <session>
          ...
          <ejb-name>EmployeeService</ejb-name>
          <ejb-class>com.wombat.empl.EmployeeServiceBean</ejb-class>
          ...
          <env-entry>
          <description>
          The maximum number of tax exemptions
          allowed to be set.
          </description>
          <env-entry-name>maxExemptions</env-entry-name>
          <env-entry-type>java.lang.Integer</env-entry-type>
          <env-entry-value>15</env-entry-value>
          </env-entry>
          <env-entry>
          <description>
          The minimum number of tax exemptions
          allowed to be set.
          </description>
          <env-entry-name>minExemptions</env-entry-name>
          <env-entry-type>java.lang.Integer</env-entry-type>
          <env-entry-value>1</env-entry-value>
          </env-entry>
          <env-entry>
          <env-entry-name>foo/name1</env-entry-name>
          <env-entry-type>java.lang.String</env-entry-type>
          <env-entry-value>value1</env-entry-value>
          </env-entry>
          <env-entry>
          <env-entry-name>foo/bar/name2</env-entry-name>
          <env-entry-type>java.lang.Boolean</env-entry-type>
          <env-entry-value>true</env-entry-value>
          </env-entry>
          <env-entry>
          <description>Some description.</description>
          <env-entry-name>name3</env-entry-name>
          <env-entry-type>java.lang.Integer</env-entry-type>
          </env-entry>
          <env-entry>
          <env-entry-name>foo/name4</env-entry-name>
          <env-entry-type>java.lang.Integer</env-entry-type>
          <env-entry-value>10</env-entry-value>
          </env-entry>
          ...
          </session>
          </enterprise-beans>
          


          and then access it as

          // Obtain the enterprise bean?s environment naming context.
          Context initCtx = new InitialContext();
          Context myEnv = (Context)initCtx.lookup("java:comp/env");
          // Obtain the maximum number of tax exemptions
          // configured by the Deployer.
          Integer maxExemptions =
          (Integer)myEnv.lookup(?maxExemptions?);
          // Obtain the minimum number of tax exemptions
          // configured by the Deployer.
          Integer minExemptions =
          (Integer)myEnv.lookup(?minExemptions?);
          // Use the environment entries to customize business logic.
          if (numberOfExeptions > maxExemptions ||
          numberOfExemptions < minExemptions)
          throw new InvalidNumberOfExemptionsException();
          // Get some more environment entries. These environment
          // entries are stored in subcontexts.
          String val1 = (String)myEnv.lookup(?foo/name1?);
          Boolean val2 = (Boolean)myEnv.lookup(?foo/bar/name2?);
          // The enterprise bean can also lookup using full pathnames.
          Integer val3 = (Integer)
          initCtx.lookup("java:comp/env/name3");
          Integer val4 = (Integer)
          initCtx.lookup("java:comp/env/foo/name4");
          


          Hope this helps
          Alex

          • 2. Environment variable in EJB3 (was EJBs and XML-RPCs)
            ejb3workshop

            Changed the title of the message.

            • 3. Re: EJBs and XML-RPCs
              aroppone

              Thanks for your answer. I noticed this feature, but as I'm working with Netbeans 5.5 IDE I somehow can't get that ejb-jar.xml configured. Have you worked with NB 5.5 and could you give me some tips? As I looked the JBoss samples from NB update center I noticed that they don't use ejb-jar.xml either, EJBs are looked like 'pacakge/bean/local'.

              • 4. Re: EJBs and XML-RPCs
                ejb3workshop

                I am using NB5.5, but we assemble the JAR using our own ANT script. Have a look if there is an ejb-jar.xml file in the constructed JAR file. If there is then you could look in the Files tab and might find it.

                • 5. Re: EJBs and XML-RPCs
                  aroppone

                  I've search the jar and all the files but there is no ejb-jar.xml. I read somewhere that EJB3s don't need deployment descriptors, I this totally false statement? I also tried to create own dep.desc. and configure manually, but as my EJB looks for the env-entry that I created it throws exception stating valueY not bound.

                  The ejb-jar.xml is like this:

                  <?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>
                   <session>
                   <ejb-name>processExistBean</ejb-name>
                   <local>org.eamssi.ejb.ProcessExistLocal</local>
                   <ejb-class>testing.ProcessExistBean</ejb-class>
                   <session-type>Stateless</session-type>
                   <transaction-type>Bean</transaction-type>
                   <env-entry>
                   <description>
                   The URI of eXist XML-RPC.
                   </description>
                   <env-entry-name>existUri</env-entry-name>
                   <env-entry-type>java.lang.String</env-entry-type>
                   <env-entry-value>xmldb:exist://localhost:8080/exist/xmlrpc</env-entry-value>
                   </env-entry>
                   </session>
                   </enterprise-beans>
                  </ejb-jar>


                  Is this totally incorrect? I used:
                  Context initCtx = new InitialContext();
                   String uri = (String)initCtx.lookup("existUri");


                  to get the env-entry value (and also with "java:comp/env/existUri").

                  • 6. Re: EJBs and XML-RPCs
                    ejb3workshop

                    EJB3 does not need a deployment descriptor to work, but certain aspects are still configurable via a deployment descriptor. After you deployed the JAR containing the ejb-jar.xml file you can look in the JNDI List within the JMX console to browse the JNDI tree.

                    • 7. Re: EJBs and XML-RPCs
                      waynebaylor

                      I have not tried using an explicit JNDI lookup for env-entries, but I have has success using:

                      @Resource(name="existsUri")
                      String uri;
                      



                      • 8. Re: EJBs and XML-RPCs
                        aroppone

                        I checked everything JNDI related but can't find out if the correct value nor the other values stated in the dep.desc. above. I quess that the problem is the way NB deploys the EJBs. any ideas how to solve that?