glassfish
  1. glassfish
  2. GLASSFISH-525

Error reporting when the DB is not running, and need to restart the app server...

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 9.0pe
    • Fix Version/s: 9.1pe
    • Component/s: jdbc
    • Labels:
      None
    • Environment:

      Operating System: All
      Platform: All

    • Issuezilla Id:
      525
    • Status Whiteboard:
      Hide

      fixed-9.0peur1

      Show
      fixed-9.0peur1

      Description

      A very common use case if when the app server is running, but the necessary
      database engine is not.

      I have some JPA in web apps created with latest Nb5.5 and the JSF managed beans
      controller to read, delete, update, create these entities.

      When the db is not running, the error I have in the log and JSF view page is:
      type Exception report

      message

      description The server encountered an internal error () that prevented it from
      fulfilling this request.

      exception

      javax.servlet.ServletException
      javax.faces.webapp.FacesServlet.service(FacesServlet.java:256)
      com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:73)
      com.sun.enterprise.web.VirtualServerPipeline.invoke(VirtualServerPipeline.java:120)
      org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:231)
      com.sun.enterprise.web.connector.grizzly.ProcessorTask.invokeAdapter(ProcessorTask.java:667)
      com.sun.enterprise.web.connector.grizzly.ProcessorTask.processNonBlocked(ProcessorTask.java:574)
      com.sun.enterprise.web.connector.grizzly.ProcessorTask.process(ProcessorTask.java:844)
      com.sun.enterprise.web.connector.grizzly.ReadTask.executeProcessorTask(ReadTask.java:287)
      com.sun.enterprise.web.connector.grizzly.ReadTask.doTask(ReadTask.java:212)
      com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:252)
      com.sun.enterprise.web.connector.grizzly.WorkerThread.run(WorkerThread.java:75)

      root cause

      java.lang.NullPointerException
      com.sun.enterprise.util.EntityManagerWrapper.createQuery(EntityManagerWrapper.java:525)
      foo.ManufactureController.getManufactures(ManufactureController.java:95)
      sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      java.lang.reflect.Method.invoke(Method.java:585)
      javax.el.BeanELResolver.getValue(BeanELResolver.java:273)
      javax.el.CompositeELResolver.getValue(CompositeELResolver.java:143)
      com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:58)
      com.sun.el.parser.AstValue.getValue(AstValue.java:117)
      com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:192)
      javax.faces.component.UIData.getValue(UIData.java:577)
      javax.faces.component.UIData.getDataModel(UIData.java:1056)
      javax.faces.component.UIData.setRowIndex(UIData.java:417)
      com.sun.faces.renderkit.html_basic.TableRenderer.encodeBegin(TableRenderer.java:82)
      javax.faces.component.UIComponentBase.encodeBegin(UIComponentBase.java:809)
      javax.faces.component.UIData.encodeBegin(UIData.java:873)
      javax.faces.component.UIComponent.encodeAll(UIComponent.java:881)
      javax.faces.render.Renderer.encodeChildren(Renderer.java:137)
      javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:827)
      javax.faces.component.UIComponent.encodeAll(UIComponent.java:883)
      javax.faces.component.UIComponent.encodeAll(UIComponent.java:889)
      com.sun.faces.application.ViewHandlerImpl.doRenderView(ViewHandlerImpl.java:258)
      com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:176)
      com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:108)
      com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:266)
      com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:159)
      javax.faces.webapp.FacesServlet.service(FacesServlet.java:245)
      com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:73)
      com.sun.enterprise.web.VirtualServerPipeline.invoke(VirtualServerPipeline.java:120)
      org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:231)
      com.sun.enterprise.web.connector.grizzly.ProcessorTask.invokeAdapter(ProcessorTask.java:667)
      com.sun.enterprise.web.connector.grizzly.ProcessorTask.processNonBlocked(ProcessorTask.java:574)
      com.sun.enterprise.web.connector.grizzly.ProcessorTask.process(ProcessorTask.java:844)
      com.sun.enterprise.web.connector.grizzly.ReadTask.executeProcessorTask(ReadTask.java:287)
      com.sun.enterprise.web.connector.grizzly.ReadTask.doTask(ReadTask.java:212)
      com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:252)
      com.sun.enterprise.web.connector.grizzly.WorkerThread.run(WorkerThread.java:75)

      note The full stack trace of the root cause is available in the Sun Java System
      Application Server Platform Edition 9.0 RC logs.
      Sun Java System Application Server Platform Edition 9.0 RC

      So we emit a cryptic java.lang.NullPointerException when a DB is not running...

      What is even more bizarre is after looking a ther server log for other cryptic
      entries like:
      RAR5038:Unexpected exception while creating resource
      RAR5117 : Failed to obtain/create connection. Reason : Connection could not be
      allocated because: java.security.PrivilegedActionException : Error opening
      socket to server localhost on port 1527 with message : null
      RAR5114 : Error allocating connection : [Error in allocating a connection.
      Cause: Connection could not be allocated because:
      java.security.PrivilegedActionException : Error opening socket to server
      localhost on port 1527 with message : null]

      Internal Exception: java.sql.SQLException: Error in allocating a connection.
      Cause: Connection could not be allocated because:
      java.security.PrivilegedActionException : Error opening socket to server
      localhost on port 1527 with message : nullError Code: 0
      Local Exception Stack:
      Exception [TOPLINK-4002] (Oracle TopLink Essentials - 2006.3 (Build 060327)):
      oracle.toplink.essentials.exceptions.DatabaseException
      Internal Exception: java.sql.SQLException: Error in allocating a connection.
      Cause: Connection could not be allocated because:
      java.security.PrivilegedActionException : Error opening socket to server
      localhost on port 1527 with message : nullError Code: 0
      at
      oracle.toplink.essentials.exceptions.DatabaseException.sqlException(DatabaseException.java:289)
      at
      oracle.toplink.essentials.jndi.JNDIConnector.connect(JNDIConnector.java:135)
      at
      oracle.toplink.essentials.sessions.DatasourceLogin.connectToDatasource(DatasourceLogin.java:167)

      I realize the DB is not started, I then start it. I would expect that a Page
      reload of my Web App would work... It seems it does not and I need to restart
      the Application Server itself in my case...

      The controler class is like this:

      package foo;
      import java.util.Collection;
      import javax.annotation.Resource;
      import javax.faces.application.FacesMessage;
      import javax.faces.context.ExternalContext;
      import javax.faces.context.FacesContext;
      import javax.persistence.EntityManager;
      import javax.persistence.PersistenceContext;
      import javax.servlet.http.HttpServletRequest;
      import javax.transaction.UserTransaction;

      public class ManufactureController {

      private Manufacture manufacture;

      @Resource
      private UserTransaction utx;

      @PersistenceContext(unitName = "WebApplication21")
      private EntityManager em;

      public String createSetup()

      { this.manufacture = new Manufacture(); return "manufacture_create"; }

      public String create() {
      try

      { utx.begin(); em.persist(manufacture); utx.commit(); }

      catch (Exception ex) {
      try

      { utx.rollback(); } catch (Exception e) {}
      }
      addMessage("Manufacture was successfully created.");
      return "manufacture_list";
      }

      public String detailSetup() { setManufactureFromRequestParam(); return "manufacture_detail"; }

      public String editSetup() { setManufactureFromRequestParam(); return "manufacture_edit"; }

      public String edit() {
      try { utx.begin(); manufacture = em.merge(manufacture); utx.commit(); addMessage("Manufacture was successfully updated."); } catch (Exception ex) {
      try { utx.rollback(); }

      catch (Exception e) {}
      }
      return "manufacture_list";
      }

      public String destroy() {
      try

      { utx.begin(); Manufacture manufacture = getManufactureFromRequestParam(); manufacture = em.merge(manufacture); em.remove(manufacture); utx.commit(); addMessage("Manufacture was successfully deleted."); }

      catch (Exception ex) {
      try

      { utx.rollback(); }

      catch (Exception e) {}
      }
      return "manufacture_list";
      }

      public Manufacture getManufactureFromRequestParam()

      { ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext(); HttpServletRequest request = (HttpServletRequest)ec.getRequest(); String param = request.getParameter("manufactureId"); Integer id = new Integer(param); return em.find(Manufacture.class, id); }

      public void setManufactureFromRequestParam()

      { Manufacture manufacture = getManufactureFromRequestParam(); setManufacture(manufacture); }

      public Collection getManufactures()

      { return em.createQuery("select object(o) from Manufacture as o").getResultList(); }

      public Manufacture getManufacture()

      { return manufacture; }

      public void setManufacture(Manufacture manufacture)

      { this.manufacture = manufacture; }

      public static void addMessage(String msg)

      { FacesMessage facesMsg = new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, msg); FacesContext fc = FacesContext.getCurrentInstance(); fc.addMessage(null, facesMsg); }

      public Manufacture findManufacture(Integer id)

      { return (Manufacture) em.find(Manufacture.class, id); }

      }

      my pu is
      <?xml version="1.0" encoding="UTF-8"?>
      <persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence">
      <persistence-unit name="WebApplication21" transaction-type="JTA">
      <jta-data-source>jdbc/ludods</jta-data-source>
      <properties/>
      </persistence-unit>
      </persistence>

      and the ds is correcly defined.

        Issue Links

          Activity

          Hide
          Hong Zhang added a comment -

          link to issue 986.

          Show
          Hong Zhang added a comment - link to issue 986.
          Hide
          marina vatkina added a comment -

          While only the pool handling code can really identify if the connection can't be
          created and send a good generic message instead, let's first rule out the NPE
          reported in the EMWrapper code. Assigning to ejb-container for that part.

          Show
          marina vatkina added a comment - While only the pool handling code can really identify if the connection can't be created and send a good generic message instead, let's first rule out the NPE reported in the EMWrapper code. Assigning to ejb-container for that part.
          Hide
          Mahesh Kannan added a comment -

          Transfering this to Jagadish

          Show
          Mahesh Kannan added a comment - Transfering this to Jagadish
          Hide
          Mahesh Kannan added a comment -

          Changing the subcategory

          Show
          Mahesh Kannan added a comment - Changing the subcategory
          Hide
          Jagadish added a comment -

          There are many reasons why a connection could not be created (eg: network
          adapter could not establish connection, password incorrect, user does not exist
          etc) and all of them will be a generic SQLException. Exception messages will
          vary from one jdbc-driver vendor to another.

          However, Appserver provides an error code and possible reasons for the error :
          Error code "RAR5038" in the exception trace indicates that one of the diagnostic
          message as "Check that database is running properly"

          Error message reference for RARXXXX - AS 9.0 :
          http://docs.sun.com/app/docs/doc/819-3665/6n5scd8ji?a=view

          Thanks,
          -Jagadish

          Show
          Jagadish added a comment - There are many reasons why a connection could not be created (eg: network adapter could not establish connection, password incorrect, user does not exist etc) and all of them will be a generic SQLException. Exception messages will vary from one jdbc-driver vendor to another. However, Appserver provides an error code and possible reasons for the error : Error code "RAR5038" in the exception trace indicates that one of the diagnostic message as "Check that database is running properly" Error message reference for RARXXXX - AS 9.0 : http://docs.sun.com/app/docs/doc/819-3665/6n5scd8ji?a=view Thanks, -Jagadish

            People

            • Assignee:
              Jagadish
              Reporter:
              ludo
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: