org.locomotive.loco.servlet
Class ServletRoutingTable

java.lang.Object
  |
  +--org.locomotive.server.ServiceRoutingTable
        |
        +--org.locomotive.loco.servlet.ServletRoutingTable

public class ServletRoutingTable
extends ServiceRoutingTable
implements javax.servlet.http.HttpSessionContext

This class controls servlet activity for a particular servlet routing table. An instance should be created at startup and maintained throughout the life of the server. The send a servlet on it's way, use the routeRequest method.


Inner Class Summary
 class ServletRoutingTable.ServletEntry
           
 
Inner classes inherited from class org.locomotive.server.ServiceRoutingTable
ServiceRoutingTable.ServiceEntry
 
Field Summary
static java.lang.Class single_thread_model_class
           
static javax.servlet.Servlet unavailable_servlet
           
 
Fields inherited from class org.locomotive.server.ServiceRoutingTable
AVAILABLE, PERMANENTLY_UNAVAILABLE, server_log, service_configs, service_extensions_hash, service_tokens_hash, SHUTDOWN, UNAVAILABLE_AND_WAITING
 
Constructor Summary
ServletRoutingTable(java.lang.String path, Log server_log, java.util.Vector classpath, boolean auto_reload)
          Initializes the servletRoutingTable and loads the servlets.
 
Method Summary
protected  ServiceRoutingTable.ServiceEntry createServiceEntry(java.lang.String pattern, java.lang.String classname, java.lang.String config_path)
          Adds the a ServletEntry to the service_tokens_hash or the service_extensions_hash.
 java.util.Enumeration getIds()
          Deprecated. for security reasons
 LocoServletRequest getLocoServletRequest()
          This method returns the LocoServletRequest for the current Thread
 javax.servlet.http.HttpSession getSession(java.lang.String sessionId)
          Deprecated. for security reasons
 javax.servlet.http.HttpSessionContext getSessionContext()
          Returns the session context object for this server.
 void initialize()
          This method overrides ServiceRoutingTable::initialize().
protected  void putInDefaults()
          Overrides the superclass to put in the default handlers.
 void routeRequest(int request_id, java.net.Socket sock, java.io.InputStream is, java.io.OutputStream os, java.util.Hashtable cgi_envars, java.util.Hashtable form_hash, java.util.Hashtable steam_vars, java.lang.String[] url_tokens, java.lang.String request_uri, long bstamp_id, Response response, java.sql.Connection conn, Session session, java.util.Hashtable attrib)
          This gets called on every request by the loco, once it determines it has a servlet in its hands.
 java.lang.Object routeToService(LocoConfig config, java.lang.String request_uri, java.lang.String first_token)
          Finds and returns the service Object associated with the specified request uri.
static void sendErrorMsg(int status_code, java.lang.String error_msg, javax.servlet.ServletRequest req, javax.servlet.http.HttpServletResponse resp)
          Displays and error page with Standard insertions, plus the error string for the class.
 
Methods inherited from class org.locomotive.server.ServiceRoutingTable
addService, containsService, getProperties, getService, log, markServiceForReloading, reloadService, routeToClass, routeToServiceEntry, shutdown, throwException
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

single_thread_model_class

public static java.lang.Class single_thread_model_class

unavailable_servlet

public static javax.servlet.Servlet unavailable_servlet
Constructor Detail

ServletRoutingTable

public ServletRoutingTable(java.lang.String path,
                           Log server_log,
                           java.util.Vector classpath,
                           boolean auto_reload)
                    throws InitializationException
Initializes the servletRoutingTable and loads the servlets.
Method Detail

initialize

public void initialize()
                throws InitializationException
This method overrides ServiceRoutingTable::initialize(). This implementation first shuts down the ServletRoutingTable's services (if any), and then it calls super.initialize().
Overrides:
initialize in class ServiceRoutingTable
Tags copied from class: ServiceRoutingTable
Throws:
InitializationException - if the file could not be loaded correctly, or if any of the Services could not be loaded successfully.

createServiceEntry

protected ServiceRoutingTable.ServiceEntry createServiceEntry(java.lang.String pattern,
                                                              java.lang.String classname,
                                                              java.lang.String config_path)
Adds the a ServletEntry to the service_tokens_hash or the service_extensions_hash.
Overrides:
createServiceEntry in class ServiceRoutingTable

putInDefaults

protected void putInDefaults()
                      throws InitializationException
Overrides the superclass to put in the default handlers. here's what we put in:
   default      SimpleServlet
   unknown      SimpleServlet
   srv          ServerServlet
 
Overrides:
putInDefaults in class ServiceRoutingTable

routeRequest

public void routeRequest(int request_id,
                         java.net.Socket sock,
                         java.io.InputStream is,
                         java.io.OutputStream os,
                         java.util.Hashtable cgi_envars,
                         java.util.Hashtable form_hash,
                         java.util.Hashtable steam_vars,
                         java.lang.String[] url_tokens,
                         java.lang.String request_uri,
                         long bstamp_id,
                         Response response,
                         java.sql.Connection conn,
                         Session session,
                         java.util.Hashtable attrib)
This gets called on every request by the loco, once it determines it has a servlet in its hands. It sets up everything the servlet needs, then sends it on its way.
Overrides:
routeRequest in class ServiceRoutingTable
Parameters:
request_id - the unique id for this request
sock - the socket this request connected on
is - the inputstream from that socket
os - the outputstream from that socket
cgi_envars - the CGI variables passed in with the request
form_hash - the form data, if there was any
url_tokens - a tokenized form of the url
request_uri - the unparsed url tokens
bstamp_id - the browser stamp id that came in from the bstamp cookie for this request
response - the response for this request
conn - the Database connection for this request
session - the Session object for this request
attrib - attributes for this request

routeToService

public java.lang.Object routeToService(LocoConfig config,
                                       java.lang.String request_uri,
                                       java.lang.String first_token)
Finds and returns the service Object associated with the specified request uri. This method first tries to match the first token to a token mapping (like "base"), and then tries to match the request uri to an extension mapping (like "*.jsp"). This method overrides the method routeToService(LocoConfig, String, String) in ServiceRoutingTable, only this method also passes through any unavailability information to present to the user if the ServiceEntry's availability status shows either temporary or permanent unavailability.

Overrides:
routeToService in class ServiceRoutingTable
Parameters:
config - a reference to the LocoConfig object
request_uri - the URI of the request
first_token - the first URL token of the request. It is used to find the correct service to map the request to.
See Also:
ServiceRoutingTable.routeToService(org.locomotive.loco.LocoConfig, java.lang.String, java.lang.String)

getSessionContext

public javax.servlet.http.HttpSessionContext getSessionContext()
Returns the session context object for this server. Context should be created in initialize()

getLocoServletRequest

public LocoServletRequest getLocoServletRequest()
This method returns the LocoServletRequest for the current Thread

sendErrorMsg

public static void sendErrorMsg(int status_code,
                                java.lang.String error_msg,
                                javax.servlet.ServletRequest req,
                                javax.servlet.http.HttpServletResponse resp)
Displays and error page with Standard insertions, plus the error string for the class. The error string is set in the constructor. Evaluates the template LOCO_TEMPLATE_ROOT_PATH/error/generic_error.tmpl. LOCO_TEMPLATE_ROOT_PATH is the template directory, as specified in the Loco configuration file. If this template is missing, then it will send a generic html file including the message.
Parameters:
status_code - one of the status codes defined in HttpServletResponse.
error_msg - The message to display. If left blank or null, then the following will message will be displayed:
Your request could not be processed due to an internal servlet error.
req - the request object for this request
resp - the response object for this request

getIds

public java.util.Enumeration getIds()
Deprecated. for security reasons

Currently returns all the ids of all the sessions in the database.
Specified by:
getIds in interface javax.servlet.http.HttpSessionContext
Returns:
an Enumeration of Long objects, or null if we had database problems

getSession

public javax.servlet.http.HttpSession getSession(java.lang.String sessionId)
Deprecated. for security reasons

Presently goes to the database and gets the session with the specified Session ID. The session id has to be a number that exists, otherwise this will null.
Specified by:
getSession in interface javax.servlet.http.HttpSessionContext