Package edu.uiuc.ncsa.security.servlet
Class AbstractServlet
- java.lang.Object
- 
- javax.servlet.GenericServlet
- 
- javax.servlet.http.HttpServlet
- 
- edu.uiuc.ncsa.security.servlet.AbstractServlet
 
 
 
- 
- All Implemented Interfaces:
- Logable,- Serializable,- javax.servlet.Servlet,- javax.servlet.ServletConfig
 
 public abstract class AbstractServlet extends javax.servlet.http.HttpServlet implements Logable Very straightforward servlet wrapper. This sets up logging and debug. All posts and gets are intercepted and routed to a single doIt method.
 This has the environment, loader and initialization static hence shared between all instances of this. 3/23/2012: Added simple bootstrapping mechanism. This requires you set a context listener in your web.xml deployment descriptor. See the documentation inBootstrapperfor more details.Created by Jeff Gaynor 
 on May 3, 2010 at 11:35:16 AM- See Also:
- Serialized Form
 
- 
- 
Field SummaryFields Modifier and Type Field Description protected static AbstractEnvironmentenvironmentprotected static Initializationinitializationprotected static String[]IP_HEADERSstatic StringPING_PARAMETER
 - 
Constructor SummaryConstructors Constructor Description AbstractServlet()
 - 
Method SummaryAll Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected booleancheckContentType(String rawContentType, String contentType)static StringCONST(String key)Utility to get constants or code gets really wordy.voiddebug(String x)Write a debug message to the log.voiddoGet(javax.servlet.http.HttpServletRequest httpServletRequest, javax.servlet.http.HttpServletResponse httpServletResponse)protected abstract voiddoIt(javax.servlet.http.HttpServletRequest httpServletRequest, javax.servlet.http.HttpServletResponse httpServletResponse)protected booleandoPing(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)This returns true or false forvoiddoPost(javax.servlet.http.HttpServletRequest httpServletRequest, javax.servlet.http.HttpServletResponse httpServletResponse)voiderror(String x)Write an error message to the log.voiderror(String x, Throwable t)static ConfigurationLoader<? extends AbstractEnvironment>getConfigurationLoader()static AbstractEnvironmentgetEnvironment()ExceptionHandlergetExceptionHandler()static InitializationgetInitialization()protected MyLoggingFacadegetMyLogger()static StringgetRequestIPAddress(javax.servlet.http.HttpServletRequest request)Make a valiant effort to get the IP address in the request.protected voidhandleException(ExceptionHandlerThingie exceptionHandlerThingie)One stop shopping for exception handling.voidinfo(String x)Write an informational message to the logvoidinit()booleanisDebugOn()Query if debugging is enabled for this logger.abstract voidloadEnvironment()Loads the current environment.voidlogOK(javax.servlet.http.HttpServletRequest request)For log messages that state a request from a servlet was ok.voidlogOK(javax.servlet.http.HttpServletRequest request, String message)For logging a success with a custom message.protected voidprintAllParameters(javax.servlet.http.HttpServletRequest request)Print all parameters to every request based on the global state of debugging.protected voidprintAllParameters(javax.servlet.http.HttpServletRequest request, MetaDebugUtil debugger)This will print all parameters to standard err for this specific debugger during trace.voidresetState()This nulls out the environment which should force a reload of it at the next call.static voidsetConfigurationLoader(ConfigurationLoader<? extends AbstractEnvironment> b)voidsetDebugOn(boolean setOn)Enable/disable debugging for this loggerstatic voidsetEnvironment(AbstractEnvironment env)voidsetExceptionHandler(ExceptionHandler exceptionHandler)static voidsetInitialization(Initialization initialization)voidwarn(String x)Write a warning to the log.- 
Methods inherited from class javax.servlet.http.HttpServletdoDelete, doHead, doOptions, doPut, doTrace, getLastModified, service, service
 
- 
 
- 
- 
- 
Field Detail- 
PING_PARAMETERpublic static final String PING_PARAMETER - See Also:
- Constant Field Values
 
 - 
initializationprotected static Initialization initialization 
 - 
environmentprotected static AbstractEnvironment environment 
 - 
IP_HEADERSprotected static final String[] IP_HEADERS 
 
- 
 - 
Method Detail- 
getInitializationpublic static Initialization getInitialization() 
 - 
setInitializationpublic static void setInitialization(Initialization initialization) 
 - 
getConfigurationLoaderpublic static ConfigurationLoader<? extends AbstractEnvironment> getConfigurationLoader() 
 - 
setConfigurationLoaderpublic static void setConfigurationLoader(ConfigurationLoader<? extends AbstractEnvironment> b) 
 - 
getEnvironmentpublic static AbstractEnvironment getEnvironment() 
 - 
setEnvironmentpublic static void setEnvironment(AbstractEnvironment env) 
 - 
loadEnvironmentpublic abstract void loadEnvironment() throws IOExceptionLoads the current environment. This is *not* called automatically. Usually a user will create a custom environment and have a getter for that which checks if the environment has been set and if not, load it or if so, cast it and return the result.- Throws:
- IOException
 
 - 
isDebugOnpublic boolean isDebugOn() Description copied from interface:LogableQuery if debugging is enabled for this logger.
 - 
setDebugOnpublic void setDebugOn(boolean setOn) Description copied from interface:LogableEnable/disable debugging for this logger- Specified by:
- setDebugOnin interface- Logable
 
 - 
getMyLoggerprotected MyLoggingFacade getMyLogger() 
 - 
debugpublic void debug(String x) Description copied from interface:LogableWrite a debug message to the log.
 - 
errorpublic void error(String x) Description copied from interface:LogableWrite an error message to the log. Typically this is invoked as the last command before throwing an exception.
 - 
infopublic void info(String x) Description copied from interface:LogableWrite an informational message to the log
 - 
warnpublic void warn(String x) Description copied from interface:LogableWrite a warning to the log. This indicates a severe, but non-fatal condition exists.
 - 
getExceptionHandlerpublic ExceptionHandler getExceptionHandler() 
 - 
handleExceptionprotected void handleException(ExceptionHandlerThingie exceptionHandlerThingie) throws IOException, javax.servlet.ServletException One stop shopping for exception handling. All thrown exceptions are intercepted and run through this. Depending on their type they are wrapped or passed along. You can change this behavior if you need to.Note that all runtime exceptions, IOExceptions and ServletExceptions are not modified, so if you over-ride this and throw one of those exceptions you will not get extra cruft. Also, a response is passed along. This may be used in over-rides, but is not used in the basic implementation. If it is null, it should be ignored. - Parameters:
- exceptionHandlerThingie-
- Throws:
- IOException
- javax.servlet.ServletException
 
 - 
setExceptionHandlerpublic void setExceptionHandler(ExceptionHandler exceptionHandler) 
 - 
doPostpublic void doPost(javax.servlet.http.HttpServletRequest httpServletRequest, javax.servlet.http.HttpServletResponse httpServletResponse) throws javax.servlet.ServletException, IOException- Overrides:
- doPostin class- javax.servlet.http.HttpServlet
- Throws:
- javax.servlet.ServletException
- IOException
 
 - 
doGetpublic void doGet(javax.servlet.http.HttpServletRequest httpServletRequest, javax.servlet.http.HttpServletResponse httpServletResponse) throws javax.servlet.ServletException, IOException- Overrides:
- doGetin class- javax.servlet.http.HttpServlet
- Throws:
- javax.servlet.ServletException
- IOException
 
 - 
doPingprotected boolean doPing(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws javax.servlet.ServletExceptionThis returns true or false for- Parameters:
- req-
- resp-
- Returns:
- Throws:
- javax.servlet.ServletException
 
 - 
doItprotected abstract void doIt(javax.servlet.http.HttpServletRequest httpServletRequest, javax.servlet.http.HttpServletResponse httpServletResponse) throws Throwable- Throws:
- Throwable
 
 - 
initpublic void init() throws javax.servlet.ServletException- Overrides:
- initin class- javax.servlet.GenericServlet
- Throws:
- javax.servlet.ServletException
 
 - 
resetStatepublic void resetState() This nulls out the environment which should force a reload of it at the next call. Put anything else you need nulled out here. This allows you to have, e.g., an updated configuration reloaded on the fly without a tomcat restart.
 - 
CONSTpublic static String CONST(String key) Utility to get constants or code gets really wordy.- Parameters:
- key-
- Returns:
 
 - 
printAllParametersprotected void printAllParameters(javax.servlet.http.HttpServletRequest request, MetaDebugUtil debugger)This will print all parameters to standard err for this specific debugger during trace. It gives a report on what is actually being passed in.- Parameters:
- request-
- debugger-
 
 - 
printAllParametersprotected void printAllParameters(javax.servlet.http.HttpServletRequest request) Print all parameters to every request based on the global state of debugging. It is a low-level debugging tool and should never be used in production, since it will bloat the logs. It gives a report on what is actually being passed in.- Parameters:
- request-
 
 - 
getRequestIPAddresspublic static String getRequestIPAddress(javax.servlet.http.HttpServletRequest request) Make a valiant effort to get the IP address in the request.- Parameters:
- request-
- Returns:
 
 - 
logOKpublic void logOK(javax.servlet.http.HttpServletRequest request) For log messages that state a request from a servlet was ok. Some clients require positive reporting for the number of successful calls too, so this can be used for that.- Parameters:
- request-
 
 - 
logOKpublic void logOK(javax.servlet.http.HttpServletRequest request, String message)For logging a success with a custom message. If you don't need a custom message, uselogOK(HttpServletRequest).- Parameters:
- request-
- message-
 
 
- 
 
-