|
![]() |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
ObjectGenericServlet
HttpServlet
hirondelle.web4j.Controller
public class Controller
Single point of entry for serving dynamic pages.
The application can serve content both directly (by simple, direct reference to a JSP's URL), and indirectly, through this Controller.
Like almost all servlets, this class is safe for multi-threaded environments.
Validates user input and request parameters, interacts with a datastore,
and places problem domain model objects in scope for eventual rendering by a JSP.
Performs either a forward or a redirect, according to the instructions of the
Action
.
Emails are sent to the webmaster when :
This class is in a distinct package for two reasons :
There are key-names defined in this class (see below). Their names need to be long-winded (web4j_key_for_...), unfortunately, in order to avoid conflict with other tools, including your application.
Field Summary | |
---|---|
static String |
CHARACTER_ENCODING
Key name for the application's character encoding, placed in application scope as a String upon startup. |
static String |
CURRENT_URI
Key name for the URI for the current request, placed in request scope as a String. |
static String |
LOCALE
Key name for the default Locale , placed in application scope
as a Locale upon startup. |
static String |
MOST_RECENT_TROUBLE_TICKET
Key name for the most recent TroubleTicket , placed in application scope when a
problem occurs. |
static String |
START_TIME
Key name for the startup time, placed in application scope as a DateTime upon startup. |
static String |
TIME_ZONE
Key name for the default TimeZone , placed in application scope
as a TimeZone upon startup. |
static String |
WEB4J_VERSION
Name and version number of the WEB4J API. |
static String |
WEBMASTER
Key name for the webmaster email address, placed in application scope as a String upon startup. |
Constructor Summary | |
---|---|
Controller()
|
Methods inherited from class HttpServlet |
---|
doHead, doOptions, doTrace, getLastModified, service, service |
Methods inherited from class GenericServlet |
---|
getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log |
Methods inherited from class Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String WEB4J_VERSION
Value: "WEB4J/4.10.0".
Upon startup, this item is logged at CONFIG level. (This item is is simply a hard-coded field in this class. It is not configured in web.xml.)
public static final String CHARACTER_ENCODING
Key name: "web4j_key_for_character_encoding".
Configured in web.xml. The value UTF-8 is highly recommended.
public static final String WEBMASTER
Key name: "web4j_key_for_webmaster".
Configured in web.xml.
public static final String LOCALE
Locale
, placed in application scope
as a Locale upon startup.
Key name: "web4j_key_for_locale".
The application programmer is encouraged to use this key for any
Locale stored in session scope : the default implementation
of LocaleSource
will always search for this
key in increasingly larges scopes. Thus, the default mechanism will
automatically use the user-specific Locale as an override to
the default one.
Configured in web.xml.
public static final String TIME_ZONE
TimeZone
, placed in application scope
as a TimeZone upon startup.
Key name: "web4j_key_for_time_zone".
The application programmer is encouraged to use this key for any
TimeZone stored in session scope : the default implementation
of TimeZoneSource
will always search for this
key in increasingly larges scopes. Thus, the default mechanism will
automatically use the user-specific TimeZone as an override to
the default one.
Configured in web.xml.
public static final String MOST_RECENT_TROUBLE_TICKET
TroubleTicket
, placed in application scope when a
problem occurs.
Key name: "web4j_key_for_most_recent_trouble_ticket".
public static final String START_TIME
DateTime
upon startup.
Key name: "web4j_key_for_start_time".
public static final String CURRENT_URI
Key name: "web4j_key_for_current_uri".
Somewhat bizarrely, the servlet API does not allow direct access to this item.
Constructor Detail |
---|
public Controller()
Method Detail |
---|
public final void init(ServletConfig aConfig) throws ServletException
Operations include :
ApplicationInfo
object into application scope
StartupTasks.startApplication(ServletConfig, String)
, to
allow the application to perform its own startup tasks
One or more of the application's databases may not be running when
the web application starts. Upon startup, this Controller first queries each database
for simple name and version information. If that query fails, then the database is
assumed to be "down", and the app's implementation of StartupTasks
(which usually fetches code tables from the database) is not called.
The web app, however, will not terminate. Instead, this Controller will keep attempting to connect for each incoming request. When all databases are determined to be healthy, the Controller will perform the database initialization tasks it usually performs upon startup, and the app will then function normally.
If the database subsequently goes down again, then this Controller will not take any special action. Instead, the container's connection pool should be configured to attempt to reconnect automatically on the application's behalf.
init
in interface Servlet
init
in class GenericServlet
ServletException
public void destroy()
destroy
in interface Servlet
destroy
in class GenericServlet
public final void doGet(HttpServletRequest aRequest, HttpServletResponse aResponse) throws IOException
processRequest(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
.
doGet
in class HttpServlet
IOException
public final void doPost(HttpServletRequest aRequest, HttpServletResponse aResponse) throws IOException
processRequest(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
.
doPost
in class HttpServlet
IOException
public final void doPut(HttpServletRequest aRequest, HttpServletResponse aResponse) throws IOException
processRequest(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
. PUT can be called by XmlHttpRequest.
doPut
in class HttpServlet
IOException
public final void doDelete(HttpServletRequest aRequest, HttpServletResponse aResponse) throws IOException
processRequest(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
. DELETE can be called by XmlHttpRequest.
doDelete
in class HttpServlet
IOException
protected void processRequest(HttpServletRequest aRequest, HttpServletResponse aResponse) throws IOException
HttpServletRequest.getMethod()
.
This method can be overridden, if desired. The great majority of applications will not need to override this method.
Operations include :
LoginTasks
RequestParser
Action
, and execute it
UntrustedProxyForUserId
)
ResponsePage
TroubleTicket
, log it, and
email it to the webmaster email address configured in web.xml
TroubleTicket
, log it, and email it to the webmaster address configured in web.xml
IOException
protected ResponsePage swapResponsePage(ResponsePage aResponsePage, Locale aLocale)
ResponsePage
according to Locale
.
This overridable default implementation does nothing, and returns null. If the return value of this method is null, then the nominal ResponsePage will be used without alteration. If the return value of this method is not null, then it will be used to override the nominal ResponsePage.
This method is intended for applications that use different JSPs for different Locales.
For example, if the nominal response is a forward to Blah_en.jsp, and the "real"
response should be Blah_fr.jsp, then this method can be overridden to return the
appropriate ResponsePage
. This method is called only for
forward operations. If it is overridden, then its return value must also correspond to a forward
operation.
This style of implementing translation is not recommended. Instead, please use the services of the hirondelle.web4j.ui.translate package.
protected final void logAndEmailSeriousProblem(Throwable aException, HttpServletRequest aRequest)
Typically called when an unexpected Exception occurs in
processRequest(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
. Uses TroubleTicket.mailToRecipients()
.
Also, stores the trouble ticket in application scope, for possible later examination.
protected final void logAndEmailPerformanceProblem(String aMilliseconds, HttpServletRequest aRequest)
Called only when the response time of a request is above the threshold value configured in web.xml.
Builds a Throwable with a description of the problem, then creates and
emails a TroubleTicket
to the webmaster.
aMilliseconds
- response time of a request in milliseconds
|
![]() |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |