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
- Direct Known Subclasses:
SASServlet
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.
3/23/2012: Added simple bootstrapping mechanism. This requires you set a context listener in your web.xml deployment descriptor. See the documentation inBootstrapper
for 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 AbstractEnvironment
environment
protected static Initialization
initialization
protected static String[]
IP_HEADERS
static String
PING_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 boolean
checkContentType(String rawContentType, String contentType)
static String
CONST(String key)
Utility to get constants or code gets really wordy.void
debug(String x)
Write a debug message to the log.void
doGet(javax.servlet.http.HttpServletRequest httpServletRequest, javax.servlet.http.HttpServletResponse httpServletResponse)
protected abstract void
doIt(javax.servlet.http.HttpServletRequest httpServletRequest, javax.servlet.http.HttpServletResponse httpServletResponse)
protected boolean
doPing(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)
This returns true or false forvoid
doPost(javax.servlet.http.HttpServletRequest httpServletRequest, javax.servlet.http.HttpServletResponse httpServletResponse)
void
error(String x)
Write an error message to the log.void
error(String x, Throwable t)
static ConfigurationLoader<? extends AbstractEnvironment>
getConfigurationLoader()
static AbstractEnvironment
getEnvironment()
ExceptionHandler
getExceptionHandler()
static Initialization
getInitialization()
protected MyLoggingFacade
getMyLogger()
static String
getRequestIPAddress(javax.servlet.http.HttpServletRequest request)
Make a valiant effort to get the IP address in the request.protected void
handleException(ExceptionHandlerThingie exceptionHandlerThingie)
One stop shopping for exception handling.void
info(String x)
Write an informational message to the logvoid
init()
boolean
isDebugOn()
Query if debugging is enabled for this logger.abstract void
loadEnvironment()
Loads the current environment.void
logOK(javax.servlet.http.HttpServletRequest request)
For log messages that state a request from a servlet was ok.void
logOK(javax.servlet.http.HttpServletRequest request, String message)
For logging a success with a custom message.protected void
printAllParameters(javax.servlet.http.HttpServletRequest request)
Print all parameters to every request based on the global state of debugging.protected void
printAllParameters(javax.servlet.http.HttpServletRequest request, MetaDebugUtil debugger)
This will print all parameters to standard err for this specific debugger during trace.void
resetState()
This nulls out the environment which should force a reload of it at the next call.static void
setConfigurationLoader(ConfigurationLoader<? extends AbstractEnvironment> b)
void
setDebugOn(boolean setOn)
Enable/disable debugging for this loggerstatic void
setEnvironment(AbstractEnvironment env)
void
setExceptionHandler(ExceptionHandler exceptionHandler)
static void
setInitialization(Initialization initialization)
void
warn(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 IOException
Loads 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:Logable
Query if debugging is enabled for this logger.
-
setDebugOn
public void setDebugOn(boolean setOn)
Description copied from interface:Logable
Enable/disable debugging for this logger- Specified by:
setDebugOn
in interfaceLogable
-
getMyLogger
protected MyLoggingFacade getMyLogger()
-
debug
public void debug(String x)
Description copied from interface:Logable
Write a debug message to the log.
-
error
public void error(String x)
Description copied from interface:Logable
Write 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:Logable
Write an informational message to the log
-
warn
public void warn(String x)
Description copied from interface:Logable
Write 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:
IOException
javax.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:
doPost
in classjavax.servlet.http.HttpServlet
- Throws:
javax.servlet.ServletException
IOException
-
doGet
public void doGet(javax.servlet.http.HttpServletRequest httpServletRequest, javax.servlet.http.HttpServletResponse httpServletResponse) throws javax.servlet.ServletException, IOException
- Overrides:
doGet
in classjavax.servlet.http.HttpServlet
- Throws:
javax.servlet.ServletException
IOException
-
doPing
protected boolean doPing(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws javax.servlet.ServletException
This 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:
init
in 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
-
-
-