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

    DTD to set Entity Bean's JNDI Name?

    George Berish Novice

      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:

       <!-- MemberBean -->
       <description>MemberBean Definition</description>
       .... other fields
       <!-- MemberBean -->
       .... other fields
       <entity-command name="mysql-get-generated-keys"
       <!-- MemberBean -->

      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");
       System.out.println("Connection Configured");
       // POST Game
       out = new ObjectOutputStream(httpConnection.getOutputStream ());
       System.out.println("OutputStream Instantiated");
       out.writeObject(model.getGame ());
       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 {
       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);
       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");

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

          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?
            Vishal Sharma Expert

            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.PROVIDER_URL, "jnp://");
             InitialContext initialContext = new InitialContext(props);
             return initialContext;

            I hope this hleps.

            • 3. Re: DTD to set Entity Bean's JNDI Name?
              Darran Lofthouse Master

              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?
                George Berish Novice

                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 2003/12/12 19:19:56 starksm Exp $ -->

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


                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?
                  Darran Lofthouse Master

                  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?
                    George Berish Novice

                    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.

                    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 **
                    MESSAGE: Connection refused: connect
                    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?
                      Luca Stancapiano Expert

                      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?
                        George Berish Novice

                        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: