Inheritance diagram for edu.virtualschool.jwaa.GenericServlet:

Most of the work is done here. Subclasses must only override methods to return information particular to each site (e.g. the login page, default page, permission denied page, and so forth).
Copyright 2002 by Brad Cox: <bcox@virtualschool.edu>
Definition at line 27 of file GenericServlet.java.
Public Member Functions | |
| GenericServlet (MetaPage[] metaPages) | |
| void | doGet (HttpServletRequest req, HttpServletResponse rsp) throws ServletException, IOException |
| void | doPost (HttpServletRequest req, HttpServletResponse rsp) throws ServletException, IOException |
| final void | doRequest (HttpServletRequest req, HttpServletResponse rsp) throws IOException, ServletException |
| AccountAbstraction | getAccountOrNull (HttpServletRequest req) |
| void | logRequest (MetaPage meta, HttpServletRequest req, HttpServletResponse rsp) |
| MetaPage | findMetaPage (String key) |
| abstract void | doFault (MetaPage meta, HttpServletRequest req, HttpServletResponse rsp, Throwable e) |
| abstract AccountAbstraction | getNullAccount () |
| abstract MetaPage | getDefaultPage () |
| abstract MetaPage | getRefusePage () |
| abstract MetaPage | getRootPage () |
| final RequestDispatcher | getRequestDispatcher (String path) throws IOFault |
Package Attributes | |
| final HashMap | dispatchTable = new HashMap() |
Static Package Attributes | |
| Logger | logger = Logger.getLogger(GenericServlet .class.getName()) |
|
|
Constructor This primes the dispatch table with a link for each of the dynamic pages they serve.
Definition at line 38 of file GenericServlet.java. References edu.virtualschool.jwaa.GenericURI.getText(), and edu.virtualschool.jwaa.MetaPage.link.
00039 {
00040 BasicConfigurator.configure();
00041 for (int i = 0; i < metaPages.length; i++)
00042 {
00043 MetaPage metaPage = metaPages[i];
00044 String url = metaPage.link.getText();
00045
00046 MetaPage prior = (MetaPage)dispatchTable.get(url);
00047 if (prior != null)
00048 logger.error("Non-unique url: " + url + ". See \n" +
00049 " page "+metaPage+" and \n" +
00050 " page "+prior + "\n");
00051
00052 dispatchTable.put(url, metaPage);
00053 }
00054 }
|
|
||||||||||||||||||||
|
Applications must override to specify how to handle faults.
Implemented in edu.virtualschool.jwaa.xml.JwaaServlet. Referenced by edu.virtualschool.jwaa.GenericServlet.doRequest(). |
|
||||||||||||
|
Handle GET requests Definition at line 58 of file GenericServlet.java. References edu.virtualschool.jwaa.GenericServlet.doRequest().
00060 {
00061 doRequest(req, rsp);
00062 }
|
|
||||||||||||
|
Handle POST requests Definition at line 66 of file GenericServlet.java. References edu.virtualschool.jwaa.GenericServlet.doRequest().
00068 {
00069 doRequest(req, rsp);
00070 }
|
|
||||||||||||
|
Handle get or post servlet requests by parsing out the requested page id from request.getPathInfo().
Definition at line 80 of file GenericServlet.java. References edu.virtualschool.jwaa.MetaPage.allowsAccessBy(), edu.virtualschool.jwaa.GenericServlet.doFault(), edu.virtualschool.jwaa.GenericServlet.findMetaPage(), edu.virtualschool.jwaa.GenericServlet.getAccountOrNull(), edu.virtualschool.jwaa.GenericServlet.getRefusePage(), edu.virtualschool.jwaa.GenericPage.init(), edu.virtualschool.jwaa.GenericServlet.logRequest(), edu.virtualschool.jwaa.MetaPage.pageClass, and edu.virtualschool.jwaa.GenericPage.run(). Referenced by edu.virtualschool.jwaa.GenericServlet.doGet(), and edu.virtualschool.jwaa.GenericServlet.doPost().
00082 {
00083 AccountAbstraction person = getAccountOrNull(req);
00084 String uri = req.getRequestURI();
00085 MetaPage meta = findMetaPage(uri);
00086 logRequest(meta, req, rsp);
00087 if (!meta.allowsAccessBy(person))
00088 meta = getRefusePage();
00089 try
00090 {
00091 GenericPage page = (GenericPage)meta.pageClass.newInstance();
00092 page.init(meta, this, req, rsp);
00093 page.run();
00094 }
00095 catch (IgnorableFault e)
00096 {
00097 }
00098 catch (IOFault e)
00099 {
00100 doFault(meta, req, rsp, e);
00101 throw (IOException)e.getChainedException();
00102 }
00103 catch (IOException e)
00104 {
00105 doFault(meta, req, rsp, e);
00106 throw e;
00107 }
00108 catch (ServletException e)
00109 {
00110 doFault(meta, req, rsp, e);
00111 throw e;
00112 }
00113 catch (Throwable e)
00114 {
00115 doFault(meta, req, rsp, e);
00116 }
00117 }
|
|
|
Find a page in the servlet's dispatch table. This is declared non-final so subclasses can override it for specialized needs. By default, the lookup key is the uri as returned by request.getURI(). Returns getMetaPage() if the lookup fails, so this NEVER returns null.
Definition at line 165 of file GenericServlet.java. References edu.virtualschool.jwaa.GenericServlet.getDefaultPage(). Referenced by edu.virtualschool.jwaa.GenericServlet.doRequest().
00166 {
00167 Object o = dispatchTable.get(key);
00168 MetaPage meta = (MetaPage)o;
00169 if (meta == null)
00170 meta = getDefaultPage();
00171 return meta;
00172 }
|
|
|
Returns the currently logged in Account if someone is logged in (e.g. if a session exists and contains an person attribute), else null.
Definition at line 125 of file GenericServlet.java. Referenced by edu.virtualschool.jwaa.GenericServlet.doRequest().
00126 {
00127 HttpSession session = req.getSession();
00128 if (session == null)
00129 return null;
00130 AccountAbstraction person = (AccountAbstraction) session.getAttribute(GenericPage.SESSION_ATTRIBUTE_NAME);
00131 if (person == null)
00132 return null;
00133 else
00134 return person;
00135 }
|
|
|
Override to specify the page to show if a page lookup fails.
Implemented in edu.virtualschool.jwaa.xml.JwaaServlet. Referenced by edu.virtualschool.jwaa.GenericServlet.findMetaPage(). |
|
|
This method gives the application control over what getAccount returns when no one is logged in. Applications often define their own conventions that are inconsistent with any decision hardcoded at this level.
Implemented in edu.virtualschool.jwaa.xml.JwaaServlet. Referenced by edu.virtualschool.jwaa.GenericPage.getAccount(), and edu.virtualschool.jwaa.GenericPage.setAccount(). |
|
|
Override with the page to show if a page access is refused.
Implemented in edu.virtualschool.jwaa.xml.JwaaServlet. Referenced by edu.virtualschool.jwaa.GenericServlet.doRequest(). |
|
|
This Dispatcher rigamarole has been problematic from day one. Apparently path must be the full path minus the leading (context name) component. Why: who knows?
Definition at line 246 of file GenericServlet.java.
00247 {
00248 if (!path.startsWith("/"))
00249 throw new IOFault("" + path + " does not begin with \"/\"");
00250 else
00251 {
00252 int i = path.indexOf("/", 1);
00253 if (i < 0)
00254 throw new IOFault("" + path + " does not begin with \"/contextName/\"");
00255
00256 String pathInContext = path.substring(i);
00257 ServletContext servletContext = getServletContext();
00258 RequestDispatcher dispatcher =
00259 servletContext.getRequestDispatcher(pathInContext);
00260
00261 if (dispatcher == null)
00262 throw new IOFault(
00263 "" + this +".getRequestDispatcher: " + path + " failed");
00264 return dispatcher;
00265 }
00266 }
|
|
|
Override to return the root page of the page hierarchy. The reference to the root of the hierarchy will cause the classloader to load all other pages in the hierarchy. If you have any pages that are not in the hierarchy, they will not be loaded.
Implemented in edu.virtualschool.jwaa.xml.JwaaServlet. |
|
||||||||||||||||
|
Called on each dispatch to log the request. Subclases can override this to do custom logging.
Definition at line 143 of file GenericServlet.java. Referenced by edu.virtualschool.jwaa.GenericServlet.doRequest().
00144 {
00145 if (logger.isDebugEnabled())
00146 {
00147 logger.debug("request: "+req.getClass().getName());
00148 logger.debug(" contextPath: "+req.getContextPath());
00149 logger.debug(" servletPath: "+req.getServletPath());
00150 logger.debug(" pathInfo: "+req.getPathInfo());
00151 logger.debug(" queryString: "+req.getQueryString());
00152 logger.debug(" requestURI: "+req.getRequestURI());
00153 logger.debug(" page: "+meta);
00154 }
00155 }
|