Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.enhydra.httpServerTest.server.servlet
Class BasicTestServlet  view BasicTestServlet download BasicTestServlet.java

java.lang.Object
  extended byjavax.servlet.GenericServlet
      extended byjavax.servlet.http.HttpServlet
          extended byorg.enhydra.httpServerTest.server.servlet.BasicTestServlet
All Implemented Interfaces:
java.io.Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig

public class BasicTestServlet
extends javax.servlet.http.HttpServlet

This class is a generic server side test servlet that client side test threads talk to. This class respondes to every request coming in by constructing an HttpResponseObject and returning it in the response as an XML stream. The response object returned contains information about all data received via the request. This presentation object properly handles GET and POST method request and multi-part mime encodings.


Field Summary
protected  java.io.File fileCacheDir
          This holds the directory, unique to this request, that any uploaded files are stored.
protected static java.lang.Long fileCacheDirCnt
          This is a static counter used by the presentation objects to ensure a unique sub-directory under the specified temporary base directory.
protected static java.lang.String TEMPORARY_BASE_DIR
          This holds a tempoary base directory used to cache uploaded files.
 
Fields inherited from class javax.servlet.http.HttpServlet
 
Fields inherited from class javax.servlet.GenericServlet
 
Constructor Summary
BasicTestServlet()
           
 
Method Summary
 void cleanupFiles()
          This function is called after all file MD5 hashkeys have been computed.
protected static long getFileCacheDirCnt()
          This is a static function to retrieve the next sequence of the conter variable held in this class.
protected  void initFileCacheDir()
          This function will continually loop until a unique temporary sub- directory is found.
protected  void populateCgiArgsFromGet(org.enhydra.httpServerTest.common.HttpResponseObject httpResponseObject, javax.servlet.http.HttpServletRequest request)
          This function will populate the response object with all CGI arguments submitted with the request.
protected  void populateCgiArgsFromPost(org.enhydra.httpServerTest.common.HttpResponseObject httpResponseObject, javax.servlet.http.HttpServletRequest request)
          This function will populate the response object with all CGI arguments submitted with the request.
protected  void populateCgiParams(org.enhydra.httpServerTest.common.HttpResponseObject httpResponseObject, javax.servlet.http.HttpServletRequest request)
          This function will populate the response object with all CGI parameters submitted with the request.
protected  void populateCookies(org.enhydra.httpServerTest.common.HttpResponseObject httpResponseObject, javax.servlet.http.HttpServletRequest request)
          This function will populate the response object with all http cookies submitted with the request.
protected  void populateFileUploadFromPost(org.enhydra.httpServerTest.common.HttpResponseObject httpResponseObject)
          This function will loop through all files found under the unique directory created by initFileCacheDir() and compute an MD5 hashkey for each individual file.
protected  void populateHeaders(org.enhydra.httpServerTest.common.HttpResponseObject httpResponseObject, javax.servlet.http.HttpServletRequest request)
          This function will populate the response object with all http headers submitted with the request.
protected  void populateRequestInfo(org.enhydra.httpServerTest.common.HttpResponseObject httpResponseObject, javax.servlet.http.HttpServletRequest request)
          This function runs through the HttpServletRequest API and populates the response object with the retrieved information.
protected  void populateSessionInfo(org.enhydra.httpServerTest.common.HttpResponseObject httpResponseObject, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          This function will populate the response object with all session information submitted with the request.
 void service(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Overide the service method of HttpServelet.
 
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doGet, doHead, doOptions, doPost, doPut, doTrace, getLastModified, service
 
Methods inherited from class javax.servlet.GenericServlet
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, init, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

fileCacheDir

protected java.io.File fileCacheDir
This holds the directory, unique to this request, that any uploaded files are stored.


TEMPORARY_BASE_DIR

protected static final java.lang.String TEMPORARY_BASE_DIR
This holds a tempoary base directory used to cache uploaded files.


fileCacheDirCnt

protected static java.lang.Long fileCacheDirCnt
This is a static counter used by the presentation objects to ensure a unique sub-directory under the specified temporary base directory. The directories created using this count variable are used to cache files uploaded from the client.

Constructor Detail

BasicTestServlet

public BasicTestServlet()
Method Detail

getFileCacheDirCnt

protected static long getFileCacheDirCnt()
This is a static function to retrieve the next sequence of the conter variable held in this class. This function synchronizes on the fileCacheDirCnt and increments this count each time this function is called and then returns the new count.


service

public void service(javax.servlet.http.HttpServletRequest request,
                    javax.servlet.http.HttpServletResponse response)
             throws javax.servlet.ServletException,
                    java.io.IOException
Overide the service method of HttpServelet. This method runs through the remainder of the functions held in this class to initialize the response object based on information pulled from the request. Once the response object is populated, this method calls toString() on it and returns the generated XML structure to the client.


populateRequestInfo

protected void populateRequestInfo(org.enhydra.httpServerTest.common.HttpResponseObject httpResponseObject,
                                   javax.servlet.http.HttpServletRequest request)
This function runs through the HttpServletRequest API and populates the response object with the retrieved information.


populateCgiParams

protected void populateCgiParams(org.enhydra.httpServerTest.common.HttpResponseObject httpResponseObject,
                                 javax.servlet.http.HttpServletRequest request)
This function will populate the response object with all CGI parameters submitted with the request.


populateCgiArgsFromGet

protected void populateCgiArgsFromGet(org.enhydra.httpServerTest.common.HttpResponseObject httpResponseObject,
                                      javax.servlet.http.HttpServletRequest request)
This function will populate the response object with all CGI arguments submitted with the request. This method assumes a stardard GET or url-encoded POST request (ie. no multi-part mime).


populateHeaders

protected void populateHeaders(org.enhydra.httpServerTest.common.HttpResponseObject httpResponseObject,
                               javax.servlet.http.HttpServletRequest request)
This function will populate the response object with all http headers submitted with the request. This function will not include any 'default' headers applied by HTTPConnection.


populateCookies

protected void populateCookies(org.enhydra.httpServerTest.common.HttpResponseObject httpResponseObject,
                               javax.servlet.http.HttpServletRequest request)
This function will populate the response object with all http cookies submitted with the request.


populateCgiArgsFromPost

protected void populateCgiArgsFromPost(org.enhydra.httpServerTest.common.HttpResponseObject httpResponseObject,
                                       javax.servlet.http.HttpServletRequest request)
This function will populate the response object with all CGI arguments submitted with the request. This method assumes a multi-part mime encoding from a POST request.


initFileCacheDir

protected void initFileCacheDir()
This function will continually loop until a unique temporary sub- directory is found. This is accomplished by using the static data members and methods held in this class. Once a unique path is found, the directories are created and the global fileCacheDir is initialized.


populateFileUploadFromPost

protected void populateFileUploadFromPost(org.enhydra.httpServerTest.common.HttpResponseObject httpResponseObject)
This function will loop through all files found under the unique directory created by initFileCacheDir() and compute an MD5 hashkey for each individual file. The response object is then populated with each hashkey.


cleanupFiles

public void cleanupFiles()
This function is called after all file MD5 hashkeys have been computed. This function will recursively delete all uploaded files and temporary directories created while caching uploaded files.


populateSessionInfo

protected void populateSessionInfo(org.enhydra.httpServerTest.common.HttpResponseObject httpResponseObject,
                                   javax.servlet.http.HttpServletRequest request,
                                   javax.servlet.http.HttpServletResponse response)
This function will populate the response object with all session information submitted with the request. FIX ME: This function does not behave properly. All initial requests are initialized as session information comming from a session cookie.