A user account is required in order to edit this wiki, but we've had to disable public user registrations due to spam.
To request an account, ask an autoconfirmed user on Chat (such as one of these permanent autoconfirmed members).
Validator.nu Servlet Overview: Difference between revisions
(Create page) |
No edit summary |
||
(9 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
{{Obsolete|spec=https://github.com/validator/validator/wiki/System-»-Servlet}} | |||
==The <code>Main</code> Class== | ==The <code>Main</code> Class== | ||
Line 9: | Line 11: | ||
# Instantiates Jetty. | # Instantiates Jetty. | ||
# Sets up an HTTP or AJP13 connector. | # Sets up an HTTP or AJP13 connector. | ||
# Builds a servlet filter chain. | # Builds a servlet [[#The_Filters|filter]] chain. | ||
# Adds the servlet to the server. | # Adds the servlet to the server. | ||
# Starts the server. | # Starts the server. | ||
If you want to run the servlet in a larger the only mandatory step you need to take care of before the servlet loads is initializing log4j. The filter chain is optional (but without it some non-core features do not work; see below). | If you want to run the servlet in a larger application server, the only mandatory step you need to take care of before the servlet loads is initializing log4j. The [[#The_Filters|filter]] chain is optional (but without it some non-core features do not work; see below). | ||
==The Servlet== | ==The Servlet== | ||
Line 31: | Line 33: | ||
Implements response compression. | Implements response compression. | ||
===nu.validator.servletfilter.InboundSizeLimitFilter | ===<code>nu.validator.servletfilter.InboundSizeLimitFilter</code>=== | ||
This filter throws a <code>nu.validator.io.StreamBoundException</code> if the request entity body is too large. This filter throttles the input for <code>nu.validator.servletfilter.InboundGzipFilter</code> and <code>nu.validator.servlet.MultipartFormDataFilter</code>. If those filters are not in use, this one isn’t needed, either. | This filter throws a <code>nu.validator.io.StreamBoundException</code> if the request entity body is too large. This filter throttles the input for <code>nu.validator.servletfilter.InboundGzipFilter</code> and <code>nu.validator.servlet.MultipartFormDataFilter</code>. If those filters are not in use and the servlet container makes sure that POSTed content is really limited by <code>Content-Length</code> if present, this one isn’t needed, either. | ||
===<code>nu.validator.servletfilter.InboundGzipFilter</code>=== | ===<code>nu.validator.servletfilter.InboundGzipFilter</code>=== |
Latest revision as of 04:33, 29 December 2016
This document is obsolete.
For the current specification, see: https://github.com/validator/validator/wiki/System-»-Servlet
The Main
Class
Validator.nu has its own main()
method in a class called nu.validator.servlet.Main
. This makes makes debugging and isolated deployment an order of magnitude easier than doing XML situps to make application server load the right bits.
The main()
method does the following thing:
- Initializes log4j
- Instantiates
VerifierServletTransaction
to trigger its static initializer early. - Instantiates Jetty.
- Sets up an HTTP or AJP13 connector.
- Builds a servlet filter chain.
- Adds the servlet to the server.
- Starts the server.
If you want to run the servlet in a larger application server, the only mandatory step you need to take care of before the servlet loads is initializing log4j. The filter chain is optional (but without it some non-core features do not work; see below).
The Servlet
Validator.nu is encapsulated in one servlet: nu.validator.servlet.VerifierServlet
. This servlet handles the generic facet, the HTML5 facet and the parsetree facet and does URI dispatching and decides which controller class to instantiate.
Servlets are by default required to be re-entrant, so for programming convenience the servlet instantiates controller object whose lifetime is limited to one HTTP request.
The Filters
Some non-core features are implemented as servlet filters. These features are inbound and outbound gzip compression, support for HTML form-based file uploads and textarea-based input and limiting the input data size before performing decompression and before performing form POST decoding.
The filter from outer (closer to container) to inner (closer to the servlet) are:
org.mortbay.servlet.GzipFilter
Implements response compression.
nu.validator.servletfilter.InboundSizeLimitFilter
This filter throws a nu.validator.io.StreamBoundException
if the request entity body is too large. This filter throttles the input for nu.validator.servletfilter.InboundGzipFilter
and nu.validator.servlet.MultipartFormDataFilter
. If those filters are not in use and the servlet container makes sure that POSTed content is really limited by Content-Length
if present, this one isn’t needed, either.
nu.validator.servletfilter.InboundGzipFilter
Implements request decompression.
nu.validator.servlet.MultipartFormDataFilter
Implements support for HTML form-based file upload and textarea input by exposing these to the servet as if the document were POSTed straight as the entity body.
The Controllers
VerifierServletTransaction
The bulk of the Validator.nu UI controller and random glue that holds it all together is in nu.validator.servlet.VerifierServletTransaction
. This is probably the ugliest class in Validator.nu; UI-related code tends to be uglier than back end code and the class has grown organically over time.
Most of the initialization of Validator.nu is performed in the static initializer of this class. The default Main
triggers early initialization by instantiating this class once before starting the HTTP server.
Html5ConformanceCheckerTransaction
This is a subclass of VerifierServletTransaction
that tweaks the overall behavior just enough to implement the HTML5 facet of Validator.nu.
ParseTreePrinter
This is the controller for parsetree.validator.nu.