org.jlf.util
Class SessionTesterBean

java.lang.Object
  |
  +--org.jlf.util.SessionTesterBean

public class SessionTesterBean
extends java.lang.Object

A set of static methods to test and dump servlet sessions. Normally to be used from SessionTester.jsp, but can also be used from the command line (see main()) or by calling these methods directly.

All dumping methods accept an object and an output stream. The display of the object is created as HTML and written to the stream.

The code for this class taken from Java Developer's Journal, "Servlet Session Display" Volume: 5 Issue: 2, p.12, by Peter Kobak.


Constructor Summary
SessionTesterBean()
           
 
Method Summary
static int dumpSerializable(java.lang.Object sessObj, java.io.PrintWriter out, boolean fDeep)
          Displays a (supposedly) Serializable object by attempting to write the object to determine if the object is serializable, and if so, how big the object is.
static void dumpSession(javax.servlet.http.HttpSession session, java.io.PrintWriter out, boolean fDeep)
          Diplays the content of a session, including indentification of each object stored in the session.
static void main(java.lang.String[] args)
          Stand-alone test for an object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SessionTesterBean

public SessionTesterBean()
Method Detail

dumpSession

public static void dumpSession(javax.servlet.http.HttpSession session,
                               java.io.PrintWriter out,
                               boolean fDeep)
Diplays the content of a session, including indentification of each object stored in the session. If fDeep is true, each such object is also displayed using dumpSerializable() and dumpBean() in this class.

Parameters:
session - Session to be displayed.
out - The stream to which HTML is written.
fDeep - True to perform a dump of each session object.

dumpSerializable

public static int dumpSerializable(java.lang.Object sessObj,
                                   java.io.PrintWriter out,
                                   boolean fDeep)
Displays a (supposedly) Serializable object by attempting to write the object to determine if the object is serializable, and if so, how big the object is. If fDeep is true, displays the name of each field in the class.

The purpose of this display is to assist the developer in determining if an object can be serialized in a servlet session, and to report the size and composition of the object so it can be controlled at an early stage in the development process.

Parameters:
sessObj - An object to be displayed. Although Serializable objects are expected, any object can be used. Non-serializable objects (including non-serializable objects embedded in sessObj) will be reported as such.
out - The stream to which HTML is written.
fDeep - True to display the fields of the object.
Returns:
Serialized size of sessObj (zero if couldn't be serialized).

main

public static void main(java.lang.String[] args)
Stand-alone test for an object. The program argument is the name of a class. If the class can be loaded and an object created, that object is displayed (with HTML tags) using dumpSerializable.