8 Replies Latest reply on Feb 20, 2005 7:13 PM by gberish

    DTD to set Entity Bean's JNDI Name?

    gberish

      My question is what deployment descriptor I use to bind a JNDI name to my Entity Beans.

      I am stuck.

      My applicartion deployes with no error messages. I have some Servlets included that all work.

      AND ... deploying my application even creates all the required database tables correctly.

      However, when I pass a Game object to a Servlets doPost () where I want the Servlet to create the GameBean, I cannot find my Bean Objects.

      And when I look in the JNDI list in the console they are not there.

      If anyone is willing to help, here are the sections of the code I think are relevant for one Bean:

      <ejb-jar>
       <enterprise-beans>
       <!-- MemberBean -->
       <entity>
       <description>MemberBean Definition</description>
       <display-name>MemberBean</display-name>
       <small-icon/>
       <large-icon/>
       <ejb-name>MemberEJB</ejb-name>
       <local-home>org.projects.games.go.MemberLocalHome</local-home>
       <local>org.projects.games.go.MemberLocal</local>
       <ejb-class>org.projects.games.go.MemberBean</ejb-class>
       <persistence-type>Container</persistence-type>
       <prim-key-class>java.lang.Integer</prim-key-class>
       <reentrant>False</reentrant>
       <cmp-version>2.x</cmp-version>
       <abstract-schema-name>MemberSchema</abstract-schema-name>
       <cmp-field><field-name>id</field-name></cmp-field>
       .... other fields
       <primkey-field>id</primkey-field>
       <resource-ref>
       <description/>
       <res-ref-name>DefaultDS</res-ref-name>
       <res-type>javax.sql.DataSource</res-type>
       <res-auth>Container</res-auth>
       <res-sharing-scope>Shareable</res-sharing-scope>
       </resource-ref>
       </entity>
      ...
       </enterprise-beans>
      </ejb-jar>
      <jbosscmp-jdbc>
       <enterprise-beans>
       <!-- MemberBean -->
       <entity>
       <ejb-name>MemberEJB</ejb-name>
       <create-table>true</create-table>
       <table-name>plays</table-name>
       <cmp-field>
       <field-name>id</field-name>
       <column-name>id</column-name>
       <not-null/><auto-increment/>
       </cmp-field>
       .... other fields
       <entity-command name="mysql-get-generated-keys"
      class="org.jboss.ejb.plugins.cmp.jdbc.keygen.JDBCMySQLCreateCommand"/>
       </entity>
       ...
       </enterprise-beans>
      </jbosscmp-jdbc>
      <jboss>
       <enterprise-beans>
       <!-- MemberBean -->
       <entity>
       <ejb-name>MemberEJB</ejb-name>
       <local-jndi-name>ejb/MemberLocalHome</local-jndi-name>
       <resource-ref>
       <res-ref-name>DefaultDS</res-ref-name>
       <jndi-name>java:/DefaultDS</jndi-name>
       </resource-ref>
       </entity>
       ...
       <enterprise-beans>
      </jboss>

      The Local Client Method
      void saveCurrentGame() {
       System.out.println ("Saving Game");
       String urlString;
       URL url;
       URLConnection urlConnection;
       HttpURLConnection httpConnection;
       ObjectOutputStream out;
       InputStream in;
       // Local vs. Remote Server
       urlString = "http://localhost:8080/X/servlet/SaveGameServlet";
       System.out.println ("URL: " + urlString);
       try {
       // Configure connection
       url = new URL (urlString);
       urlConnection = url.openConnection ();
       System.out.println("Connection Opened.");
       httpConnection = (HttpURLConnection) urlConnection;
       httpConnection.setRequestMethod ("POST");
       httpConnection.setDoOutput(true);
       httpConnection.setDoInput(true);
       System.out.println("Connection Configured");
       // POST Game
       out = new ObjectOutputStream(httpConnection.getOutputStream ());
       System.out.println("OutputStream Instantiated");
       out.writeObject(model.getGame ());
       out.flush();
       out.close ();
       System.out.println("New Game object POSTed");
       // Get response
       in = (InputStream) httpConnection.getContent ();
       System.out.println("POST returned");
       System.out.println("*****Begining printContent()*****");
       BufferedReader reader =
       new BufferedReader (
       new InputStreamReader (in) );
       while (true) {
       int i = in.read ();
       if (i <0) break;
       System.out.print ((char) i);
       }
       in.close ();
       System.out.println("*****End printContent()*****\n");
       } catch (MalformedURLException me) {
       System.out.println("Malformed URL Exception");
       } catch (ProtocolException pe) {
       System.out.println("Protocal Exception");
       } catch (IOException io) {
       System.out.println("IO Exception");
       }
      
       }

      The Servlet doPost ()
      public void doPost(HttpServletRequest request, HttpServletResponse response)
       throws IOException, ServletException {
      
       response.setContentType("text/html");
       PrintWriter out = response.getWriter();
      
       out.println("Beginning doPost() in UploadGameServlet");
       ObjectInputStream in =
       new ObjectInputStream( request.getInputStream () );
       out.println("Got ObjectInputStream from request");
       Game game = null;
       try {
       game = (Game) in.readObject();
       out.println("Game Object Instantiated");
       } catch (ClassNotFoundException cnf) {
       out.println("Class Not Found Exception");
       } catch (Exception e) {
       out.println("Other Exception");
       }
       in.close ();
       Object ref = null;
       GameLocalHome home = null;
       GameLocal gameBean = null;
       try {
       Context jndiContext = new InitialContext();
       out.println("getInitialContext() returned: "+jndiContext);
      
       // THIS IS WERE IT BRANCHES TO NAMINGEXCEPTION BELOW
      
       ref = jndiContext.lookup("ejb/GameLocalHome");
       out.println("Got jndiContext for GameBean");
       home = (GameLocalHome) ref;
       out.println("Cast ref to home X");
       gameBean = home.create(game);
       out.println("GameBean created");
       } catch (CreateException ce) {
       out.println("Create Exception ");
       } catch (NamingException ne) {
       out.println("Naming Exception");
       }
       out.println("BYE");
       }



        • 1. Re: DTD to set Entity Bean's JNDI Name?

          are u Jndi.properties file for the name server detail and cointext facatry settings, if thet the case then make sure its in the .war file of the serrvlet.

          Otheriwse fisr har code thos in yr servlet codeand test ita nd put jndi.propteries file.

          • 2. Re: DTD to set Entity Bean's JNDI Name?

            Opps!!!, Sorry for the previous posting with typos..
            Are u using Jndi.properties file for the name server details and context factory settings, if that's the case then make sure its in the .war file of the servlet.

            Otherwise first hardcode those in yr servlet code and test it and put it jndi.propteries file.

            private InitialContext getContext() throws NamingException {
             Hashtable props = new Hashtable();
            
             props.put(
             InitialContext.INITIAL_CONTEXT_FACTORY,
             "org.jnp.interfaces.NamingContextFactory");
             props.put(InitialContext.PROVIDER_URL, "jnp://127.0.0.1:1099");
            
             InitialContext initialContext = new InitialContext(props);
             return initialContext;
             }
            


            I hope this hleps.
            Vishal.

            • 3. Re: DTD to set Entity Bean's JNDI Name?
              darranl

              Unfortunately the last two suggestions will not help, the entity beans have only been deployed with local interfaces so you do not want to obtain an initial context using a 'PROVIDER_URL' otherwise you will effectively be accessing JNDI remotely.

              Is your sevlet running as a web application under JBoss or is it running on a different servlet container?

              You say that you can not see your entities when you list the contents of JNDI, have you looked to see if they are bound using a different name - I am not sure of the reasons but other users recently have had problems getting the jboss.xml to be read.

              • 4. Re: DTD to set Entity Bean's JNDI Name?
                gberish

                Thanks, I sort of guessed that was why it still didn't work.

                The servlets are in the same container I think.

                My entire application is deployed in exploded form (the provider of my virtual remote server where I go next has problems with go.ear packaging)

                The Servlets are in $jboss}\...\deploy\go.ear\go-web.war\WEB-INF\lib\svlts.jar.

                I don't know if this helps, but here is the JNDI list I get when the application is deployed.

                java: Namespace
                 +- XAConnectionFactory (class: org.jboss.mq.SpyXAConnectionFactory)
                 +- DefaultDS (class: org.jboss.resource.adapter.jdbc.WrapperDataSource)
                 +- SecurityProxyFactory (class: org.jboss.security.SubjectSecurityProxyFactory)
                 +- GoDS (class: org.jboss.resource.adapter.jdbc.WrapperDataSource)
                 +- DefaultJMSProvider (class: org.jboss.jms.jndi.JNDIProviderAdapter)
                 +- comp (class: javax.naming.Context)
                 +- ConnectionFactory (class: org.jboss.mq.SpyConnectionFactory)
                 +- JmsXA (class: org.jboss.resource.adapter.jms.JmsConnectionFactoryImpl)
                 +- jaas (class: javax.naming.Context)
                 | +- JmsXARealm (class: org.jboss.security.plugins.SecurityDomainContext)
                 | +- jbossmq (class: org.jboss.security.plugins.SecurityDomainContext)
                 +- timedCacheFactory (class: javax.naming.Context)
                Failed to lookup: timedCacheFactory, errmsg=org.jboss.util.TimedCachePolicy
                 +- TransactionPropagationContextExporter (class: org.jboss.tm.TransactionPropagationContextFactory)
                 +- Mail (class: javax.mail.Session)
                 +- StdJMSPool (class: org.jboss.jms.asf.StdServerSessionPoolFactory)
                 +- TransactionPropagationContextImporter (class: org.jboss.tm.TransactionPropagationContextImporter)
                 +- TransactionManager (class: org.jboss.tm.TxManager)
                
                Global JNDI Namespace
                 +- XAConnectionFactory (class: org.jboss.mq.SpyXAConnectionFactory)
                 +- HAILXAConnectionFactory[link -> XAConnectionFactory] (class: javax.naming.LinkRef)
                 +- UIL2ConnectionFactory[link -> ConnectionFactory] (class: javax.naming.LinkRef)
                 +- UserTransactionSessionFactory (proxy: $Proxy13 implements interface org.jboss.tm.usertx.interfaces.UserTransactionSessionFactory)
                 +- HTTPConnectionFactory (class: org.jboss.mq.SpyConnectionFactory)
                 +- HAILConnectionFactory[link -> ConnectionFactory] (class: javax.naming.LinkRef)
                 +- UIL2XAConnectionFactory[link -> XAConnectionFactory] (class: javax.naming.LinkRef)
                 +- console (class: org.jnp.interfaces.NamingContext)
                 | +- PluginManager (proxy: $Proxy27 implements interface org.jboss.console.manager.PluginManagerMBean)
                 +- UUIDKeyGeneratorFactory (class: org.jboss.ejb.plugins.keygenerator.uuid.UUIDKeyGeneratorFactory)
                 +- HTTPXAConnectionFactory (class: org.jboss.mq.SpyXAConnectionFactory)
                 +- topic (class: org.jnp.interfaces.NamingContext)
                 | +- testDurableTopic (class: org.jboss.mq.SpyTopic)
                 | +- testTopic (class: org.jboss.mq.SpyTopic)
                 | +- securedTopic (class: org.jboss.mq.SpyTopic)
                 +- queue (class: org.jnp.interfaces.NamingContext)
                 | +- A (class: org.jboss.mq.SpyQueue)
                 | +- testQueue (class: org.jboss.mq.SpyQueue)
                 | +- ex (class: org.jboss.mq.SpyQueue)
                 | +- DLQ (class: org.jboss.mq.SpyQueue)
                 | +- D (class: org.jboss.mq.SpyQueue)
                 | +- C (class: org.jboss.mq.SpyQueue)
                 | +- B (class: org.jboss.mq.SpyQueue)
                 +- ConnectionFactory (class: org.jboss.mq.SpyConnectionFactory)
                 +- UserTransaction (class: org.jboss.tm.usertx.client.ClientUserTransaction)
                 +- jmx (class: org.jnp.interfaces.NamingContext)
                 | +- invoker (class: org.jnp.interfaces.NamingContext)
                 | | +- RMIAdaptor (proxy: $Proxy26 implements interface org.jboss.jmx.adaptor.rmi.RMIAdaptor,interface org.jboss.jmx.adaptor.rmi.RMIAdaptorExt)
                 | +- rmi (class: org.jnp.interfaces.NamingContext)
                 | | +- RMIAdaptor[link -> jmx/invoker/RMIAdaptor] (class: javax.naming.LinkRef)
                 +- UILXAConnectionFactory[link -> XAConnectionFactory] (class: javax.naming.LinkRef)
                 +- UILConnectionFactory[link -> ConnectionFactory] (class: javax.naming.LinkRef)
                I can see DefaultDS which is the MySql database resource I used.
                I can also see GoDS. That is a resoruce I set up in ${jboss}\...\deploy\mysql-ds.xml, but did not use in my app.
                <?xml version="1.0" encoding="UTF-8"?>
                <!-- $Id: mysql-ds.xml,v 1.1.2.1 2003/12/12 19:19:56 starksm Exp $ -->
                <datasources>
                 <local-tx-datasource>
                 <jndi-name>DefaultDS</jndi-name>
                 <connection-url>jdbc:mysql://localhost:3306/jbossdb</connection-url>
                 <driver-class>com.mysql.jdbc.Driver</driver-class>
                 <user-name></user-name>
                 <password></password>
                 </local-tx-datasource>
                
                 <local-tx-datasource>
                 <jndi-name>GoDS</jndi-name>
                 <connection-url>jdbc:mysql://localhost:3306/go</connection-url>
                 <driver-class>com.mysql.jdbc.Driver</driver-class>
                 <user-name></user-name>
                 <password></password>
                 </local-tx-datasource>
                </datasources>

                But I was expteting to see an "ejb/" sub contex under the Java: Name Space.

                Thanks

                ps: JNDI is the one area that I cannot get a grip on. If any one can suggest a good class on the west coast I'd appreciate it.


                • 5. Re: DTD to set Entity Bean's JNDI Name?
                  darranl

                  Looking back at your first post: -

                  My applicartion deployes with no error messages. I have some Servlets included that all work.


                  Are you getting messages displayed to show that the ejbs are being deployed, it might be worth conventrating on the ejbs for the moment and try deploying the jar that contains them on its own outside the ear.

                  Where is the jar containing the ejbs, is it next to the war folder? Is your ejb jar properly referenced from your application.xml?

                  • 6. Re: DTD to set Entity Bean's JNDI Name?
                    gberish

                    Sorry for not getting back to you sooner, but I was interrupted by the need to renew my Norton Anti-Virus software, and the update trashed my computer.

                    At the moment, I can no longer even get jboss to launch locally.

                    I am guessing that the upgradeed NOrtons is blocking the connection, but am not having any luck getting it uninstalled cleanly, so now I cannot even get a clean start without my project deployed.

                    I hope I can get it resolved soon.

                    In the meantime, in case its of interest, here is the deployed directory and file structure. the 's' prefeace just indicates signed jar file.

                    ${jboss}\server\default\deploy
                     \go.ear
                     sGo-ejb.jar
                     \META-INF
                     application.xml
                     ejb-jar.xml
                     jboss.xml
                     jbosscmp-jdbc.xml
                     \go-web.war
                     index.htm
                     \images
                     \META-INF
                     \resources
                     jboss-j2ee.jar
                     LaunchLocalServer.jnlp
                     properties.Go
                     sGo-jnlp.jar
                     sjboss-j2ee.jar
                     \styles
                     \WEB-INF
                     web.xml
                     \classes
                     \lib
                     go-servlets.jar
                    
                    And here is the error I am getting on starting Jboss.
                    16:46:50,485 INFO [DefaultDS] Bound connection factory for resource adapter for ConnectionManager 'jboss.jca:service=LocalTxCM,name=DefaultDS to JNDI name 'java:/DefaultDS'
                    16:46:51,567 WARN [JBossManagedConnectionPool] Throwable while attempting to get a new connection: null org.jboss.resource.JBossResourceException: Could not create connection; - nested throwable: (java.sql.SQLException: Unable to connect to any hosts due to exception: java.net.ConnectException: Connection refused: connect
                    
                    ** BEGIN NESTED EXCEPTION **
                    
                    java.net.ConnectException
                    MESSAGE: Connection refused: connect
                    
                    STACKTRACE:
                    
                    java.net.ConnectException: Connection refused: connect
                     at java.net.PlainSocketImpl.socketConnect(Native Method)
                     at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)/code]


                    • 7. Re: DTD to set Entity Bean's JNDI Name?
                      sviluppatorefico

                      hi....
                      it's a firewall problem...you'ld to have to see the configuration of your firewall about the 3306 port. If you are under linux you can to do a "netstat -an | grep 3306". If it is no there then it's a firewall problem

                      • 8. Re: DTD to set Entity Bean's JNDI Name?
                        gberish

                        Thanks much.

                        That was exactly it. I allowed Norton's to upgrade my anti-virus protection and it slipped in another fire wall I didn't need. Uninstalling it got me back to my original problem.

                        I get no errors on deploy, but cannot see my enterprise beans in the JNDI list.

                        If anyone is still willing to help, I cleaned up the question and posted it along with the JBoss log output at:
                        http://www.jboss.org/index.html?module=bb&op=viewtopic&t=60424