de.spieleck.pcs.http
Class ControllerServlet
java.lang.Object
|
+--javax.servlet.GenericServlet
|
+--javax.servlet.http.HttpServlet
|
+--de.spieleck.pcs.http.ControllerServlet
- All Implemented Interfaces:
- ConfigUser, Constants, java.io.Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig
- public class ControllerServlet
- extends javax.servlet.http.HttpServlet
- implements ConfigUser, Constants
This servlet acts as a Controller defined by the Front Controller Pattern.
The ControllerServlet is the main gateway of a pcs based web application
and every request should use this servlet.
The ControllerServlet uses a file to lookup the mappings between action keys
and the implementing Action classes. This file is a Java Properties file
specified by the servlet init parameter "pcsfw.controller.actions". If this
is not set, "/conf/actions.properties" will be used instead.
If a init parameter "pcsfw.controller.viewconfig" is specified, this file
name will be used to configure the used View
- See Also:
- Serialized Form
Method Summary |
protected boolean |
checkAuthorization(javax.servlet.http.HttpServletRequest request)
by this method the Controller Servlet checks, if a given request is
authorized or not. |
void |
destroy()
Destroys the servlet. |
protected void |
display(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
ActionResult ar,
ServiceInfo service)
|
protected void |
doGet(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Handles the HTTP GET method by calling processRequest |
protected void |
doPost(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Handles the HTTP POST method by calling processRequest |
protected ServiceInfo |
getService(javax.servlet.http.HttpServletRequest request)
returns an Action matching the given request. |
java.lang.String |
getServletInfo()
Returns a short description of the servlet. |
protected void |
handleException(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
java.lang.Exception e)
This method handles exceptions by addind the exception to the session
and call processRequest. |
void |
init(javax.servlet.ServletConfig config)
Initializes the servlet. |
protected void |
processRequest(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Processes requests for both HTTP GET
and POST methods.
|
void |
resetConfig()
resets the configuration by calling the Servlet's init method |
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, getServletName, init, log, log |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
description
protected static java.lang.String description
controllerConfig
protected ControllerConfig controllerConfig
ControllerServlet
public ControllerServlet()
init
public void init(javax.servlet.ServletConfig config)
throws javax.servlet.ServletException
- Initializes the servlet.
- Overrides:
init
in class javax.servlet.GenericServlet
destroy
public void destroy()
- Destroys the servlet.
- Overrides:
destroy
in class javax.servlet.GenericServlet
getService
protected ServiceInfo getService(javax.servlet.http.HttpServletRequest request)
throws ControllerException
- returns an Action matching the given request. To determine the key of the
action, at first the path is checked and as key is taken the string from
the beginning of the path to the second occurance of '/'. As example if a
request is processed with the URL
"http://www.server.com/controller/action/" then the String "action"
is used as key.
If the ActionFactory returns no Action object for this key, the
Controller checks whether there is a request parameter named "action".
If such a parameter is found the Controller tries to get an Action from
the ActionFactory with such a key.
If this fails, the Controller tries to get an Action from the
ActionFactory with the key "default". If again no matching action can
be found, a ServletException is thrown.
- Parameters:
request
- the request to the Servlet- Returns:
- a matching action
- Throws:
javax.servlet.ServletException
- if no matching action could be found
processRequest
protected void processRequest(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
throws javax.servlet.ServletException,
java.io.IOException
- Processes requests for both HTTP
GET
and POST
methods.
It gets an action via the getAction-Method and performs this action with all
parameters supplied by the request and the request and the response. The
request is put in the hashtable of the action
with the key "request" and the reponse is put with the key "response".
- Parameters:
request
- servlet requestresponse
- servlet response
display
protected void display(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
ActionResult ar,
ServiceInfo service)
throws java.io.IOException
handleException
protected void handleException(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
java.lang.Exception e)
throws java.io.IOException,
javax.servlet.ServletException
- This method handles exceptions by addind the exception to the session
and call processRequest. Then the called method will display the
exception.
checkAuthorization
protected boolean checkAuthorization(javax.servlet.http.HttpServletRequest request)
- by this method the Controller Servlet checks, if a given request is
authorized or not. Should be overwritten if neccessary, since this
implementaiton allways returns true.
- Parameters:
request
- the request which is checked for authorization
doGet
protected void doGet(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
throws javax.servlet.ServletException,
java.io.IOException
- Handles the HTTP
GET
method by calling processRequest
- Overrides:
doGet
in class javax.servlet.http.HttpServlet
- Parameters:
request
- servlet requestresponse
- servlet response
doPost
protected void doPost(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
throws javax.servlet.ServletException,
java.io.IOException
- Handles the HTTP
POST
method by calling processRequest
- Overrides:
doPost
in class javax.servlet.http.HttpServlet
- Parameters:
request
- servlet requestresponse
- servlet response
getServletInfo
public java.lang.String getServletInfo()
- Returns a short description of the servlet.
- Overrides:
getServletInfo
in class javax.servlet.GenericServlet
resetConfig
public void resetConfig()
- resets the configuration by calling the Servlet's init method
- Specified by:
resetConfig
in interface ConfigUser