0

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 Answers1

1

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)
Piotr P. Karwasz
  • 12,857
  • 3
  • 20
  • 43
  • Thank you for kindly reply! If I understood correct, all requests are going through Engine, Host, Context? I think the diagram has meaning to it and your advice helped me to draw starting point for learning. – bluenote1982 Sep 27 '21 at 18:42
  • Yes, `Engine` is the entry point of every request and if the request is valid (not a `404` error) it traverses a `Host`, `Context` and `Wrapper` component. – Piotr P. Karwasz Sep 27 '21 at 18:50
  • It helps me a lot. First button is well for beginning to learn. I appreciate your care, man! – bluenote1982 Sep 27 '21 at 18:52