Package com.helger.xservlet
Class AbstractXServlet
- java.lang.Object
-
- javax.servlet.GenericServlet
-
- javax.servlet.http.HttpServlet
-
- com.helger.xservlet.AbstractXServlet
-
- All Implemented Interfaces:
Serializable,javax.servlet.Servlet,javax.servlet.ServletConfig
@NotThreadSafe public abstract class AbstractXServlet extends javax.servlet.http.HttpServletAbstract HTTP based servlet. Compared to the defaultHttpServletthis class uses a handler map withEHttpMethodas the key.
The following features are added compared to the default servlet implementation:- It has counting statistics
- It has timing statistics
- It enforces a character set on the response
- It checks for known security attacks (like httpoxy)
- It has custom handler per HTTP method
- It has custom filter
- It has custom exception handler
- It handles Post-Redirect-Get centrally.
HttpServletto be usable with annotation based configuration in Jetty (was GenericServlet previously)- Since:
- 9.0.0
- Author:
- Philip Helger
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static StringREQUEST_ATTR_HANDLED_ASYNCInternal request attribute defining whether a request was handled asynchronously.static StringREQUEST_ATTR_SCOPE_CREATEDInternal request attribute defining whether a request scope was created or re-used
-
Constructor Summary
Constructors Constructor Description AbstractXServlet()Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddestroy()protected com.helger.commons.callback.CallbackList<IXServletExceptionHandler>exceptionHandler()protected com.helger.commons.collection.impl.ICommonsList<IXServletHighLevelFilter>filterHighLevelList()protected com.helger.commons.collection.impl.ICommonsList<IXServletLowLevelFilter>filterLowLevelList()protected ServletStatusManagergetServletStatusMgr()protected XServletHandlerRegistryhandlerRegistry()voidinit(javax.servlet.ServletConfig aSC)A final overload of "init".voidlog(String sMsg)voidlog(String sMsg, Throwable t)protected voidlogInvalidRequestSetup(String sMsg, javax.servlet.http.HttpServletRequest aHttpRequest)This method logs errors, in case a HttpServletRequest object is missing basic information or uses unsupported values for e.g.protected voidservice(javax.servlet.http.HttpServletRequest aHttpRequest, javax.servlet.http.HttpServletResponse aHttpResponse)Dispatches client requests to the protectedservicemethod.voidservice(javax.servlet.ServletRequest req, javax.servlet.ServletResponse res)XServletSettingssettings()StringtoString()-
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doGet, doHead, doOptions, doPost, doPut, doTrace, getLastModified
-
-
-
-
Field Detail
-
REQUEST_ATTR_HANDLED_ASYNC
public static final String REQUEST_ATTR_HANDLED_ASYNC
Internal request attribute defining whether a request was handled asynchronously. If this attribute is not present, it means synchronous- See Also:
- Constant Field Values
-
REQUEST_ATTR_SCOPE_CREATED
public static final String REQUEST_ATTR_SCOPE_CREATED
Internal request attribute defining whether a request scope was created or re-used- See Also:
- Constant Field Values
-
-
Method Detail
-
handlerRegistry
@Nonnull @ReturnsMutableObject protected final XServletHandlerRegistry handlerRegistry()
- Returns:
- The handler registry for HTTP method to handler registration. Never
null.
-
filterLowLevelList
@Nonnull @ReturnsMutableObject protected final com.helger.commons.collection.impl.ICommonsList<IXServletLowLevelFilter> filterLowLevelList()
- Returns:
- The internal filter list where custom filters can be added. Never
null.
-
filterHighLevelList
@Nonnull @ReturnsMutableObject protected final com.helger.commons.collection.impl.ICommonsList<IXServletHighLevelFilter> filterHighLevelList()
- Returns:
- The internal filter list where custom filters can be added. Never
null.
-
exceptionHandler
@Nonnull @ReturnsMutableObject protected final com.helger.commons.callback.CallbackList<IXServletExceptionHandler> exceptionHandler()
- Returns:
- The internal exception handler list. Never
null.
-
settings
public final XServletSettings settings()
- Returns:
- Settings for this servlet. May not be
null.
-
getServletStatusMgr
@Nonnull protected final ServletStatusManager getServletStatusMgr()
- Returns:
- The servlet status manager stored in the constructor. Never
null.
-
log
public final void log(String sMsg)
- Overrides:
login classjavax.servlet.GenericServlet
-
log
public final void log(String sMsg, Throwable t)
- Overrides:
login classjavax.servlet.GenericServlet
-
init
public final void init(@Nonnull javax.servlet.ServletConfig aSC) throws javax.servlet.ServletException
A final overload of "init". Overload "init" instead.- Specified by:
initin interfacejavax.servlet.Servlet- Overrides:
initin classjavax.servlet.GenericServlet- Throws:
javax.servlet.ServletException
-
destroy
@OverridingMethodsMustInvokeSuper public void destroy()
- Specified by:
destroyin interfacejavax.servlet.Servlet- Overrides:
destroyin classjavax.servlet.GenericServlet
-
logInvalidRequestSetup
@OverrideOnDemand protected void logInvalidRequestSetup(@Nonnull String sMsg, @Nonnull javax.servlet.http.HttpServletRequest aHttpRequest)
This method logs errors, in case a HttpServletRequest object is missing basic information or uses unsupported values for e.g. HTTP version and HTTP method.- Parameters:
sMsg- The concrete message to emit. May not benull.aHttpRequest- The current HTTP request. May not benull.
-
service
protected final void service(@Nonnull javax.servlet.http.HttpServletRequest aHttpRequest, @Nonnull javax.servlet.http.HttpServletResponse aHttpResponse) throws javax.servlet.ServletException, IOException
Dispatches client requests to the protectedservicemethod. There's no need to override this method.- Overrides:
servicein classjavax.servlet.http.HttpServlet- Parameters:
aHttpRequest- theHttpServletRequestobject that contains the request the client made of the servletaHttpResponse- theHttpServletResponseobject that contains the response the servlet returns to the client- Throws:
IOException- if an input or output error occurs while the servlet is handling the HTTP requestjavax.servlet.ServletException- if the HTTP request cannot be handled- See Also:
Servlet.service(javax.servlet.ServletRequest, javax.servlet.ServletResponse)
-
service
public final void service(@Nonnull javax.servlet.ServletRequest req, @Nonnull javax.servlet.ServletResponse res) throws javax.servlet.ServletException, IOException
- Specified by:
servicein interfacejavax.servlet.Servlet- Overrides:
servicein classjavax.servlet.http.HttpServlet- Throws:
javax.servlet.ServletExceptionIOException
-
-