com.bristle.javalib.net.http
Class ServletDebugger

java.lang.Object
  extended by com.bristle.javalib.net.http.ServletDebugger

public class ServletDebugger
extends Object

This class contains utility routines for interacting with the HTTP protocol.

Usage:
   - The typical scenario for using this class is:

     - To enable the ServletDebugger for an HttpServlet, add the following 
       line of code to the top of the servlet's service() method:
           if (ServletDebugger.intercept(this, request, response)) return;
       This causes the ServletDebugger to examine the HTTP request, and 
       decide whether to take action.  If so, it generates an HTTP response
       (setting the content-type, writing to the response Writer, etc.) and
       returns true.  Returning true causes the calling servlet to return 
       to its caller without doing anything. 

     - To activate an enabled ServletDebugger for an HTTP request, specify
       the following HTTP parameter (typically in the URL string)  
           bristleDebug

     - To force activation of the ServletDebugger, even if the HTTP parameters
       didn't request it:
           ServletDebugger.invoke(this, request, response);

?? Add other params that can cause other actions.
Assumptions:
Effects:
       - Intercepts requests to a servlet, sending its own response to the 
         HTTP client while running in the original servlet's Session.  Can
         modify values of attributes in the Session, the ServletContext, 
         etc.  ??Not yet??
Anticipated Changes:
Notes:
Implementation Notes:
Portability Issues:
Revision History:
   $Log$


Nested Class Summary
static class ServletDebugger.Tester
          Each class contains a Tester inner class with a main() for easier unit testing.
 
Field Summary
static String strACTIVATION_PARAM_NAME
          Name of the HTTP parameter used to active the ServletDebugger.
 
Constructor Summary
ServletDebugger()
           
 
Method Summary
static boolean intercept(HttpServlet servlet, HttpServletRequest request, HttpServletResponse response)
          Examine the specified HTTP request, and decide whether to invoke the "servlet debugger", returning true if invoked; false otherwise.
static void invoke(HttpServlet servlet, HttpServletRequest request, HttpServletResponse response)
          Invoke the "servlet debugger".
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

strACTIVATION_PARAM_NAME

public static final String strACTIVATION_PARAM_NAME
Name of the HTTP parameter used to active the ServletDebugger.

See Also:
Constant Field Values
Constructor Detail

ServletDebugger

public ServletDebugger()
Method Detail

intercept

public static boolean intercept(HttpServlet servlet,
                                HttpServletRequest request,
                                HttpServletResponse response)
                         throws IOException
Examine the specified HTTP request, and decide whether to invoke the "servlet debugger", returning true if invoked; false otherwise. See invoke() for more details.

Parameters:
servlet - The HttpServlet object defining the servlet.
request - The HttpServletRequest object of the servlet.
response - The HttpServletResponse object of the servlet.
Returns:
true if invoked; false otherwise.
Throws:
IOException - When an I/O error occurs during interaction with the servlet, request, or response.

invoke

public static void invoke(HttpServlet servlet,
                          HttpServletRequest request,
                          HttpServletResponse response)
                   throws IOException
Invoke the "servlet debugger". For now, this simply means to write as an XML stream to the HTTP client all information available to the servlet. Format of XML is as shown in HttpUtil.writeInfoAvailableToServlet.

Parameters:
servlet - The HttpServlet object defining the servlet.
request - The HttpServletRequest object of the servlet.
response - The HttpServletResponse object of the servlet.
Throws:
IOException - When an I/O error occurs during interaction with the servlet, request, or response.