org.cdlib.xtf.dynaXML.test
Class TestableDynaXML

Object
  extended by GenericServlet
      extended by HttpServlet
          extended by TextServlet
              extended by DynaXML
                  extended by TestableDynaXML
All Implemented Interfaces:
Serializable, Servlet, ServletConfig

public class TestableDynaXML
extends DynaXML

Extends the DynaXML servlet slightly to allow programmatic testing of the servlet. Authentication always succeeds. Any exceptions will be thrown upward rather than generating an error page.

Author:
Martin Haye
See Also:
Serialized Form

Field Summary
private  String baseDir
           
private  String indexDirOverride
           
private  IndexWarmer indexWarmer
           
private  ThreadLocal<Integer> nHits
           
 
Fields inherited from class TextServlet
stylesheetCache
 
Constructor Summary
TestableDynaXML(String baseDir)
          Simplified initialization for use outside a real servlet container.
 
Method Summary
protected  boolean authenticate(DocRequest docReq, HttpServletRequest req, HttpServletResponse res)
          Performs user authentication for a request, given the authentication info for the document.
 DocLocator createDocLocator()
          Create a DocLocator.
 QueryProcessor createQueryProcessor()
          For test mode, allow override of index warmer.
protected  void genErrorPage(HttpServletRequest req, HttpServletResponse res, Exception exc)
          Would normally generate an error page.
protected  Source getSourceDoc(DocRequest docReq, Transformer transformer)
          Perform the normal dynaXML getSourceDoc() operation, then record the resulting number of hits (if any) that came out.
 int nHits()
          Return the number of hits in the last request processed by this thread
 void overrideIndexDir(String dir)
          Allows overriding the directory specified in future query requests.
protected  DocRequest runDocReqParser(HttpServletRequest req, AttribList attribs)
          Allow overriding the index directory
 void service(String url)
          Simplified method to test-get the given URL.
 void setIndexWarmer(IndexWarmer warmer)
          Allows overriding default index warmer.
protected  void setupTrace(TextConfig config)
          For test mode, do nothing to the current trace flags.
 
Methods inherited from class DynaXML
doGet, getConfig, getConfigName, getServletInfo, readConfig, setProfiling
 
Methods inherited from class TextServlet
addParam, addToken, addTokens, buildParamBlock, calcMimeType, convertUTF8inURL, cqlTokenize, createFilteredReceiver, decodeURL, defaultTokenize, destroy, doPost, getCurRequest, getCurResponse, getCurServlet, getRealPath, getRequestURL, getRequestURL, getText, isEmpty, isSessionTrackingEnabled, makeAttribList, makeHtmlString, makeHtmlString, rawTokenize, readBranding, requireOrElse, restoreWildcards, saveWildcards, service, setErrorGenSheet, stuffAttribs, stuffAttribs, stuffSpecialAttribs
 
Methods inherited from class HttpServlet
doDelete, doHead, doOptions, doPut, doTrace, getLastModified, service
 
Methods inherited from class GenericServlet
getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletName, init, init, log, log
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

baseDir

private String baseDir

indexDirOverride

private String indexDirOverride

indexWarmer

private IndexWarmer indexWarmer

nHits

private ThreadLocal<Integer> nHits
Constructor Detail

TestableDynaXML

public TestableDynaXML(String baseDir)
                throws ServletException
Simplified initialization for use outside a real servlet container.

Parameters:
baseDir - the XTF home directory.
Throws:
ServletException - if anything goes wrong.
Method Detail

overrideIndexDir

public void overrideIndexDir(String dir)
Allows overriding the directory specified in future query requests.


setIndexWarmer

public void setIndexWarmer(IndexWarmer warmer)
Allows overriding default index warmer.


nHits

public int nHits()
Return the number of hits in the last request processed by this thread


setupTrace

protected void setupTrace(TextConfig config)
For test mode, do nothing to the current trace flags.

Overrides:
setupTrace in class TextServlet

runDocReqParser

protected DocRequest runDocReqParser(HttpServletRequest req,
                                     AttribList attribs)
                              throws Exception
Allow overriding the index directory

Overrides:
runDocReqParser in class DynaXML
Parameters:
req - The original HTTP request
attribs - Attributes to pass to the stylesheet.
Returns:
A parsed document request, or null if before that step
Throws:
Exception

createQueryProcessor

public QueryProcessor createQueryProcessor()
For test mode, allow override of index warmer. Default to foreground warming.

Overrides:
createQueryProcessor in class TextServlet

service

public void service(String url)
             throws ServletException,
                    IOException
Simplified method to test-get the given URL. Throws away the output but retains the number of hits.

Parameters:
url - the URL to test-get
Throws:
ServletException
IOException

getSourceDoc

protected Source getSourceDoc(DocRequest docReq,
                              Transformer transformer)
                       throws InvalidDocumentException,
                              IOException,
                              SAXException,
                              ParserConfigurationException
Perform the normal dynaXML getSourceDoc() operation, then record the resulting number of hits (if any) that came out.

Overrides:
getSourceDoc in class DynaXML
Parameters:
docReq - Tells which document to load, the query to apply, tec.
transformer - The XSLT transformer that will be used on the document.
Returns:
An XML Source object representing the loaded document.
Throws:
IOException - If a problem is encountered loading a file or URL
SAXException - If the document cannot be parsed as valid XML
ParserConfigurationException - Miscellaneous configuration problems
InvalidDocumentException

authenticate

protected boolean authenticate(DocRequest docReq,
                               HttpServletRequest req,
                               HttpServletResponse res)
                        throws Exception
Performs user authentication for a request, given the authentication info for the document. In the case of testing, we never fail authentication.

Overrides:
authenticate in class DynaXML
Parameters:
docReq - Info structure containing authentication parameters
req - The request being processed
res - Where to send results if authentication fails
Returns:
true iff authentication succeeds
Throws:
Exception

genErrorPage

protected void genErrorPage(HttpServletRequest req,
                            HttpServletResponse res,
                            Exception exc)
Would normally generate an error page. Instead we throw an exception upward.

Overrides:
genErrorPage in class TextServlet
Parameters:
req - The HTTP request we're responding to
res - The HTTP result to write to
exc - The exception producing the error. If it's a DynaXMLException, the attributes will be passed to the error stylesheet.

createDocLocator

public DocLocator createDocLocator()
Description copied from class: DynaXML
Create a DocLocator. Checks the system property "org.cdlib.xtf.DocLocatorClass" to see if there is a user- supplied implementation. If not, a DefaultDocLocator is created.

Overrides:
createDocLocator in class DynaXML