org.locomotive.loco.servlet
Class MultiThreadedLocoServlet

java.lang.Object
  |
  +--javax.servlet.GenericServlet
        |
        +--javax.servlet.http.HttpServlet
              |
              +--org.locomotive.servlets.MultiThreadedHttpServlet
                    |
                    +--org.locomotive.loco.servlet.MultiThreadedLocoServlet
Direct Known Subclasses:
UnavailableServlet

public class MultiThreadedLocoServlet
extends MultiThreadedHttpServlet

The MultiThreadedLocoServlet class is a Servlet class you can subclass if you want to write a servlet for use with the Locomotive (maybe one that uses STEAM).

WARNING: Servlets that are written as subclasses of this class will not run on any servlet containers other than the Locomotive! Only subclass this class if you're sure that you (nor anyone else) will ever need/want to run your servlet in another servlet container.

Notice that as a subclass of MultiThreadedHttpServlet, this class does not implement SingleThreadModel, which means that subclasses of this class will be treated as multithreaded servlets. Only one instance of each kind of multithreaded servlet will be instantiated in the Locomotive, and that one instance will serve any/all requests simultaneously.

Author:
Jason Brittain
See Also:
MultiThreadedHttpServlet, Serialized Form

Field Summary
static int DEBUG
          Log level to use for debugging
static int ERROR
          Log level to use for serious errors; e.g.
static int NORMAL
          Log level to use for normal activities
static int WARNING
          Log level to use for warnings
 
Constructor Summary
MultiThreadedLocoServlet()
           
 
Method Summary
 java.lang.String displayPage(java.lang.String document_path, java.util.Hashtable steam_vars, javax.servlet.http.HttpServletResponse response)
          Loads a Steam document, inserts the values of Steam variables into that document, and then writes the result back to the Web server.
 java.sql.Connection getConnection(javax.servlet.http.HttpServletRequest request)
          Pass this method the ServletRequest Object, and it returns the Locomotive's database Connection for this request (if it is defined in the request attributes under the key "locomotive.connection").
 FormData getFormData(javax.servlet.http.HttpServletRequest request)
          Pass this method the ServletRequest Object, and it returns the Locomotive's FormData for this request (if it is defined in the request attributes under the key "locomotive.form_data").
 java.util.Hashtable getSteamVars(javax.servlet.http.HttpServletRequest request)
          Pass this method the ServletRequest Object, and it returns the Locomotive's SteamVars Hashtable for this request (if it is defined in the request attributes under the key "locomotive.steam_vars").
 java.lang.String[] getURLTokens(javax.servlet.http.HttpServletRequest request)
          Pass this method the ServletRequest Object, and it returns the Locomotive's URL tokens (if they are defined in the request attributes under the key "locomotive.url_tokens").
 User getUser(javax.servlet.http.HttpServletRequest request)
          Pass this method the ServletRequest Object, and it returns the Locomotive's User Object for this request (if it is defined in the request's session values under the key "locomotive.user").
 void log(int log_level, java.lang.String log_message)
          Writes a message to the Locomotive's global server log.
 void logEvent(java.lang.String major, java.lang.String minor, java.lang.String data, javax.servlet.http.HttpServletRequest request)
          Write one event to the global Locomotive event log.
 void service(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          The service method is the main entry point for Servlets.
 
Methods inherited from class org.locomotive.servlets.MultiThreadedHttpServlet
displayString, exceptionStackTrace, handleException, sayBadURL
 
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doGet, doOptions, doPost, doPut, doTrace, getLastModified, service
 
Methods inherited from class javax.servlet.GenericServlet
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, init, init, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ERROR

public static final int ERROR
Log level to use for serious errors; e.g. log(ERROR, "Wait! There's an error!");

WARNING

public static final int WARNING
Log level to use for warnings

NORMAL

public static final int NORMAL
Log level to use for normal activities

DEBUG

public static final int DEBUG
Log level to use for debugging
Constructor Detail

MultiThreadedLocoServlet

public MultiThreadedLocoServlet()
Method Detail

service

public void service(javax.servlet.http.HttpServletRequest request,
                    javax.servlet.http.HttpServletResponse response)
             throws java.io.IOException,
                    javax.servlet.ServletException
The service method is the main entry point for Servlets. All this method does is call the setup() method to get everything ready for the request, and then call super.service() to send the request off to the appropriate do() method (i.e. doGet(), doPost(), etc).

If you choose to override this method in a sub class, don't forget to call the setup() method at the beginning of your version.

Overrides:
service in class MultiThreadedHttpServlet
See Also:
#setup, javax.servlet.http.HttpServlet.html#service

log

public void log(int log_level,
                java.lang.String log_message)
Writes a message to the Locomotive's global server log.

Parameters:
log_level - 0 is most severe. The higher, the less severe. Messages with log_levels higher than the config variable LOG_LEVEL will be suppressed from being written to the log.
log_message - the message to write to the log.

logEvent

public void logEvent(java.lang.String major,
                     java.lang.String minor,
                     java.lang.String data,
                     javax.servlet.http.HttpServletRequest request)
Write one event to the global Locomotive event log. (this method is just a wrapper around Loco.logEvent().)

example:

logEvent(5, "login", "submit_form", user.getUsername());
Parameters:
major - the major event region or code section
minor - the minor event code
data - event specific data
request - the HttpServletRequest for this Thread

displayPage

public java.lang.String displayPage(java.lang.String document_path,
                                    java.util.Hashtable steam_vars,
                                    javax.servlet.http.HttpServletResponse response)
                             throws java.io.IOException
Loads a Steam document, inserts the values of Steam variables into that document, and then writes the result back to the Web server.

Parameters:
document_path - the file path of that document, relative to the template root.
steam_vars - a Hashtable containing STEAM variables to insert into the template.
response - the HttpServletResponse for this Thread
Returns:
a String containing the fully evaluated Steam document, after inserting all the variables. If the document with that file path does not exist, then returns "", an empty String. If another page has already been displayed, will return "".

getURLTokens

public java.lang.String[] getURLTokens(javax.servlet.http.HttpServletRequest request)
Pass this method the ServletRequest Object, and it returns the Locomotive's URL tokens (if they are defined in the request attributes under the key "locomotive.url_tokens"). Otherwise, this method returns null.

Parameters:
request - the HttpServletRequest for this Thread

getFormData

public FormData getFormData(javax.servlet.http.HttpServletRequest request)
Pass this method the ServletRequest Object, and it returns the Locomotive's FormData for this request (if it is defined in the request attributes under the key "locomotive.form_data"). Otherwise, this method returns null.

Parameters:
request - the HttpServletRequest for this Thread

getSteamVars

public java.util.Hashtable getSteamVars(javax.servlet.http.HttpServletRequest request)
Pass this method the ServletRequest Object, and it returns the Locomotive's SteamVars Hashtable for this request (if it is defined in the request attributes under the key "locomotive.steam_vars"). Otherwise, this method returns null.

Parameters:
request - the HttpServletRequest for this Thread

getConnection

public java.sql.Connection getConnection(javax.servlet.http.HttpServletRequest request)
Pass this method the ServletRequest Object, and it returns the Locomotive's database Connection for this request (if it is defined in the request attributes under the key "locomotive.connection"). Otherwise, this method returns null.

Parameters:
request - the HttpServletRequest for this Thread

getUser

public User getUser(javax.servlet.http.HttpServletRequest request)
Pass this method the ServletRequest Object, and it returns the Locomotive's User Object for this request (if it is defined in the request's session values under the key "locomotive.user"). Otherwise, this method returns null.

Parameters:
request - the HttpServletRequest for this Thread