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 Summary
Fields Modifier and Type Field Description protected static AbstractEnvironmentenvironmentprotected static Initializationinitializationprotected static String[]IP_HEADERSstatic StringPING_PARAMETER
-
Constructor Summary
Constructors Constructor Description AbstractServlet()
-
Method Summary
All 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.HttpServlet
doDelete, doHead, doOptions, doPut, doTrace, getLastModified, service, service
-
-
-
-
Field Detail
-
PING_PARAMETER
public static final String PING_PARAMETER
- See Also:
- Constant Field Values
-
initialization
protected static Initialization initialization
-
environment
protected static AbstractEnvironment environment
-
IP_HEADERS
protected static final String[] IP_HEADERS
-
-
Method Detail
-
getInitialization
public static Initialization getInitialization()
-
setInitialization
public static void setInitialization(Initialization initialization)
-
getConfigurationLoader
public static ConfigurationLoader<? extends AbstractEnvironment> getConfigurationLoader()
-
setConfigurationLoader
public static void setConfigurationLoader(ConfigurationLoader<? extends AbstractEnvironment> b)
-
getEnvironment
public static AbstractEnvironment getEnvironment()
-
setEnvironment
public static void setEnvironment(AbstractEnvironment env)
-
loadEnvironment
public 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
-
isDebugOn
public boolean isDebugOn()
Description copied from interface:LogableQuery if debugging is enabled for this logger.
-
setDebugOn
public void setDebugOn(boolean setOn)
Description copied from interface:LogableEnable/disable debugging for this logger- Specified by:
setDebugOnin interfaceLogable
-
getMyLogger
protected MyLoggingFacade getMyLogger()
-
debug
public void debug(String x)
Description copied from interface:LogableWrite a debug message to the log.
-
error
public 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.
-
info
public void info(String x)
Description copied from interface:LogableWrite an informational message to the log
-
warn
public void warn(String x)
Description copied from interface:LogableWrite a warning to the log. This indicates a severe, but non-fatal condition exists.
-
getExceptionHandler
public ExceptionHandler getExceptionHandler()
-
handleException
protected 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:
IOExceptionjavax.servlet.ServletException
-
setExceptionHandler
public void setExceptionHandler(ExceptionHandler exceptionHandler)
-
doPost
public void doPost(javax.servlet.http.HttpServletRequest httpServletRequest, javax.servlet.http.HttpServletResponse httpServletResponse) throws javax.servlet.ServletException, IOException- Overrides:
doPostin classjavax.servlet.http.HttpServlet- Throws:
javax.servlet.ServletExceptionIOException
-
doGet
public void doGet(javax.servlet.http.HttpServletRequest httpServletRequest, javax.servlet.http.HttpServletResponse httpServletResponse) throws javax.servlet.ServletException, IOException- Overrides:
doGetin classjavax.servlet.http.HttpServlet- Throws:
javax.servlet.ServletExceptionIOException
-
doPing
protected 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
-
doIt
protected abstract void doIt(javax.servlet.http.HttpServletRequest httpServletRequest, javax.servlet.http.HttpServletResponse httpServletResponse) throws Throwable- Throws:
Throwable
-
init
public void init() throws javax.servlet.ServletException- Overrides:
initin classjavax.servlet.GenericServlet- Throws:
javax.servlet.ServletException
-
resetState
public 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.
-
CONST
public static String CONST(String key)
Utility to get constants or code gets really wordy.- Parameters:
key-- Returns:
-
printAllParameters
protected 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-
-
printAllParameters
protected 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-
-
getRequestIPAddress
public static String getRequestIPAddress(javax.servlet.http.HttpServletRequest request)
Make a valiant effort to get the IP address in the request.- Parameters:
request-- Returns:
-
logOK
public 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-
-
logOK
public 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-
-
-