23.3.3 Capturing Stack Traces of Exceptions

If any error occurs at the server side (Identity Server or Access Gateway) while processing the JSP content, perform the following steps to save the exceptions into the catalina.out file through a JSP page:

  1. On Linux /opt/novell/nam/idp/webapps/nidp and on Windows C:\Program Files\Novell\Tomcat\webapps\nidp, create the following files:

    testerror.jsp:

            <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
          pageEncoding="ISO-8859-1"%>
                <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
                    <html>
                               <head>
                                            <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
                                            <title>TestError.JSP</title>
                                </head>
                                <%
                                             String a = null;
                                             out.println(" test " + a.toString());
                                 %>
                   </html>

    error.jsp:

    <%@ page language="java" isErrorPage="true" import="java.io.*" contentType="text/html; charset=ISO-8859-1"
        pageEncoding="utf-8"%>
          <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
            <html>
                    <head>
                             <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
                             <title>Default Error Page</title>
                    </head>
                    <body>
                      Message:
                      <%=exception.getMessage()%>
                      StackTrace:
                      <%
                              StringWriter stringWriter = new StringWriter();
                              PrintWriter printWriter = new PrintWriter(stringWriter);
                              exception.printStackTrace(printWriter);
                              out.println(stringWriter);
                              System.out.println(stringWriter);
                              printWriter.close();
                              stringWriter.close();
                      %>
                   </body>
            </html>
  2. On Linux /opt/novell/nam/idp/webapps/nidp/WEB-INF/web.xml file, and on Windows C:\Program Files\Novell\Tomcat\webapps\nidp\WEB-INF\web.xml file, add the following:

    <error-page>
                     <exception-type>java.lang.Throwable</exception-type>
                     <location>/error.jsp</location>
      </error-page>

    If the element error-page is already available, add exception-type and update location.

  3. In idp_url:port/nidp/testerror.jsp, the stack trace is displayed on the browser and is also stored in the catalina.out log file.

  4. To prevent the stack trace from being displayed on the browser, remove the out.println(stringWriter) string from the error.jsp file and change isErrorPage to false. Now, the stack trace is not displayed on the browser but is still stored in the catalina.out log file.