org.locomotive.servlets
Class MultiThreadedHttpServlet

java.lang.Object
  |
  +--javax.servlet.GenericServlet
        |
        +--javax.servlet.http.HttpServlet
              |
              +--org.locomotive.servlets.MultiThreadedHttpServlet
Direct Known Subclasses:
MultiThreadedHang, MultiThreadedLocoServlet, PermanentlyUnavailable1, PermanentlyUnavailable2, TemporarilyUnavailable1, TemporarilyUnavailable2

public class MultiThreadedHttpServlet
extends javax.servlet.http.HttpServlet

The MultiThreadedHttpServlet class is a Servlet class you can use as a superclass for multithreaded servlet-container-independant servlets you're writing. All of the functionality it provides should work on any Servlet 2.1-compliant container. This class and your own subclass should be all that you need.

Notice that 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 servlet container, and that one instance will serve any/all requests simultaneously.

Author:
Jason Brittain
See Also:
Serialized Form

Constructor Summary
MultiThreadedHttpServlet()
           
 
Method Summary
 void displayString(java.lang.String message, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          If you want to send back a single string as the response to the user, you can use this method.
static java.lang.String exceptionStackTrace(java.lang.Throwable e)
          A utility function - given the exception, give us a string that contains the stack trace for it.
 void handleException(java.lang.Exception exception, java.lang.String short_code, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          This is a convenience method you can use when you catch serious Exceptions for which you want a stack trace and you need to send the user an error code, which can help you debug.
 void sayBadURL(javax.servlet.http.HttpServletResponse response)
          Simply tells the user that they typed a bad URL, by sending the message: "I'm sorry, I don't understand that URL."

 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 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
 

Constructor Detail

MultiThreadedHttpServlet

public MultiThreadedHttpServlet()
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 javax.servlet.http.HttpServlet
See Also:
#setup, javax.servlet.http.HttpServlet.html#service

handleException

public void handleException(java.lang.Exception exception,
                            java.lang.String short_code,
                            javax.servlet.http.HttpServletRequest request,
                            javax.servlet.http.HttpServletResponse response)
This is a convenience method you can use when you catch serious Exceptions for which you want a stack trace and you need to send the user an error code, which can help you debug.

Parameters:
exception - the exception to print to the server log.
short_code - the error message to send to the user
request - the HttpServletRequest for this Thread
response - the HttpServletResponse for this Thread

displayString

public void displayString(java.lang.String message,
                          javax.servlet.http.HttpServletRequest request,
                          javax.servlet.http.HttpServletResponse response)
                   throws java.io.IOException
If you want to send back a single string as the response to the user, you can use this method. (You don't need to put your message within <HTML><BODY>...</BODY></HTML>)

Parameters:
message - the message you'd like to display
request - the HttpServletRequest for this Thread
response - the HttpServletResponse for this Thread

sayBadURL

public void sayBadURL(javax.servlet.http.HttpServletResponse response)
               throws java.io.IOException
Simply tells the user that they typed a bad URL, by sending the message: "I'm sorry, I don't understand that URL."

Parameters:
response - the HttpServletResponse for this Thread

exceptionStackTrace

public static java.lang.String exceptionStackTrace(java.lang.Throwable e)
A utility function - given the exception, give us a string that contains the stack trace for it. This method was copied verbatim from org.locomotive.util.StringUtil.java for inclusion in this self-contained container-portable class.