+ All Categories
Home > Documents > Apache Tomcat (Tomcat, formerly also Jakarta Tomcat)

Apache Tomcat (Tomcat, formerly also Jakarta Tomcat)

Date post: 06-Apr-2018
Category:
Upload: mukesh
View: 278 times
Download: 1 times
Share this document with a friend

of 43

Transcript
  • 8/2/2019 Apache Tomcat (Tomcat, formerly also Jakarta Tomcat)

    1/43

    1

    Jakarta Tomcat:

    A look inside a servlet container

  • 8/2/2019 Apache Tomcat (Tomcat, formerly also Jakarta Tomcat)

    2/43

    2

    What well cover:

    History of Tomcat

    Relationship to J2EE

    Tomcat Features

    Tomcat Architecture

  • 8/2/2019 Apache Tomcat (Tomcat, formerly also Jakarta Tomcat)

    3/43

    3

    In the beginning..

    Web servers serving static html

    Web servers using cgi for dynamic content

    Modules to handle dynamic content

    Ex: Apache and Mod-Perl

    Then along came servlets

  • 8/2/2019 Apache Tomcat (Tomcat, formerly also Jakarta Tomcat)

    4/43

    4

    Web Containers Using Servlets

    and JSPs

    Java alternative to CGI

    Servlets - Java with a bit of HTML thrown in

    JSPs (JavaServer Pages) - HTML with a bit ofJava thrown in

    JSP converted to a Servlet the first time accessed

    Servlets stay in memory - big plus over CGI

  • 8/2/2019 Apache Tomcat (Tomcat, formerly also Jakarta Tomcat)

    5/43

    5

    History of Tomcat

    Java Web Server First servlet container

    Created by Sun to demonstrate Servlet technology

    Jserv Integrated with Apaches web server

    Created by ASF (Apache Software Foundation)

    Tomcat 3.x Merger of Java Web Server & Jserv

    Reference implementation of Servlet & JSP specs

  • 8/2/2019 Apache Tomcat (Tomcat, formerly also Jakarta Tomcat)

    6/43

    6

    History of Tomcat (cont)

    Tomcat 4.0 released in 2001

    Major architecture overhaul

    Tomcat 5.x the most recent version

    Builds on version 4

    Updated to implement Suns latest Servlet & JSPspecifications

  • 8/2/2019 Apache Tomcat (Tomcat, formerly also Jakarta Tomcat)

    7/43

    7

    How does this fit into J2EE?

    What is J2EE? Java 2, Enterprise Edition

    For creating distributed applications

    Open standard created by Sun

    For application servers and apps that connect to them

    Components of a J2EE application server:

    Deployment tools EJB container - session beans, entity beans

    Servlet container - servlets and JSPs

    Web server - html pages

  • 8/2/2019 Apache Tomcat (Tomcat, formerly also Jakarta Tomcat)

    8/43

    8

    J2EE (cont)

    Examples of J2EE application servers

    BEA Weblogic

    IBM WebsphereJboss

    Tomcat & J2EE

    Just implements the servlet container and webserver portions of the specification

    Not a full-fledged application server

  • 8/2/2019 Apache Tomcat (Tomcat, formerly also Jakarta Tomcat)

    9/43

    9

    Tomcat Features

    Runs as a service (Windows) or daemon(Unix)

    Run stand-alone or on beefier web server

    Manager Application provides tools: Deploy, undeploy, list, start and stop applications

    Shared hosting - handling multiple sites

    Clustering - running multiple instances For scalability and availability

  • 8/2/2019 Apache Tomcat (Tomcat, formerly also Jakarta Tomcat)

    10/43

    10

    How Does Tomcat Work?

    Nested hierarchy of components:

    Top-level components - containers

    Nested components - reside in containers anddo not contain other components

    Components are all configurable

    Not all components are required

  • 8/2/2019 Apache Tomcat (Tomcat, formerly also Jakarta Tomcat)

    11/43

    11

    Directory Structure

    bin

    Start and Stop Server

    Scripts + useful Toolscommon

    common used classesand libraries (Tomcat

    and Applications)conf

    Config files of Tomcat

  • 8/2/2019 Apache Tomcat (Tomcat, formerly also Jakarta Tomcat)

    12/43

    12

    Directory Structure

    logs

    Logs all log files of

    Tomcat

    server

    classes and libraries only

    for Tomcat + system Web

    applications, e.g. the

    manager App or the

    Admin Tool

  • 8/2/2019 Apache Tomcat (Tomcat, formerly also Jakarta Tomcat)

    13/43

    13

    Directory Structure

    shared

    classes and libraries only forWeb applications

    tempthe JVM temporary files putshere

    webapps

    contains all user-defined Webapplications

    work

    contains temporary files ofTomcat, e.g. to Servletscompiled JSP files

  • 8/2/2019 Apache Tomcat (Tomcat, formerly also Jakarta Tomcat)

    14/43

    14

    Directory Structure

  • 8/2/2019 Apache Tomcat (Tomcat, formerly also Jakarta Tomcat)

    15/43

    15

    Simple Servlet Container

    Client1

    Client2

    Client3

    Servlet1

    Servlet2

    Servlet Container

  • 8/2/2019 Apache Tomcat (Tomcat, formerly also Jakarta Tomcat)

    16/43

    16

    Tomcat Components

    Server

    Service

    Connectors

    Engine

    Realm

    Valves

    Logger

    Host

    Context

  • 8/2/2019 Apache Tomcat (Tomcat, formerly also Jakarta Tomcat)

    17/43

    17

    The Major Components

    Service - has one or more connectors

    and one or more containersCatalina - the servlet container

    Jasper - the JSP engine

    Coyote - the web connector

  • 8/2/2019 Apache Tomcat (Tomcat, formerly also Jakarta Tomcat)

    18/43

    18

    The Connector

    Manages the connection between

    applications and clients

    Point at which client requests are received

    Implements org.apache.catalina.Connector

    Example implementations:

    Coyote (HTTP) - the default

    Apache Jserv Protocol (SSL)

  • 8/2/2019 Apache Tomcat (Tomcat, formerly also Jakarta Tomcat)

    19/43

    19

    The Connector (cont)

    Waits for incoming HTTP requests

    Parses HTTP request headers

    Creates request and response objects

    Passes these objects to the container

    Default port for HTTP apps is 8080 but can

    change it to 80 for stand-alone mode

  • 8/2/2019 Apache Tomcat (Tomcat, formerly also Jakarta Tomcat)

    20/43

    20

    The Container/Engine

    Request processing component

    Passes the request and response objects

    from connector to the servlet

    Implements org.apache.catalina.Container

    Catalina is the default implementation

  • 8/2/2019 Apache Tomcat (Tomcat, formerly also Jakarta Tomcat)

    21/43

    21

    The Container/Engine (cont)

    Passes objects to the Servlet through service()

    On first request for a servlet, the container:

    loads the servlet classcalls the servlets init() method

    calls servlets service() method

    On subsequent requests for the servlet the

    container only calls service()

  • 8/2/2019 Apache Tomcat (Tomcat, formerly also Jakarta Tomcat)

    22/43

    22

    Servlet Lifecycle in Tomcat

    Container instantiates the Servlet and callsinit()

    Container gets a request and calls service()The Servlet receives HttpServletRequest

    and HttpServletResponse objects

    Servlet finds HTTP request data in therequest object - ex: form data, cookies,headers

  • 8/2/2019 Apache Tomcat (Tomcat, formerly also Jakarta Tomcat)

    23/43

    23

    Servlet Lifecyle (cont)

    Servlet processes the data and writes

    output to the response object

    Container passes the response object backto the connector

    Connector sends reply back to client

    Container calls destroy() before removing

    a servlet instance

  • 8/2/2019 Apache Tomcat (Tomcat, formerly also Jakarta Tomcat)

    24/43

    24

    Why Tomcat?

    Highly configurable

    Modular design

    means you cancustomize it by

    writing your own

    modules

    No longer just areference

    implementation

  • 8/2/2019 Apache Tomcat (Tomcat, formerly also Jakarta Tomcat)

    25/43

    25

    Server Configuration Reference

    Configuration directives that can be included ina conf/server.xml file to configure the behaviorof the Tomcat 4 servlet/JSP container

    The configuration element descriptions areorganized into the following major categories:

    Top Level Elements - is theroot element of the entire configuration

    file, while represents a groupof Connectors that is associated with anEngine.

    Connectors - Represent the interfacebetween external clients sending requeststo (and receiving responses from) aparticular Service.

    Containers - Represent componentswhose function is to process incoming

    requests, and create the correspondingresponses. An Engine handles all requestsfor a Service, a Host handles all requestsfor a particular virtual host, and a Contexthandles all requests for a specific webapplication.

    Nested Components - Representelements that can be nested inside theelement for a Container. Some elementscan be nested inside any Container, while

    others can only be nested inside a Context

  • 8/2/2019 Apache Tomcat (Tomcat, formerly also Jakarta Tomcat)

    26/43

    26

    The Server Component

    A Server element represents the entire

    Catalina servlet container. Therefore, it must

    be the single outermost element in theconf/server.xml configuration file. Its

    attributes represent the characteristics of the

    servlet container as a whole.

  • 8/2/2019 Apache Tomcat (Tomcat, formerly also Jakarta Tomcat)

    27/43

    27

    Common Attributes

    All implementations ofServer support the

    following attributes

    Attribute DescriptionclassName Java class name of the implementation to use. This

    class must implement the org.apache.catalina.Server

    interface. If no class name is specified, the standardimplementation will be used

    port The TCP/IP port number on which this server waitsfor a shutdown command. This connection must be

    initiated from the same server computer that is

    running this instance of Tomcat

    shutdown The command string that must be received via aTCP/IP connection to the specified port number, inorder to shut down Tomcat

  • 8/2/2019 Apache Tomcat (Tomcat, formerly also Jakarta Tomcat)

    28/43

    28

    Standard Implementation The standard implementation of

    Server isorg.apache.catalina.core.StandardServer. It

    supports the following additional attributes (in addition to

    the common attributes listed above):

    Attribute Description

    debug The level of debugging detail logged by thisServer to the associated Logger. Higher numbers

    generate more detailed output. If not specified, thedefault debugging detail level is zero (0).

    http://jakarta.apache.org/tomcat/tomcat-4.1-doc/config/logger.htmlhttp://jakarta.apache.org/tomcat/tomcat-4.1-doc/config/logger.html
  • 8/2/2019 Apache Tomcat (Tomcat, formerly also Jakarta Tomcat)

    29/43

    29

    Nested Components

    The following components may be nested

    inside a Server element:

    Service - One or more service element.GlobalNamingResources - Configure the

    JNDI global resources for the server

    http://jakarta.apache.org/tomcat/tomcat-4.1-doc/config/service.htmlhttp://jakarta.apache.org/tomcat/tomcat-4.1-doc/config/globalresources.htmlhttp://jakarta.apache.org/tomcat/tomcat-4.1-doc/config/globalresources.htmlhttp://jakarta.apache.org/tomcat/tomcat-4.1-doc/config/service.html
  • 8/2/2019 Apache Tomcat (Tomcat, formerly also Jakarta Tomcat)

    30/43

    30

    The Service Component

    A Service element represents the

    combination of one or more Connector

    components that share a single Enginecomponent for processing incoming

    requests. One or more Service elements

    may be nested inside a Server element.

    http://jakarta.apache.org/tomcat/tomcat-4.1-doc/config/engine.htmlhttp://jakarta.apache.org/tomcat/tomcat-4.1-doc/config/server.htmlhttp://jakarta.apache.org/tomcat/tomcat-4.1-doc/config/server.htmlhttp://jakarta.apache.org/tomcat/tomcat-4.1-doc/config/engine.html
  • 8/2/2019 Apache Tomcat (Tomcat, formerly also Jakarta Tomcat)

    31/43

    31

    Common Attributes

    Attribute DescriptionclassName Java class name of the implementation to use. This class

    must implement the org.apache.catalina.Service

    interface. If no class name is specified, the standardimplementation will be used

    name The display name of this Service, which will be included

    in log messages if you utilize standard Catalina

    components. The name of each Service that is associated

    with a particular Server must be unique

    S d d I l i Th d d i l i f

    http://jakarta.apache.org/tomcat/tomcat-4.1-doc/config/server.htmlhttp://jakarta.apache.org/tomcat/tomcat-4.1-doc/config/server.html
  • 8/2/2019 Apache Tomcat (Tomcat, formerly also Jakarta Tomcat)

    32/43

    32

    Standard ImplementationThe standard implementation of

    Service isorg.apache.catalina.core.StandardService. It

    supports the following additional attributes (in addition to

    the common attributes listed above):

    Attribute Description

    debug The level of debugging detail logged by

    this Service to the associated Logger.Higher numbers generate more detailed

    output. If not specified, the default

    debugging detail level is zero (0).

    http://jakarta.apache.org/tomcat/tomcat-4.1-doc/config/logger.htmlhttp://jakarta.apache.org/tomcat/tomcat-4.1-doc/config/logger.html
  • 8/2/2019 Apache Tomcat (Tomcat, formerly also Jakarta Tomcat)

    33/43

    33

    Nested Components

    The only components that may be nested

    inside a Service element are one or more

    Connector elements, followed by exactlyone Engine element

    http://jakarta.apache.org/tomcat/tomcat-4.1-doc/config/engine.htmlhttp://jakarta.apache.org/tomcat/tomcat-4.1-doc/config/engine.html
  • 8/2/2019 Apache Tomcat (Tomcat, formerly also Jakarta Tomcat)

    34/43

    34

    The Context Container

    The Context element represents a web application, which is run within aparticular virtual host

    The web application used to process each HTTP request is selected byCatalina based on matching the Request URI against the context path of eachdefined Context. Once selected, that Context will select an appropriate

    servlet to process the incoming request, according to the servlet mappingsdefined in the web application deployment descriptorfile (which MUST belocated at /WEB-INF/web.xml within the web app's directory hierarchy).

    You may define as many Context elements as you wish, nested within aHost element in conf/server.xml. Each such Context MUST have a uniquecontext path, which is defined by the path attribute

    In addition, you MUST define a Context with a context path equal to a zero-

    length string. This Context becomes the defaultweb application for thisvirtual host, and is used to process all requests that do not match any otherContext's context path.

    C Att ib t

    http://jakarta.apache.org/tomcat/tomcat-4.1-doc/config/host.htmlhttp://jakarta.apache.org/tomcat/tomcat-4.1-doc/config/host.html
  • 8/2/2019 Apache Tomcat (Tomcat, formerly also Jakarta Tomcat)

    35/43

    35

    Common Attributes

    All implementations of Context support the

    following attributes

    Attribute DescriptionclassName Java class name of the implementation to use. This class

    must implement the org.apache.catalina.Context

    interface. If not specified, the standard value (definedbelow) will be used.

    cookies Set to true if you want cookies to be used for session

    identifier communication if supported by the client (this

    is the default). Set to false if you want to disable the use

    of cookies for session identifier communication, and rely

    only on URL rewriting by the application

    docBase The Document Base (also known as the Context Root)directory for this web application, or the pathname to the

    web application archive file (if this web application is

    being executed directly from the WAR file).

    C Att ib t

  • 8/2/2019 Apache Tomcat (Tomcat, formerly also Jakarta Tomcat)

    36/43

    36

    Common Attributes

    All implementations of Context support the

    following attributes

    Attribute Descriptionpath The context path of this web application, which is

    matched against the beginning of each request URI to

    select the appropriate web application for processing. Allof the context paths within a particular Host must be

    unique. If you specify a context path of an empty string

    (""), you are defining the default web application for this

    Host, which will process all requests not assigned to

    other Contexts

    http://jakarta.apache.org/tomcat/tomcat-4.1-doc/config/host.htmlhttp://jakarta.apache.org/tomcat/tomcat-4.1-doc/config/host.html
  • 8/2/2019 Apache Tomcat (Tomcat, formerly also Jakarta Tomcat)

    37/43

    37

    The Engine Container

    The Engine element represents the entire requestprocessing machinery associated with a particularCatalina Service. It receives and processes all

    requests from one or more Connectors, andreturns the completed response to the Connectorfor ultimate transmission back to the client

    Exactly one Engine element MUST be nested

    inside a Service element, following all of thecorresponding Connector elements associatedwith this Service..

    C Att ib t

    http://jakarta.apache.org/tomcat/tomcat-4.1-doc/config/service.htmlhttp://jakarta.apache.org/tomcat/tomcat-4.1-doc/config/service.htmlhttp://jakarta.apache.org/tomcat/tomcat-4.1-doc/config/service.htmlhttp://jakarta.apache.org/tomcat/tomcat-4.1-doc/config/service.html
  • 8/2/2019 Apache Tomcat (Tomcat, formerly also Jakarta Tomcat)

    38/43

    38

    Common Attributes

    All implementations of Engine support the

    following attributes:

    Attribute Description

    defaultHost The default host name, which identifies the Host thatwill process requests directed to host names on this

    server, but which are not configured in this configurationfile. This name MUST match the name attributes of one

    of the Host elements nested immediately inside

    name Logical name of this Engine, used in log and errormessages

    http://jakarta.apache.org/tomcat/tomcat-4.1-doc/config/host.htmlhttp://jakarta.apache.org/tomcat/tomcat-4.1-doc/config/host.htmlhttp://jakarta.apache.org/tomcat/tomcat-4.1-doc/config/host.htmlhttp://jakarta.apache.org/tomcat/tomcat-4.1-doc/config/host.html
  • 8/2/2019 Apache Tomcat (Tomcat, formerly also Jakarta Tomcat)

    39/43

    39

    Nested Components

    You can nest one or more Host elements inside this Engine element,each representing a different virtual host associated with this server.At least one Host is required, and one of the nested Hosts MUSThave a name that matches the name specified for the defaultHostattribute, listed above

    You can nest at most one instance of the following utilitycomponents by nesting a corresponding element inside your Engineelement Logger - Configure a logger that will receive and process all log

    messages for this Engine, plus messages from Connectors associatedwith this Engine in the surrounding Service. In addition, this Logger will

    log messages from subordinate Hosts and Contexts, unless overridden bya Logger configuration at a lower level.

    Realm - Configure a realm that will allow its database of users, and theirassociated roles, to be shared across all Hosts and Contexts nested insidethis Engine, unless overridden by a Realm configuration at a lower level.

    http://jakarta.apache.org/tomcat/tomcat-4.1-doc/config/host.htmlhttp://jakarta.apache.org/tomcat/tomcat-4.1-doc/config/host.htmlhttp://jakarta.apache.org/tomcat/tomcat-4.1-doc/config/host.htmlhttp://jakarta.apache.org/tomcat/tomcat-4.1-doc/config/logger.htmlhttp://jakarta.apache.org/tomcat/tomcat-4.1-doc/config/host.htmlhttp://jakarta.apache.org/tomcat/tomcat-4.1-doc/config/context.htmlhttp://jakarta.apache.org/tomcat/tomcat-4.1-doc/config/logger.htmlhttp://jakarta.apache.org/tomcat/tomcat-4.1-doc/config/realm.htmlhttp://jakarta.apache.org/tomcat/tomcat-4.1-doc/config/host.htmlhttp://jakarta.apache.org/tomcat/tomcat-4.1-doc/config/context.htmlhttp://jakarta.apache.org/tomcat/tomcat-4.1-doc/config/realm.htmlhttp://jakarta.apache.org/tomcat/tomcat-4.1-doc/config/realm.htmlhttp://jakarta.apache.org/tomcat/tomcat-4.1-doc/config/context.htmlhttp://jakarta.apache.org/tomcat/tomcat-4.1-doc/config/host.htmlhttp://jakarta.apache.org/tomcat/tomcat-4.1-doc/config/realm.htmlhttp://jakarta.apache.org/tomcat/tomcat-4.1-doc/config/logger.htmlhttp://jakarta.apache.org/tomcat/tomcat-4.1-doc/config/context.htmlhttp://jakarta.apache.org/tomcat/tomcat-4.1-doc/config/host.htmlhttp://jakarta.apache.org/tomcat/tomcat-4.1-doc/config/logger.htmlhttp://jakarta.apache.org/tomcat/tomcat-4.1-doc/config/host.htmlhttp://jakarta.apache.org/tomcat/tomcat-4.1-doc/config/host.htmlhttp://jakarta.apache.org/tomcat/tomcat-4.1-doc/config/host.html
  • 8/2/2019 Apache Tomcat (Tomcat, formerly also Jakarta Tomcat)

    40/43

    40

    The Host Container

    The Host element represents a virtual host,

    which is an association of a network name

    for a server (such as"www.mycompany.com" with the

    particular server on which Catalina is

    running

    C A ib

  • 8/2/2019 Apache Tomcat (Tomcat, formerly also Jakarta Tomcat)

    41/43

    41

    Common AttributesAll implementations of Host support the following

    attributes:

    Attribute Description

    appBase The Application Base directory for this virtual host. Thisis the pathname of a directory that may contain web

    applications to be deployed on this virtual host. You mayspecify an absolute pathname for this directory, or a

    pathname that is relative to the $CATALINA_HOME

    directory.

    name Network name of this virtual host. One of the Hostsnested within an Engine MUST have a name that

    matches the defaultHost setting for that Engine.

    http://jakarta.apache.org/tomcat/tomcat-4.1-doc/config/engine.htmlhttp://jakarta.apache.org/tomcat/tomcat-4.1-doc/config/engine.html
  • 8/2/2019 Apache Tomcat (Tomcat, formerly also Jakarta Tomcat)

    42/43

    42

    Nested Components

    You can nest one or more Context elements inside this Hostelement, each representing a different web application associatedwith this virtual host. In addition, you can nest a singleDefaultContext element that defines default values forsubsequently deployed web applications.

    You can nest at most one instance of the following utilitycomponents by nesting a corresponding element inside your Hostelement

    Logger - Configure a logger that will receive and process alllog messages for this Host, plus messages from Contextsassociated with this Host .

    Realm - Configure a realm that will allow its database ofusers, and their associated roles, to be shared across allContexts nested inside this Host

    http://jakarta.apache.org/tomcat/tomcat-4.1-doc/config/context.htmlhttp://jakarta.apache.org/tomcat/tomcat-4.1-doc/config/defaultcontext.htmlhttp://jakarta.apache.org/tomcat/tomcat-4.1-doc/config/logger.htmlhttp://jakarta.apache.org/tomcat/tomcat-4.1-doc/config/context.htmlhttp://jakarta.apache.org/tomcat/tomcat-4.1-doc/config/realm.htmlhttp://jakarta.apache.org/tomcat/tomcat-4.1-doc/config/context.htmlhttp://jakarta.apache.org/tomcat/tomcat-4.1-doc/config/context.htmlhttp://jakarta.apache.org/tomcat/tomcat-4.1-doc/config/realm.htmlhttp://jakarta.apache.org/tomcat/tomcat-4.1-doc/config/context.htmlhttp://jakarta.apache.org/tomcat/tomcat-4.1-doc/config/logger.htmlhttp://jakarta.apache.org/tomcat/tomcat-4.1-doc/config/defaultcontext.htmlhttp://jakarta.apache.org/tomcat/tomcat-4.1-doc/config/context.html
  • 8/2/2019 Apache Tomcat (Tomcat, formerly also Jakarta Tomcat)

    43/43

    References

    How Tomcat Works: A Guide to DevelopingYour Own Java Servlet Container

    (Kurniawan & Deck)

    J2EE 1.4: The Big Picture (Haugland, Cade, & Orapallo)

    Java Extreme Programming Cookbook (Burke & Coyner)

    The Apache Jakarta Tomcat Website (http://jakarta.apache.org/tomcat/)

    Tomcat-Einfuehrung.pdf

    http://jakarta.apache.org/tomcat/http://jakarta.apache.org/tomcat/

Recommended