how_tomcat_works.pdf

Please download to get full document.

View again

of 81
All materials on our website are shared by users. If you have any questions about copyright issues, please report us to resolve them. We are always happy to assist you.
Categories
Published
Table of Contents 1. Introduction 2. A Simple Web Server i. The Hypertext Transfer Protocol (HTTP) ii. The Socket Class iii. The ServerSocket Class iv. The Application v. The HttpServer Class vi. The Request Class vii. The Response Class viii. Running the Application ix. Summary 3. A Simple Servlet Container i. The javax.servlet.Servlet Interface ii. Application 1 iii. The HttpServer1 Class iv. The Request Class v. The Response Class v
  1. Introduction2. A Simple Web Serveri. The Hypertext Transfer Protocol (HTTP)ii. The Socket Classiii. The ServerSocket Classiv. The Applicationv. The HttpServer Classvi. The Request Classvii. The Response Classviii. Running the Applicationix. Summary3. A Simple Servlet Containeri. The javax.servlet.Servlet Interfaceii. Application 1iii. The HttpServer1 Classiv. The Request Classv. The Response Classvi. The StaticResourceProcessor Class vii. The ServletProcessor1 Classviii. Running the Application ix. Application 2x. Summary4. Connector5. Tomcat Default Connector6. Container Table of Contents  Welcome to How Tomcat Works. This book dissects Tomcat 4.1.12 and 5.0.18 and explains the internal workings of itsfree, open source, and most popular servlet container code-named Catalina. Tomcat is a complex system, consisting ofmany different components. Those who want to learn how Tomcat works often do know where to start. What this bookdoes is provide the big picture and then build a simpler version of each component to make understanding thatcomponent easier. Only after that will the real component be explained.You should start by reading this Introduction as it explains the structure of the book and gives you the brief outline of theapplications built. The section Preparing the Prerequisite Software gives you instructions on what software you need todownload, how to make a directory structure for your code, etc.This book is for anyone working with the Java technology.This book is for you if you are a servlet/JSP programmer or a Tomcat user and you are interested in knowing how aservlet container works.It is for you if you want to join the Tomcat development team because you need to first learn how the existing code works.If you have never been involved in web development but you have interest in software development in general, thenyou can learn from this book how a large application such as Tomcat was designed and developed.If you need to configure and customize Tomcat, you should read this book.To understand the discussion in this book, you need to understand object-oriented programming in Java as well asservlet programming. If you are not familiar with the latter, there are a plethora of books on sendets, including Budi's Javafor the Web with Servlets, JSP, and EJB. To make the material easier to understand, each chapter starts with backgroundinformation that will be required to understand the topic in discussion.A servlet container is a complex system. However, basically there are three things that a servlet container does to servicea request for a servlet:Creating a request object and populate it with information that may be used by the invoked servlet, such asparameters, headers, cookies, query string, URI, etc. A request object is an instance of the javax.servlet.ServletRequest interface or the javax.servlet.http.ServletRequest interface.Creating a response object that the invoked servlet uses to send the response to the web client. A response object isan instance of the javax.servlet.ServletResponse interface or the javax.servlet.http.ServletResponse interface.Invoking the service method of the servlet, passing the request and response objects. Here the servlet reads thevalues from the request object and writes to the response object.As you read the chapters, you will find detailed discussions of Catalina servlet container.Catalina is a very sophisticated piece of software, which was elegantly designed and developed. It is also modular too.Based on the tasks mentioned in the section How A Servlet Container Works , you can view Catalina as consisting oftwo main modules: the connector and the container.The block diagram in Figure I.1 is, of course, simplistic. Later in the following chapters you will unveil all smallercomponents one by one.Figure I.1: Catalina's main modulesNow, back to Figure I.1, the connector is there to connect a request with the container. Its job is to construct a requestobject and a response object for each HTTP request it receives. It then passes processing to the container. The container OverViewWho This Book Is forHow A Servlet Container WorksCatalina Block Diagram  receives the request and response objects from the connector and is responsible for invoking the servlet's servicemethod.Bear in mind though, that the description above is only the tip of the iceberg. There are a lot of things that a containerdoes. For example, before it can invoke a servlet's service method, it must load the servlet, authenticate the user (ifrequired), update the session for that user, etc. It's not surprising then that a container uses many different modules forprocessing. For example, the manager module is for processing user sessions, the loader is for loading servlet classess,etc.This book covers both Tomcat 4 and 5. Here are some of the differences between the two:Tomcat 5 supports Servlet 2.4 and JSP 2.0 specifications, Tomcat 4 supports Servlet 2.3 and JSP 1.2.Tomcat 5 has a more efficient default connector than Tomcat 4.Tomcat 5 shares a thread for background processing whereas Tomcat 4'scomponents all have their own threads for background processing. Therefore, Tomcat 5 uses less resources in thisregard.Tomcat 5 does not need a mapper component to find a child component, therefore simplifying the code.There are 20 chapters in this book. The first two chapters serve as an introduction. Chapter 1 explains how an HTTPserver works and Chapter 2 features a simple servlet container. The next two chapters focus on the connector andChapters 5 to 20 cover each of the components in the container. The following is the summary of each of the chapters.Note For each chapter, there is an accompanying application similar to the component being explained. Chapter 1 starts this book by presenting a simple HTTP server. To build a working HTTP server, you need to know theinternal workings of two classes in the java.net package: Socket and ServerSocket. There is sufficient backgroundinformation in this chapter about these two classes for you to understand how the accompanying application works. Chapter 2 explains how simple servlet containers work. This chapter comes with two servlet container applications thatcan service requests for static resources as well as very simple servlets. In particular, you will learn how you can createrequest and response objects and pass them to the requested servlet's service method. There is also a servlet that canbe run inside the servlet containers and that you can invoke from a web browser. Chapter 3  presents a simplified version of Tomcat 4's default connector. The application built in this chapter serves as alearning tool to understand the connector discussed in Chapter 4. Chapter 4  presents Tomcat 4's default connector. This connector has been deprecated in favor of a faster connectorcalled Coyote. Nevertheless, the default connector is simpler and easier to understand. Chapter 5  discusses the container module. A container is represented by the org.apache.catalina.Container interfaceand there are four types of containers: engine, host, context, and wrapper. This chapter offers two applications that work with contexts and wrappers. Chapter 6  explains the Lifecycle interface. This interface defines the lifecycle of a Catalina component and provides anelegant way of notifying other components of events that occur in that component. In addition, the Lifecycle interfaceprovides an elegant mechanism for starting and stopping all the components in Catalina by one single start/stop. Chapter 7  covers loggers, which are components used for recording error messages and other messages. Chapter 8  explains about loaders. A loader is an important Catalina module responsible for loading servlet and otherclasses that a web application uses. This chapter also shows how application reloading is achieved. Chapter 9  discusses the manager, the component that manages sessions in session management. It explains thevarious types of managers and how a manager can persist session objects into a store. At the end of the chapter, you will Tomcat 4 and 5Overview of Each Chapter
We Need Your Support
Thank you for visiting our website and your interest in our free products and services. We are nonprofit website to share and download documents. To the running of this website, we need your help to support us.

Thanks to everyone for your continued support.

No, Thanks