edu.utexas.beg.agi
Class AGIServlet

java.lang.Object
  |
  +--javax.servlet.GenericServlet
        |
        +--javax.servlet.http.HttpServlet
              |
              +--edu.utexas.beg.agi.AGIServlet

public class AGIServlet
extends javax.servlet.http.HttpServlet

The main Servlet for the AGI interactive web pages.

This Servlet is responsible for generating web pages that contain dynamic content, and for processing parameters submitted by those pages.
Specifically, when an exercise step uses and Applet, then this servlet is responsible for sending any previous input parameter values to that Applet, either through Applet parameters, or an I/O request by the Applet.
When an exercise step uses JavaScript- or plainHTML-forms, this Servlet is solely responsible for streaming the page (which may have dynamic values within it) and processing the results.

This class uses several helper classes, mostly for the purpose of dividing the source code into logical sections. Everything servlet-related could have been in this one class, but Servlet classes tend to get untidy with too many println()s in them.

See Also:
LoginHandler, DynamicHTMLPage, ParameterValidator, Serialized Form

Field Summary
(package private)  DynamicHTMLPage[] dynamicPages
          Helper Object for streaming mostly-static HTML pages back to the client browser, but substituting initial parameter values where appropriate.
(package private)  LoginHandler loginHandler
          Helper Object for validating user logins.
(package private)  ParameterValidator validator
          Helper Object for validating parameters when validation is needed.
 
Fields inherited from class javax.servlet.GenericServlet
config
 
Constructor Summary
AGIServlet()
           
 
Method Summary
private  DynamicHTMLPage[] createDynamicHTMLPages()
          Called during Servlet initialization to create the list of DynamicHTMLPages that will be served by this Object.
 void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          The main method for handling any HTTP GET request.
 void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          The main method for handling any HTTP POST request.
private  DynamicHTMLPage findDynamicHTMLPage(String pagePath)
          Searches the array of dynamic page Objects for one to handle the given path.
private  String getNextPage(javax.servlet.http.HttpServletRequest request, UserParameters parameters)
          Determines the next page to show the user.
 String getServletInfo()
          Standard Servlet API method for describing who we are, and what we think we're doing here.
 void init(javax.servlet.ServletConfig config)
          Initializes this Servlet Object.
 void processHTTPRequest(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Process an HTTP GET or POST request.
protected  Vector processInputParameters(javax.servlet.http.HttpServletRequest request, UserParameters parameters)
          Sets any user input parameters attached to the request as values in the UserParameters Object which is attached to this Session.
protected  void returnErrorPage(String error, String reason, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Generic routine for reporting errors to the client browser when something goes wrong.
 void returnLoginPage(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Writes the user login page to the client browser.
 
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doHead, doOptions, doPut, doTrace, getAllDeclaredMethods, getLastModified, maybeSetLastModified, service, service
 
Methods inherited from class javax.servlet.GenericServlet
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, log
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

validator

ParameterValidator validator
Helper Object for validating parameters when validation is needed.

dynamicPages

DynamicHTMLPage[] dynamicPages
Helper Object for streaming mostly-static HTML pages back to the client browser, but substituting initial parameter values where appropriate.

loginHandler

LoginHandler loginHandler
Helper Object for validating user logins.
Constructor Detail

AGIServlet

public AGIServlet()
Method Detail

init

public void init(javax.servlet.ServletConfig config)
          throws javax.servlet.ServletException
Initializes this Servlet Object.

Servlets use init() instead of a real constructor.
If a Servlet is database-driven or dependent on some other being, it would establish connections here, so that in the event of some failure, it could throw a ServletException, and our web server would know not to count on us.

This servlet does not have dependencies, so we'll simply create our helper Objects here.

Overrides:
init in class javax.servlet.GenericServlet

getServletInfo

public String getServletInfo()
Standard Servlet API method for describing who we are, and what we think we're doing here.
Overrides:
getServletInfo in class javax.servlet.GenericServlet

doGet

public void doGet(javax.servlet.http.HttpServletRequest request,
                  javax.servlet.http.HttpServletResponse response)
           throws javax.servlet.ServletException,
                  IOException
The main method for handling any HTTP GET request.

When you type a simple URL, i.e. http://www.jjt.com/index.html, that is a GET request. In HTTP, that simply means "GET me this file from this host." GET requests can also have simple parameters, i.e. http://www.jjt.com/index.html?myname=Jonathan&mycompany=JJT. In this way, parameters can be passed to this Servlet.

The "other" main type of HTTP is a POST. This servlet accepts GET or POST requests, and handles them both in the same manner by calling processHTTPRequest().

Parameters:
request - the HTTP request received from the client browser.
response - the HTTP reply to be populated by this method.
Overrides:
doGet in class javax.servlet.http.HttpServlet
See Also:
doPost(HttpServletRequest,HttpServletResponse), processHTTPRequest(HttpServletRequest,HttpServletResponse)

doPost

public void doPost(javax.servlet.http.HttpServletRequest request,
                   javax.servlet.http.HttpServletResponse response)
            throws javax.servlet.ServletException,
                   IOException
The main method for handling any HTTP POST request.

When you type a simple URL, i.e. http://www.jjt.com/index.html, that is a GET request. A slightly more complex request is a POST, which is the way most HTML forms submit data. The client user fills in the blanks and hits the "submit" button, and the values of each field are POSTed to the server as named parameters.

The "other" main type of HTTP is a GET. This servlet accepts GET or POST requests, and handles them both in the same manner by calling processHTTPRequest().

Parameters:
request - the HTTP request received from the client browser.
response - the HTTP reply to be populated by this method.
Overrides:
doPost in class javax.servlet.http.HttpServlet
See Also:
doGet(HttpServletRequest,HttpServletResponse), processHTTPRequest(HttpServletRequest,HttpServletResponse)

processHTTPRequest

public void processHTTPRequest(javax.servlet.http.HttpServletRequest request,
                               javax.servlet.http.HttpServletResponse response)
                        throws javax.servlet.ServletException,
                               IOException
Process an HTTP GET or POST request.

This method is called when a request comes from a client browser directed at this Servlet. The request might be in the form: http://www.beg.utexas.edu/servlets/edu.utexas.beg.agi.AGIServlet?parm1=value1&parm2=value2
This request is presented in the form of a Request Object, which encapsulates all aspects of the client request, incuding cookie values and the parameters given. This method should digest the Request and populate the Response Object, which includes streaming back the HTML code for the next page the client browser will display.

Parameters:
request - the HTTP request received from the client browser.
response - the HTTP reply to be populated by this method.

returnErrorPage

protected void returnErrorPage(String error,
                               String reason,
                               javax.servlet.http.HttpServletRequest request,
                               javax.servlet.http.HttpServletResponse response)
                        throws IOException
Generic routine for reporting errors to the client browser when something goes wrong.

createDynamicHTMLPages

private DynamicHTMLPage[] createDynamicHTMLPages()
Called during Servlet initialization to create the list of DynamicHTMLPages that will be served by this Object.

returnLoginPage

public void returnLoginPage(javax.servlet.http.HttpServletRequest request,
                            javax.servlet.http.HttpServletResponse response)
                     throws IOException
Writes the user login page to the client browser.

processInputParameters

protected Vector processInputParameters(javax.servlet.http.HttpServletRequest request,
                                        UserParameters parameters)
Sets any user input parameters attached to the request as values in the UserParameters Object which is attached to this Session.
Returns:
a List of parameter names which were added to the UserParameters Object, represented as Strings.

findDynamicHTMLPage

private DynamicHTMLPage findDynamicHTMLPage(String pagePath)
Searches the array of dynamic page Objects for one to handle the given path.

getNextPage

private String getNextPage(javax.servlet.http.HttpServletRequest request,
                           UserParameters parameters)
Determines the next page to show the user.

The next page is determined either by the nextpage parameter of the Request, or, if none is given, by the content of the UserParameters Object.