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, save the exceptions into catalina.out through a JSP page as follows:

  1. 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. Add these files to /opt/novell/nam/idp/webapps/nidp using Advanced File Configurator. For information about how to add a file, see Adding Configurations to a Cluster.

  3. Open Identity Server’s web.xml and 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.

    For information about how to modify a file, see Modifying Configurations.

  4. 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.

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