|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjavax.servlet.GenericServlet
javax.servlet.http.HttpServlet
org.alltimeflashdreamer.mailwebform.AbstractMailWebFormServlet
org.alltimeflashdreamer.mailwebform.MailWebFormServlet
Title: MailWebFormServlet
Description: This class represents the core of the MailWebForm application part. It collects the
required information to send a mail using the wrapper class
org.alltimeflashdreamer.util.email.MailSender.
This information consists of the required and the optional parameters that are
provided by either the server administrator (lowest in hierarchy) or the MailWebForm provider
(using an overriding provider file) or the calling web site (highest priority; using URL
parameters from e.g. hidden form inputs). In case the information is set in more than one of
these sources, the source with the highest ranking is used.
The required parameters are the host name and the port number of the SMTP server to send the
mails to as well as the sender's and the recipient's address (the recipient's name is recognized
by the servlet too, but not required by specification).
Each additional URL parameter is treated as an optional parameter. They may be added to the
MailWebForm calling web site, usually an input mask to send a mail to the provider of a web site
(or someone else, but always to the same address). In case such additional/optional key-value
pairs are found in the request object, they are added at the beginning of the message text,
unless a mail template is defined. If one is defined, the placeholders in this template are
replaced with the values of the URL parameters having the same name as those placeholders.
Example : Let's say one likes to have a gender checkbox on his input mask, and because he
uses two different input masks to send mails with, he wants to configure indipendent send mail
configurations. The solution for the first problem is to add a HTML input tag of type checkbox,
named e.g. "isMale", and a text telling the user that he shall activate the checkbox in case he
is man. The recipient will see a line "isMale = on" at the beginning of the mail, and no
additional line in case the box remained unchecked. The second solution is to configure two
different provider configurations in the admin tool and specify the send configuration using a
hidden HTML input tag named "provider" in both sites. The value of the first one would perhaps be
"myfirstsite" and the second one therefore "mysecondsite". This requires two files in the
providers overwriting files or in the application's config directory, one named
myfirstsite.properties and the second mysecondsite.properties, each of them having individually
configured overwrite parameters.
For a HTML example, see the mailwebform_testexample.html file which is part of the distribution.
The important tags (required and optional) are demonstrated and commented there.
The output which is produced after the sending of a site isn't designed at all. Therefore, one
probably wants to replace this output with his own site. The provider of the mail sending site
may show a site telling the user that the mail has been sent successfully (in case it was
successful) or one telling him that the mail couldn't be delivered (in case of some error).
However, he doesn't have to do this. In case these sites aren't defined for the current provider,
the application looks for default settings (defined for the "system" provider in the Admin Tool).
If those lack too, the servlet produces its own, ugly output.
The system settings allow the definition of a site which is shown in case the application's
action method was called with illegal URL parameters, because some hacker was active or some
robot tried to enter or even spam the site.
The decision which provider's settings are to be used to send a mail depends on the value of the
URL parameter "provider". If this value isn't defined, either the spam error site (if defined) or
an error message is shown by the servlet. If it's known, the settings for this provider are read
from the different sources, and for each setting, the highest existing (in ranking, see above) is
taken. Finally, the URL parameters named "subject" and "text" are received and their values added
to the generated mail which is then sent to the provider's own or the application's default SMTP
server.
If this servlet is accessed without URL parameters, a simple default input mask is shown, as a
demonstration on the one and as a "is running" test on the other hand.
Field Summary | |
(package private) GlobalProperties |
globalProperties
Properties instance storing the values read from the global properties file |
(package private) MailFormProviderList |
mailFormProviders
the list of known providers of a mailwebform hosted by this servlet, including the "system" provider |
Constructor Summary | |
MailWebFormServlet()
|
Method Summary | |
void |
destroy()
Cleans up pointers and closes resources. |
void |
doGet(HttpServletRequest request,
HttpServletResponse response)
Since this servlet makes no distinction between a GET and a POST, pass the GET requests over to the doPost method. |
void |
doPost(HttpServletRequest request,
HttpServletResponse response)
Looks for the URL parameters. |
(package private) static String |
getConfigDirProperty()
Reads the system property defining the app's config directory. |
(package private) File |
getCredentialsFile()
Returns the abstract File instance pointing to the user credentials file. |
(package private) String |
getParameterIgnoreCase(HttpServletRequest request,
String sKey)
Searches the list of parameter names case-insensitively for the given key and returns the first value, if found. |
(package private) String[] |
getParameterValuesIgnoreCase(HttpServletRequest request,
String sKey)
Searches the list of parameter names case-insensitively for the given key and returns the value list, if found. |
(package private) File |
getPropertyFile()
Returns the abstract File instance pointing to the global properties file. |
(package private) void |
printOutput(String sText,
HttpServletResponse response)
Prints the given text to the response's output writer, flushes and finally closes it. |
(package private) void |
readGlobalProperties()
Reads the settings from the global properties file which must reside in the application classes' root folder. |
(package private) void |
showErrorScreen(MailWebFormException mwfe,
HttpServletRequest request,
HttpServletResponse response)
Wraps the given error message into the JSPBean and redirects the client to the error page. |
Methods inherited from class javax.servlet.http.HttpServlet |
doDelete, doHead, doOptions, doPut, doTrace, getLastModified, service, service |
Methods inherited from class javax.servlet.GenericServlet |
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 |
GlobalProperties globalProperties
MailFormProviderList mailFormProviders
Constructor Detail |
public MailWebFormServlet()
Method Detail |
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
doPost
in class AbstractMailWebFormServlet
request
- contains the request parameters we need to haveresponse
- contains the client's url to write to
ServletException
- in case problems occurred within the servlet container
IOException
- in case problems occurred accessing a properties filepublic void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
request
- (see description of implementing doPost method)response
- (see description of implementing doPost method)
ServletException
- (see description of implementing doPost method)
IOException
- (see description of implementing doPost method)void readGlobalProperties() throws MailWebFormException
MailWebFormException
- wrapped and commented IOException, if one was
thrownFile getPropertyFile() throws MailWebFormException
MailWebFormException
- if the file is missing or not editableFile getCredentialsFile() throws MailWebFormException
MailWebFormException
- if the system's configdir property isn't
setstatic String getConfigDirProperty() throws MailWebFormException
MailWebFormException
- if the property isn't definedString getParameterIgnoreCase(HttpServletRequest request, String sKey)
request
- what to query for the URL parameterssKey
- the key that shall case-insensitively be searched for
String[] getParameterValuesIgnoreCase(HttpServletRequest request, String sKey)
request
- what to query for the URL parameterssKey
- the key that shall case-insensitively be searched for
void printOutput(String sText, HttpServletResponse response) throws IOException
sText
- a text that is wrapped into a very simple HTML pageresponse
- contains the client's url to write to
IOException
- thrown by the PrintWriter class, if anyvoid showErrorScreen(MailWebFormException mwfe, HttpServletRequest request, HttpServletResponse response) throws IOException
mwfe
- the application-specific error object that is to be renderedrequest
- the client's request objectresponse
- used for redirecting the client
IOException
- thrown by the PrintWriter class, if anypublic void destroy()
destroy
in interface Servlet
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |