Sun Java System Web Server 7.0 Update 6 Developer's Guide to Java Web Applications

Chapter 10 Debugging Web Applications

This chapter provides guidelines for debugging web applications in Web Server. The chapter includes the following sections:

Debugging applications requires you to edit the server.xml file as described in this chapter. For more general information, see Sun Java System Web Server 7.0 Update 6 Administrator’s Configuration File Reference.

Enabling Debugging

When you enable debugging, you enable both local and remote debugging. You can enable debugging through Admin Console or by editing server.xml.

Sun Java System Web Server debugging is based on the JPDA (Java™ Platform Debugger Architecture software). For more information, see JPDA Options

Procedure To Enable Debugging Through Admin Console

  1. Access the Admin Console.

  2. Click the Edit Java Settings tab in the home page.

  3. Click the JVM Settings tab.

  4. Select the Enable Debug option to enable debugging.

    For more information about debug options, see JPDA Options

  5. Click Save.

ProcedureTo Enable Debugging by Editing server.xml

  1. Set the following attributes of the jvm element in the server.xml file:

    • Set debug="true" to turn on debugging.

    • Add any desired JPDA debugging options in the debugoptions attribute. See JPDA Options.

    • To specify the port to use when attaching the JVM to a debugger. Specify address=port_number in the debugoptions attribute.

    For details about the server.xml file, see the Sun Java System Web Server 7.0 Update 6 Administrator’s Configuration File Reference.

JPDA Options

The default JPDA options are as follows:

-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n

If you change the value of suspend=y, the JVM starts in suspended mode and stays suspended until a debugger attaches to it. Use this option if you want to start debugging as soon as the JVM starts.

To specify the port to use when attaching the JVM to a debugger, specify address=port_number. You can also use the shared memory transport dt_shmem on the Win32 platform.

For more information on list of JPDA debugging options, see

http://java.sun.com/products/jpda/doc/conninv.html#Invocation.

Using Developer Tools for Debugging

Sun Java Studio Enterprise 8.1 technology can be used for remote debugging if you want to manually attach the IDE to a remote Web Server started in debug mode.

ProcedureTo Debug using NetBeans 5.5

  1. Press mouse button the Web project name in the IDE. Choose Debug Project from the context menu.

    Web Server will then start in debug mode and the IDE will pause executing the program at the breakpoint you have set in your application.

Debugging JSPs

When you use Sun Java Studio Enterprise 8.1 to debug JSPs, you can set breakpoints in either the JSP code or the generated servlet code. You can switch between them and see the same breakpoints in both the JSP code and the servlet code.

To set up debugging in Sun Java Studio Enterprise 8.1, see Using Developer Tools for Debugging.

Generating a Stack Trace for Debugging

For information about how to generate a Java stack trace for debugging, see

http://developer.java.sun.com/developer/technicalArticles/Programming/Stacktrace/.

If the -Xrs flag is set for reduced signal usage in the server.xml file (under jvm), comment it out before generating the stack trace. If the -Xrs flag is used, the server might dump core and restart when you send the signal to generate the trace.

The stack trace goes to the system log file or to stderr based on the log attributes in server.xml.

For more information about the server.xml file, see the Sun Java System Web Server 7.0 Update 6 Administrator’s Guide.

Displaying Stack Trace and Compiler Errors

Web Server supports, display-exception feature under server/servlet container which displays stack traces and compiler errors to the browser. This feature helps the user to view the log in the browser and prevents them from looking into the server log file every time a compiler error occurs. You can enable or disable this feature by set-servlet-container-prop CLI or by selecting Display-Exception check box under set-servlet-container tab in Administration GUI.

ProcedureTo Display Stack Trace and Compiler Error

  1. Create a JSP with syntax error.

  2. Request for the log page through the browser.

    The browser displays the message Server Error.

  3. Select Display-Exception check box under set-servlet-container tab in Administration GUI or enable the display-exception feature through set-servlet-container-prop CLI.

  4. Request for the log page again through the browser.

    The browser displays the stack trace and compiler errors.

Using Logging for Debugging

You can use the Web Server log files to help debug your applications. For general information about logging, see the Sun Java System Web Server 7.0 Update 6 Administrator’s Guide. For information about server.xml file, see the Sun Java System Web Server 7.0 Update 6 Administrator’s Configuration File Reference.

You can change logging settings in one of these ways:

ProcedureTo Change the Log Settings

  1. Access the Admin Console.

  2. Click the View Server Logs tab in the home page.

  3. Set the log preferences.

  4. Click Save to apply your changes.

Using Profiling for Debugging

You can use a profiler to perform remote profiling on the Web Server to discover choke point in server-side performance. This section describes how to configure these profilers for use with Web Server:

Using the HPROF Profiler

HPROF is a simple profiler agent shipped with the Java 2 SDK. It is a dynamically linked library that interacts with the JavaTM Virtual Machine Profiler Interface (JVMPI) and writes out profiling information either to a file or to a socket in ASCII or binary format. This information can be further processed by a profiler front-end tool such as HAT.

HPROF can present CPU usage, heap allocation statistics, and monitor contention profiles. In addition, it can also report complete heap dumps and states of all of the monitors and threads in the Java virtual machine. For more details on the HPROF profiler, see the JDK documentation at:

http://java.sun.com/j2se/1.4.2/docs/guide/jvmpi/jvmpi.html

Once HPROF is installed, its libraries are loaded into the server process.

You can configure Web Server

ProcedureTo Install the HPROF Profiler

  1. Access the Admin Console.

  2. Click the Edit Java Settings tab in the home page.

    The JVM General Settings screen appears.

  3. Click Profilers.

  4. Click New.

    The Create JVM Profiler popup appears.

  5. Type the Name and select the JVM Profiler option to enable the profiler. Leave the Class Path and Native Library Path fields blank.

  6. Click New to configure the JVM options.

  7. Click OK.

    Edit the server.xml file as appropriate

    <! --hprof options -->
    <profiler name="hprof" enabled="true"
    <jvm-options>
    -Xrunhprof:file=log.txt,options
    </jvm-options>
    </profiler>

    Note –

    Do not use the -Xrs flag.


    Here is an example of options you can use:

    -Xrunhprof:file=log.txt,thread=y,depth=3

    The file option is important because it determines where the stack dump is written in step 6.

    The syntax of HPROF options is as follows:


    -Xrunhprof[:help]|[:option=value,option2=value2, ...]

    Using help lists options that can be passed to HPROF. The output is as follows:

    Hprof usage: -Xrunhprof[:help]|[:<option>=<value>, ...]
    Option Name and Value Description Default
    heap=dump|sites|all heap profiling allcpu=samples|old CPU 
    usage offformat=a|b ascii or binary output 
    afile=<file> write data to file java.hprof(.txt for ascii)
    net=<host>:<port> send data over a socket write to filedepth=<size> 
    stack trace depth 4cutoff=<value> 
    output cutoff point 0.0001lineno=y|n line number in traces? 
    ythread=y|n thread in traces? ndoe=y|n dump on exit? y
  8. Change the PRODUCT_BIN assignment in the /install_dir/instance_dir/bin/startserv file from:

    PRODUCT_BIN=webservd-wdog to PRODUCT_BIN=webservd

  9. Start the server by running the startserv script.

    As the server runs in the foreground, the command prompt returns only after the server has been stopped.

  10. Find the process ID of the server process in another window or terminal.

    % ps -ef | grep webservd

    This command lists two webservd processes. Look at the PPID (parent process ID) column and identify which of the two processes is the parent process and which is the child process. Note the PID (process ID) of the child process ID.

  11. Send a SIGQUIT signal (signal 3) to the child process:

    % kill -QUIT child_PID

  12. Run the stopserv script from another window to stop the Web Server.

    % ./stopserv

    Stopping the server writes an HPROF stack dump to the file you specified using the file HPROF option. For general information about using a stack dump, see Generating a Stack Trace for Debugging.

Using the Optimizeit Profiler

Information about Optimizeit is available at:

http://www.borland.com/optimizeit/

Once Optimizeit is installed, its libraries are loaded into the server process.

To enable remote profiling with Optimizeit, do one of the following: