Home > Tomcat Introduction > Tomcat Primer

Tomcat Primer

 

  

Tomcat Logo

 

 

 

Apache Origin:

Apache Tomcat (or Jakarta Tomcat or just Tomcat) is an open source servlet container started out as a reference implementation by Sun Microsystems and donated to the Apache Software Foundation (ASF). Tomcat implements the Java Servlet and the JavaServer Pages (JSP) specifications from Sun Microsystems, and provides a “pure Java” HTTP web server environment for Java code to run. Tomcat should not be confused with the Apache web server, which is a C implementation of an HTTP web server; these two web servers are not bundled together. Apache Tomcat includes tools for configuration and management, but can also be configured by editing XML configuration files.

Members of the ASF and independent volunteers develop and maintain Tomcat. Users have free access to the source code and to the binary form of Tomcat under the Apache License and hence is freely downloadable. The initial Tomcat release appeared with versions 3.0.x. Tomcat 6.0.20 is the latest production quality release of the 6.0.x trunk (based on 2.5 servlet specification).

Tomcat started off as a servlet reference implementation by James Duncan Davidson, a software architect at Sun Microsystems. He later helped make the project open source and played a key role in its donation by Sun to the Apache Software Foundation.

 

Tomcat Introduction:

Tomcat is a Java Servlet/JSP container and web server from the Jakarta project of the Apache software foundation. A web server dishes out web pages in response to requests from a user which typically is a web browser. But web servers are not limited to serving up static HTML pages; they can also run programs in response to user requests and return the dynamic results to the user’s browser. Tomcat is very good at this because it provides both Java servlet and JavaServerPages (JSP) technologies (in addition to traditional static pages and external CGI programming). Tomcat can be used as either a standalone product with its own internal Web server or together with other Web servers, including Apache, Netscape Enterprise Server, Microsoft Internet Information Server (IIS), and Microsoft Personal Web Server where the traditional server can be used to serve static pages and Tomcat can be used to serve dynamic servlet and JSP requests.

Tomcat is one of several open source collaborations called Jakarta. Tomcat requires a Java Runtime Enterprise Environment that conforms to JRE 1.1 or later. Developed under the Apache license in an open and participatory environment, Tomcat is intended to be a collaboration of the best-of-breed developers from around the world.

 

Some of the Tomcat and related definitions:

Apache:
“The Apache software foundation provides support for the Apache community of open-source software projects. The Apache projects are characterized by a collaborative, consensus based development process, an open and pragmatic software license, and a desire to create high quality software that leads the way in its field.” Amongst the projects that come under the “Apache” banner are the HTTP Web Server from which the whole Apache project has grown, and which is the container used for the majority of web sites worldwide, Ant (a build tool which allows the developer excellent control of the compiling and bundling processes), and Jakarta.

Jakarta:
“The Jakarta Project creates and maintains open source solutions on the Java platform for distribution to the public at no charge. Jakarta products are developed by and distributed through various sub-projects.” Jakarta is the name for the Apache project which deals with the provision of open source additions in Java. More than 20 such additions (known as sub-projects) are listed on their web site, including Struts and Tomcat.

Tomcat:
Tomcat is a servlet container for the Java Servlets and JavaServer Pages. It provides a Java Virtual Machine and associated elements to give a complete Java Runtime Environment, and it also provides web server software to make that environment accessible on the Web. Configuration and management tools are also provided, with configuration data largely held in XML. It’s worth noting that Tomcat is much more than just an implementation of Servlets and JSPs, it’s the official reference implementation and the standard against which all other suppliers of containers for Servlets and JSPs must measure their products. It means that developers know that if they develop code that works under Tomcat, that code should work under other containers that conform to the standards set.

 

 

Tomcat Architecture:

 

Tomcat Basic Architecture

 

Tomcat is a container that is made up of pluggable components that fit together in a nested manner. Tomcat is configurable, you can set such settings to use specialized filters, change port numbers and IP address bindings, security settings, etc. You should always change the default setting when using in a production environment especially the security aspects.

The most basic Tomcat concept is that of the container. Basically, a container is an object that handles requests from clients, performs some action, and returns responses. Containers can be nested and often the request processing is delegated to a child component for processing. The top-level component is the server itself. A server runs one or more services. A service consists of one or more connectors and an engine. A connector is responsible for client communication on a specific port using a specific protocol. There are various connectors available, but the most used are the HTTP port for browser clients, and the JK port for Apache integration.

 

 

Few of the components of Tomcat are:

Server:
The server is Tomcat, its an instance of the Web application server, it owns a port that is used to shutdown the server (port 8005). You can setup multiple servers on one node providing they use different ports. The server is an implementation of the Server interface, it implements the StandardServer object.

Catalina:
Catalina is Tomcat’s servlet container. Catalina implements Sun Microsystems’ specifications for servlet and JavaServer Pages (JSP). Craig McClanahan was the architect of Catalina.

Coyote:
Coyote is Tomcat’s HTTP Connector component that supports the HTTP 1.1 protocol for the web server or application container. Coyote listens for incoming connections on a specific TCP port on the server and forwards the request to the Tomcat Engine to process the request and send back a response to the requesting client.

Jasper:
Jasper is the JSP Engine that’s used inTomcat from version 4.1. Tomcat 5.x uses Jasper 2, which is an implementation of the Sun Microsystems’s JavaServer Pages 2.0 specification. Jasper parses JSP files to compile them into Java code as servlets (that can be handled by Catalina). At runtime, Jasper is able to automatically detect JSP file changes and recompile them.Service:
A service groups a container (usually an engine) with a set of Connectors. The service is responsible for accepting requests, routing them to the specified Web application and specific resources and then returning the result of the processing of the request, they are the middle man between the clients web browser and the container.

Connectors:
Connectors connect the applications to clients. They receive the incoming requests HTTP (port 8080) or AJP (port 8009) by default from the clients. The default connector is Coyote which implements HTTP 1.1.

Engine:
The engine is the top-level container, it cannot be contained by another container, thus this is the parent container for all the containers beneath it. The engine is a request-processing component that represents the Catalina Server Engine. It examines the HTTP headers to determine the virtual host or context to which requests should be passed. An engine may contain Hosts representing a group of Web applications and Contexts representing a single Web application i.e. a virtual host

Realm:
The realm for an engine manages user authentication and authorization. Resources uses roles to allow access, the realm enforces the security polices. A realm applies across the whole engine, however this can be overridden by using a realm at the Host level or the Context level, it a object that can be superceded by its children objects.

Valves:
Valves are used to intercept a request and preprocess it. They are similar to filter mechanism of the servlet specifications but are specific to Tomcat . They are used for single sign-on for all Hosts on a Server, log request patterns, client IP addresses, server usage patterns. You can have multiple Valves at its particular parent and are typically chained in the order they were added to the parent. This means that you may have Valves that depend on other Valves.

Loggers:
Loggers report on the internal state of a component. Logging behavior is inherited, so the logger from the engine is assigned to every child object unless overridden.

Host:
Hosts mimics the popular Apache virtual host concept, the Host contains a name and an IP address. You can multiple Hosts each with its own Web application.

Context:
The Context is the Web application, also known as a Context. You can enable dynamic reloading so that any classes that have been changed are reloaded into memory. The Context can also have specific error pages for each Web application, you can also setup initialization parameters to control access. The context implements the Context interface, most Context implementations are created with the StandardContext class. Because the Context itself is a container at the Web application level, it becomes the parent of servlets and filters, the Contexts add these children as StandardWrapper class.

 

Nested Tomcat Architecture

 

As requests come in from clients, the connectors hand them off to the engine for processing. The engine, in turn, delegates the requests to individual application objects, or contexts. These contexts represent particular domain names or IP addresses that resolve to the machine on which Tomcat is running.

Tomcat runs as a Windows service or a Linux or Unix Daemon, awaiting connections(by default) on port 8080. A single instance of Tomcat can provide several
services, though this is unusual. Each Tomcat service will have at least one (and possibly more) connectors, and at least one (and possibly more containers) in which an engine such as Catalina provides a service.

Server, Service, Connector, Container and Engine are all very flexibly configurable, and the default application configuration can be overridden on a per application basis if need be. The Tomcat Manager is a useful application which runs in one of the standard Tomcat containers and is used to control loading, reloading and unloading of individual applications or of the engine as a whole.

 

Lifecycle:

Tomcat starts and stops the components in the order that were started, thus when starting the parent gets started first then the children get started, stopping is the reserve order. This is done through the Lifecycle interface: LifecycleEvent and LifecycleListener.

The Lifecycle interface has two key methods start() and stop(), all major components usually contain a LifecycleSupport object that manages all of the LifecycleListener objects for that component, it is this object that propagates and fires general events. The top-level component calls all of its child’s start() methods, the reverse is true when stopping. This method allows to to stop/start Host components without affecting any other Hosts.

The LifecycleListener interface can be added at any level in the Tomcat container that can execute specific code when a particular event is fired. By default there are three listeners configured at the server level, they are configured in the server.xml or context.xml file at the specific level.

 

Configuration:

The most important file in Tomcat is the server.xml file, when Tomcat starts it uses a version of the Apache Commons Digester to read the file, the digester is a utility that reads XML file and creates Java objects from a set of rules. With what you have learned above you can see that the rules in the file follows Tomcat architecture exactly.

 

Links:

http://tomcat.apache.org/

 

Note: Refer to other posts in Tomcat category for further knowledge.

 

 

Advertisements
  1. Anonymous
    June 11, 2012 at 1:54 am

    Thanks for a through explanations 🙂

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: