Apache Tomcat component hierarchy processing for each different access request

218 Views Asked by At

I'm learning Apache Tomcat and reading book about Tomcat 6. The first chapter is about fundamental components included in Tomcat 6. The diagram of the hierarchy depicts basic components are accordingly Server, Service, Engine, Host, Context, and Apache web server requests connection via Engine, IIS via Host, Web Browser via Context. I interpreted this way because each valve is within the box each component level as mentioned earlier in this question.

There seems hardly the document or book about this diagram. When apache web server, IIS, and web browser request connection to Tomcat, is it processed by different component as the above?

1

There are 1 best solutions below

3
Piotr P. Karwasz On

Absolutely not.

Basically every request received by Tomcat:

  1. Is processed by a Coyote connector (on multiple threads). The details depend on the connector,
  2. The connector ends up calling CoyoteAdapter#service on the thread chosen to service the request,
  3. The request passes through a series of valves in the Engine, Host, Context and Wrapper (which represents a single servlet) components,
  4. The FilterChain#doFilter method is called as in every servlet container.

You can shed some more light on the process, by throwing an exception in a servlet and dissecting the call stack:

SEVERE: Servlet.service() for servlet [pl.copernik.servlet.HelloServlet] in context with path [/servlet-test] threw exception [null] with root cause
jakarta.servlet.ServletException
    at pl.copernik.servlet.HelloServlet.doGet(HelloServlet.java:25)
    *** Servlet API: ***
    at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:665)
    at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:774)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:223)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:158)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:185)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:158)
    *** Catalina Valves: ***
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:197)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:543)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:119)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:353)
    *** Coyote connector details: ***
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:382)
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:870)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1699)
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    *** Thread pool details: ***
    at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191)
    at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.base/java.lang.Thread.run(Thread.java:829)