Preface
Current books on Tomcat are primarily focused on the application deployer or administrator. As a result, they invariably focus on the issues related to managing a Tomcat installation, configuring the runtime environment, and on deploying web applications.
On the other hand, while books on servlet programming are targeted at Java web developers, they often provide a container-agnostic view of the servlet specification. Tomcat is often a bit player in these books and has very few speaking lines.
This book fills the void between these two approaches.
It will take you on a guided tour of a living implementation of an industrial-strength servlet container.
Along the way, you will learn how various elements of the Servlet 2.5 specification as well as how the HTTP RFCs are implemented.
By the end of your journey, you will have acquired specialist grade skills in a range of technologies that contribute to the arena of Java server-side development.
This book intended to provide Tomcat administrators, deployers, and developers an introduction into the internal workings of the Tomcat servlet container.
At the same time, it provides Java web programmers with a deep appreciation of the Servlet API by exploring its reference implementation—the Tomcat container.
While this book provides you with the conceptual background of all that is necessary to take your skills to the next level, it assumes that the reader has a general understanding of the Java programming language and Java web programming.
What this book covers
Chapter 1—Introduction to Tomcat introduces you to the Tomcat container and provides you with the tools necessary to begin to take it apart. The key objective of this chapter is to allow you to make a current source distribution of Tomcat active in a development environment (Eclipse Galileo) so that you can trace the path that a request takes through the container's code.
Chapter 2—Servlet API Overview provides the prerequisite information necessary to navigate the remainder of the book. It describes the Java Enterprise Edition Platform, the HTTP protocol, and the Servlet API, and serves as a refresher for those who are already familiar with Java EE web development.
Chapter 3—Servlet Container Overview introduces the reader to the Tomcat container. This is the 10,000 foot overview of the container that provides a backdrop to the chapters that follow. All the components of Tomcat are described with just enough detail, so as not to overwhelm the reader with too much information, too early in the process.
Chapter 4—Starting up Tomcat takes a closer look at the startup process for Tomcat. This is also where you will be first introduced to the Apache Digester project—a key component that we will revisit in later chapters. The chapter ends with an example that demonstrates how a web application can be deployed to a dissected Tomcat container living within an Integrated Development Environment.
Chapter 5—The Server and Service Components discusses the Server
component and investigates one of its key services—an implementation of the Java Naming and Directory Interface (JNDI) API. We are also introduced to the Lifecycle
interface that almost every component within Tomcat implements in order to participate in a standardized event based listener mechanism. To show JNDI in action, our example considers connecting to a MySQL database to retrieve data.
Chapter 6—The Connector Component introduces our first Tomcat luminary, the Coyote Connector. We take a closer look at the standard Java I/O implementation of an HTTP connector. In this chapter, we get a closer look at socket programming, advanced elements of the HTTP protocol, and the internals of the request processing mechanism.
Chapter 7—The Engine Component describes the first request processing 'Container' within Tomcat and gives us an inkling of things to come. We are also introduced to the Pipeline
and its Valves
, which are the standard request processing mechanism for Tomcat components.
Chapter 8—The Host Component discusses the Tomcat implementation of a Virtual Host. This is the key component responsible for the deployment of web application contexts, as well as for the error page mechanism.
Chapter 9—The Context Component is at the central core of this book. You get an up-close-and-personal look at how a Context
is configured, how it accesses its resources, and how it implements its class loading magic.
Chapter 10—The Wrapper Component takes us to the workhorse of the Tomcat component hierarchy. This component wraps an actual servlet, and as a result is close to a web developer's heart. In addition to reviewing the mapping rules dictated by the Servlet API, we also look at the implementation of servlet filters and the request dispatcher mechanism.
Chapter 11—The Session Component discusses how sessions are implemented in Tomcat to enable stateful behavior over the stateless HTTP protocol. In addition to looking at some core concepts, such as Java serialization and entropy gathering for random number generation, we look at the standard memory based session implementation, as well as an implementation that uses files to persist sessions.
What you need for this book
You should have knowledge of the Java programming language and web development on the Java platform.
Who this book is for
This book is written for the following classes of readers:
1. Web developers who want to take their programming skills to the next level.
2. Server administrators who want to get a better understanding of the software they manage.
3. Hobbyists who want to contribute to the Tomcat project.
4. Academics and students who want to look at a production grade web server and servlet container from the inside out.
5. Open source auditors who want to understand whether a particular open source project passes audit for usage in highly secure environments or not.
6. Developers who want to understand how to architect high availability, high performance software.
Conventions
In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.
Code words in text are shown as follows: "You will end up with a file named jdk-6u14-windows-i586.exe
on your workstation."
A block of code will be set as follows:
[request-method] [/path/to/resource] [HTTP protocol version] [request-header=value]+ [blank-line to indicate the end of the request headers] [POST:request-payload]
When we wish to draw your attention to a particular part of a code block, the relevant lines or items will be shown in bold:
<?xml version="1.0" encoding="UTF-8"?>
<Context antiResourceLocking = "false" reloadable = "true" privileged = "false">
<ResourceLink name = "contactsTableCaption" global = "contactsCaption" type = "java.lang.String"/>
<ResourceLink name = "jdbc/swengsolDB" global = "jdbc/swengsolDB" type = "javax.sql.DataSource"/>
</Context>
Any command-line input or output is written as follows:
mysql> help contents;
New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in our text like this: "Once the installation has completed, run the MySQL Server Instance Configuration Wizard".
Note
Warnings or important notes appear in a box like this.
Note
Tips and tricks appear like this.
Reader feedback
Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.
To send us general feedback, simply drop an email to <feedback@packtpub.com>
, and mention the book title in the subject of your message.
If there is a book that you need and would like to see us publish, please send us a note in the SUGGEST A TITLE form on www.packtpub.com or email <suggest@packtpub.com>
.
If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.
Customer support
Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.
Note
Downloading the example code for the book
Visit http://www.packtpub.com/files/code/7283_Code.zip to directly download the example code.
The downloadable files contain instructions on how to use them.
Errata
Although we have taken every care to ensure the accuracy of our contents, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in text or code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration, and help us to improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/support, selecting your book, clicking on the let us know link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata added to any list of existing errata. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.
Piracy
Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.
Please contact us at<copyright@packtpub.com>
with a link to the suspected pirated material.
We appreciate your help in protecting our authors, and our ability to bring you valuable content.
Questions
You can contact us at<questions@packtpub.com>
if you are having a problem with any aspect of the book, and we will do our best to address it.