You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Sukhwinder Singh <ss...@hotmail.com> on 2002/12/09 16:12:42 UTC

Tomcat 4.1.12 exception reporting vs Resin exception reproting

Hi,

I am using tomcat 4.1.12 for learning and development purpose. And I am
facing some problems regarding exception handling of tomcat. During
development Tomcat doesn't provide detailed description of an exception.
Instead of providing greater details about what caused the exception and
where it was thrown it just display the name of the bean which was called
from a jsp.

In an test application, I am using a jsp page which uses a CatalogBean to
get a list of products. CatalogBean again uses a DBBean to get access to
database through odbc and execute a query. When exception is thrown in
DBBean because of unavailability of db connection or some other problem it
throws an exception. And again CatalogBean catches the exception and
rethrows it. This exception is handled by jsp page and a stack trace is
printed.

Here is the line in jsp file which uses a bean:

    -------------------------------------------------------------------
    <jsp:useBean id="catalog" class="CatalogBean" scope="request" />
    --------------------------------------------------------------------


Here is how list of products i retrieved:

   -------------------------------------------------------------------------
   <%
     try


        Product[] products = catalog.getProducts();
        for (int i = 0; i < products.length; i++)
        {
            out.println("<tr>");
            out.println("<td>"+ products[i].getName() + "</td>");
            out.println("<td>" + products[i].getPrice() + "</td>");
            out.println("<td><a
href=\"/work/servlet/UpdateServlet?action=1&pid="+products[i].getId()+"\">Ad
d</a></td>");
            out.println("</tr>");
        }
     }
     catch(Exception e)
     {
        e.printStackTrace(new java.io.PrintWriter(out));
     }
  %>
  --------------------------------------------------------------------------
----

Here is the constructor of CatalogBean which is called by useBean in jsp:

  --------------------------------------------------------------------------
------
    public CatalogBean() throws Exception
    {
        products = Collections.synchronizedList(new ArrayList(25));
        try
        {
            db = new DBBean("shop", "sukh", "test");

        }
        catch (Exception e)
        {
            throw new Exception ("Could not create DBBean", e);
        }
    }
   -------------------------------------------------------------------------
-

And here is the constructor of DBBean which is called by CatalogBean:

   -------------------------------------------------------------------------
-------

    public DBBean(String dsn, String dbUser, String dbPassword) throws
Exception
    {
            this("sun.jdbc.odbc.JdbcOdbcDriver", "jdbc:odbc:"+dsn, dbUser,
dbPassword);

    }

    public DBBean(String driverClass, String conString, String dbUser,
String dbPassword) throws Exception
    {
        try
        {
            Class.forName(driverClass);
            con = DriverManager.getConnection(conString, dbUser,
dbPassword);
            stmt = con.createStatement();

        }
        catch (ClassNotFoundException e)
        {
            e.printStackTrace();
            throw new Exception("Driver " + driverClass + " not found. ",
e);
        }
        catch (SQLException sqle)
        {
            sqle.printStackTrace();
            throw new Exception("Could not connect: " + sqle);
        }
        catch (Exception e)
        {
            e.printStackTrace();
            throw new Exception("Some error occured while connecting to
database: " + e);
        }
     }

   -------------------------------------------------------------------------
----------------

Now when database access is not available or some other error occurs here is
how tomcat reports this problem when jsp page above is accessed:

   -------------------------------------------------------------------------
-------

   type Exception report

   message

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

   exception

   org.apache.jasper.JasperException: CatalogBean
    at
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java)
    at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Application
FilterChain.java)
    at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterCh
ain.java)
    at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.ja
va)
    at
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invok
eNext(StandardPipeline.java)
    at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java)
    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java)
    at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.ja
va)
    at
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invok
eNext(StandardPipeline.java)
    at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java)
    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java)
    at org.apache.catalina.core.StandardContext.invoke(StandardContext.java)
    at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java)
    at
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invok
eNext(StandardPipeline.java)
    at
org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.
java)
    at
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invok
eNext(StandardPipeline.java)
    at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java)
    at
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invok
eNext(StandardPipeline.java)
    at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java)
    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java)
    at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java
)
    at
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invok
eNext(StandardPipeline.java)
    at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java)
    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java)
    at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java)
    at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java)
    at
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConne
ction(Http11Protocol.java)
    at
org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:508)
    at
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.jav
a:533)
    at java.lang.Thread.run(Thread.java:536)


root cause

javax.servlet.ServletException: CatalogBean
    at
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImp
l.java)
    at org.apache.jsp.shop_jsp._jspService(shop_jsp.java:100)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java)
    at
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java)
    at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Application
FilterChain.java)
    at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterCh
ain.java)
    at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.ja
va)
    at
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invok
eNext(StandardPipeline.java)
    at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java)
    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java)
    at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.ja
va)
    at
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invok
eNext(StandardPipeline.java)
    at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java)
    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java)
    at org.apache.catalina.core.StandardContext.invoke(StandardContext.java)
    at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java)
    at
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invok
eNext(StandardPipeline.java)
    at
org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.
java)
    at
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invok
eNext(StandardPipeline.java)
    at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java)
    at
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invok
eNext(StandardPipeline.java)
    at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java)
    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java)
    at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java
)
    at
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invok
eNext(StandardPipeline.java)
    at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java)
    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java)
    at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java)
    at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java)
    at
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConne
ction(Http11Protocol.java)
    at
org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:508)
    at
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.jav
a:533)
    at java.lang.Thread.run(Thread.java:536)
   -------------------------------------------------------------------------
-----------------

And here is how Resin 2.1.5 reports this exception:

   --------------------------------------------------------------------
    500 Servlet Exception
        java.lang.Exception: Could not create DBBean
        at sukhwinder.shop.CatalogBean.<init>(CatalogBean.java:28)
        at
_projects._shop._shop__jsp._jspService(/work/projects/shop/shop.jsp:5)
        at com.caucho.jsp.JavaPage.service(JavaPage.java:75)
        at com.caucho.jsp.Page.subservice(Page.java:485)
        at
com.caucho.server.http.FilterChainPage.doFilter(FilterChainPage.java:182)
        at com.caucho.server.http.Invocation.service(Invocation.java:312)
        at
com.caucho.server.http.CacheInvocation.service(CacheInvocation.java:135)
        at
com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:221)
        at
com.caucho.server.http.HttpRequest.handleConnection(HttpRequest.java:163)
        at com.caucho.server.TcpConnection.run(TcpConnection.java:137)
        at java.lang.Thread.run(Thread.java:536)
    Caused by: java.lang.Exception: Could not connect:
java.sql.SQLException:
    [TCX][MyODBC]Access denied for user: 'sukh@localhost' to database 'shop'
        at sukhwinder.shop.DBBean.<init>(DBBean.java:54)
        at sukhwinder.shop.DBBean.<init>(DBBean.java:21)
        at sukhwinder.shop.CatalogBean.<init>(CatalogBean.java:23)
        ... 10 more

   -------------------------------------------------------------------------
-----

Even when there is some other problem tomcat displays the same message but
resin displays this:

   -------------------------------------------------------------------------
-----
    java.lang.Exception: Could not retrieve products
    at sukhwinder.shop.CatalogBean.getProducts(CatalogBean.java:93)
    at projects._shop._shop__jsp._jspService(_shop__jsp.java:38)
    at com.caucho.jsp.JavaPage.service(JavaPage.java:75) at
com.caucho.jsp.Page.subservice(Page.java:485)
    at
com.caucho.server.http.FilterChainPage.doFilter(FilterChainPage.java:182)
    at com.caucho.server.http.Invocation.service(Invocation.java:312)
    at
com.caucho.server.http.CacheInvocation.service(CacheInvocation.java:135)
    at
com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:221)
    at
com.caucho.server.http.HttpRequest.handleConnection(HttpRequest.java:163)
    at com.caucho.server.TcpConnection.run(TcpConnection.java:137) at
java.lang.Thread.run(Thread.java:536)

    Caused by: java.sql.SQLException: [Microsoft][ODBC Driver Manager]
Invalid descriptor index
    at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6106)
    at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:6263)
    at sun.jdbc.odbc.JdbcOdbc.SQLGetDataInteger(JdbcOdbc.java:3211)
    at
sun.jdbc.odbc.JdbcOdbcResultSet.getDataInteger(JdbcOdbcResultSet.java:5432)
    at sun.jdbc.odbc.JdbcOdbcResultSet.getInt(JdbcOdbcResultSet.java:571)
    at sukhwinder.shop.CatalogBean.getProducts(CatalogBean.java:85) ... 10
more
   -------------------------------------------------------------------------
-------------

Resin reporting is better here and we are able to see where the actual
problem is. It at least gives me some starting point to find the problem.
>From the caused by line above it is clear that it is because I am using
invlaid column number or name. So there is need to improve a little error
reporting of tomcat. Or is there any other way to configure tomcat so that
it provides more details. It is also very fast in comparison to tomcat even
when I am using resin cmp with ejb support. Resin compiles jsp within a
second but tomcat takes more then five seconds. I use jikes for both.
Also when using jikes tomcat prints warnings produced by jikes, encoding
related and others, when a modified jsp is accessed for the first time but
not second time. But resin doesn't.

--Sukhwinder Singh

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>