1 Reply Latest reply on Jun 15, 2004 6:44 AM by jamesstrachan

    jndi lookup/referencing question

    nano_uhe

      Hello,

      I have a Servlet/Applet, which, changes very seldom that I worked on about a year ago and maintain. Usually when I develop the beans that I reference do not change, but in this case my servlet receives data from another bean which is frequently updated by another developer in our organization. A problem that we've been running into, is that every time he updates his bean, my Servlet breaks. All I have to do to fix it is to re-deploy it, so I'm fairly certain that there must be a subtle problem with either the way I'm looking this bean up or with our jboss configuration. I can't find anything written on this, so I'm sure it must be a quirk with our stuff. Does anyone have any ideas about this?

      Here's how I'm doing the lookup in the servlet:
      public void init() throws ServletException
      {
      try
      {
      jndiContext = new InitialContext();
      System.out.println("jndiContext="+jndiContext);
      Object ref = jndiContext.lookup("java:comp/env/ejb/Jdbcnan");
      jdbcboardhome = (JdbcboardHome) PortableRemoteObject.narrow(ref, JdbcboardHome.class);
      jdbcboard = jdbcboardhome.create();
      }
      catch(Exception e)
      {
      e.printStackTrace();
      }
      }


      Here's my web.xml
      <web-app>
      <!-- ### Servlets -->

      <servlet-name>VplAppServlet</servlet-name>
      <servlet-class>cae.VPL.VplAppServlet</servlet-class>

      <servlet-mapping>
      <servlet-name>VplAppServlet</servlet-name>
      <url-pattern>/VplAppServlet</url-pattern>
      </servlet-mapping>
      <welcome-file-list>
      <welcome-file>home.jsp</welcome-file>
      </welcome-file-list>
      <ejb-ref>
      <ejb-ref-name>ejb/Jdbcnan</ejb-ref-name>
      <ejb-ref-type>Session</ejb-ref-type>
      cae.jdbcboard.JdbcboardHome
      cae.jdbcboard.Jdbcboard
      </ejb-ref>

      </web-app>


      And here is my jboss-web.xml:
      <jboss-web>
      <ejb-ref>
      <ejb-ref-name>ejb/Jdbcnan</ejb-ref-name>
      <jndi-name>Jdbcboard</jndi-name>
      </ejb-ref>
      </jboss-web>

      Thank You,

      ~Nano

        • 1. Re: jndi lookup/referencing question
          jamesstrachan

          Nano,

          I have just had to deal with a very similar problem in another application server.

          I would suspect that your home reference, which you get as you initialise the servlet, contains internal information which becomes out of date when your colleague does a hot deploy.

          This will then lead to an error when you try to use the home interface to get the remote interface.

          A suggested cure is to check for exceptions when you access the remote, and to close and reopen the home interface if an error occurs. It would be best to put this in a loop with a retry limit so that it will fail after two or three times if other errors occur.

          See sample code below :-

           while ( remoteFound == false && retryAttempts < retriesLimit ) {
           try {
           // Test for existing home connection. Retry if life expired.
           if ( home == null ) {
           getHome();
           }
           remote = home.create();
           remoteFound = true;
           }
           catch ( Exception e ) {
           fatalException = e;
           home = null;
           retryAttempts++;
           }
           }
          
          


          The variable fatalException will be used to report other errors if the remote could nott be found.

          James