Archive for January, 2009

Chapter 4: Tomcat Architecture The Service A Service

Saturday, January 31st, 2009

Chapter 4: Tomcat Architecture The Service A Service groups a container (usually of type Engine) with a set of Connectors and is a top-level component. An Engine is a request-processing component that represents the Catalina Servlet engine. It examines the HTTP headers to determine the virtual host or context to which requests should be passed. Each Service represents a grouping of Connectors (components that manage the connection between the client and server) and a single container, which accepts requests from the Connectors and processes the requests to present them to the appropriate Host. Each Service is named so that administrators can easily identify log messages sent from each Service. In other words, the container contains the Web applications. It is responsible for accepting requests, routing them to the specified Web application and specific resources, and returning the result of the processing of the request. Connectors stand between the client making the request and the container. They provide additional services such as SSL support. Multiple Service objects may be children to the Server. However, most of the time, you will use only a single Service in a container. Tomcat typically uses the StandardServiceobject as the service that implements the Serviceinterface. The Connectors Connectors connect the applications to clients. They represent the point at which requests are received from clients and are assigned a port on the server. The default port for non-secure HTTP applications is kept as 8080 to avoid interference with any Web server running on the standard HTTP port, but there is no reason why this cannot be changed as long as the port is free. Multiple Connectors may be set up for a single Engine or Engine-level component, but they must have unique port numbers. The default port to which browsers make requests if a port number is not specified is port 80. If Tomcat is run in standalone mode, the port for the primary Connector of the Web application can be changed to 80 by reconfiguring this component. The default Connector is Coyote, which implements HTTP 1.1; Tomcat also comes with an AJP connector. In addition, the HTTP connector can be used with SSL as well. Both the HTTP and AJP connectors are fully supported by Tomcat. However, there are alternative Connectors, such as the old JServ and JK2, which work, but are no longer supported. These are discussed later in this chapter. The Engine The next component in the architecture is the top-level container a container object that cannot be contained by another container. This means that it is guaranteed not to have a parent container. It is at this level that the objects begin to aggregate child components. Strictly speaking, the container does not need to be an Engine; it just has to implement the container interface. This interface mandates the following: that the object implementing it is aware of its position in the hierarchy (it knows its parent and its children), that it provides access to logging, that it provides a Realm for user authentication and role-based authorization, and that it has access to a number of resources, including its session manager (and some internally important aspects that you do not need to worry about).

If you looking for unlimited one inclusive web hosting plan please check web hosting plan website.

Chapter 4: Tomcat Architecture Logger LoggerConnector Server Service

Friday, January 30th, 2009

Chapter 4: Tomcat Architecture Logger LoggerConnector Server Service Engine Host Valve Valve Realm Realm Context Valve Realm Wrapper Figure 4-2: Tomcat s architecture Here, components that can be contained multiple times are denoted by a symbol that has multiple profiles, including Connector, Logger, Valve, Host, and Context. The nested relationships of the components in this architecture are parent-child in nature. This essentially means that each component may have one or more child components, and those children may have children of their own. For example, as shown in Figure 4-2 , you can have one or more Service objects as children. Each Service object may contain a single Engine and one or more Connector objects. Each Engine may have one or more Host objects as children, and so on. The Wrapper objects in the Context represent the holders for servlets and JSPs. The following sections examine each component at a high level. Chapter 5 discusses each component s configuration. The Server The Server is Tomcat itself an instance of the Web application server and is a top-level component. It owns a port that is used to shut down the server. In addition, the Server can be set in debug mode, which instantiates a version of the Java Virtual Machine (JVM) that enables debugging. Only one instance of the Server can be created inside a given Java Virtual Machine (JVM). Separate Servers configured to different ports can be set up on a single machine to separate applications so that they can be restarted independently. That is, if one Server running in a JVM were to crash, the other applications would be safe in another Server instance. This is sometimes done in hosting environments in which each customer has a separate instance of a JVM, so a badly configured/written application will not cause others to crash. The server is an implementation of the Serverinterface. The default and usual configuration is for Tomcat to implement the StandardServer object for the server.

If you looking for unlimited one inclusive web hosting plan please check unlimited web hosting website.

Chapter 4: Tomcat Architecture Tomcat comes standard with

Friday, January 30th, 2009

Chapter 4: Tomcat Architecture Tomcat comes standard with several applications that reside in this directory: . ROOT: The welcome screen application. This is a special directory that designates the / root of your Web container. When you move Tomcat to a production environment you would likely remove this directory if your application reuses the / root context. . docs: Contains the Tomcat documentation. It is the same documentation you would find on the http://tomcat.apache.org/tomcat-6.0-doc Web site. . examples: Contains the JSP and servlet examples. . host-manager: An application that allows you to manage the hosts that run in your application. Accessible from the /host-manager/html URL. It requires that you have set up proper credentials in the conf/tomcat-users.xmlfile to access this application. . manager: An application that allows you to manage your applications in Tomcat. From this application you can start, stop, reload, deploy, and undeploy your applications. It is accessible from the /manager/html URL. It requires that you have set up proper credentials in the conf/tomcat-users.xmlfile to access this application. work Directory Directory for temporary and working files. This is heavily used during JSP compilation where the JSP is converted to a Java servlet and accessed through this directory. An Overview of Tomcat Architecture Tomcat s architecture was completely revised for version 4. It was rebuilt from the ground up because some users felt that the refactoring done in the previous Tomcat release, while improving its performance and flexibility, was always going to result in a somewhat limited server. A rather heated debate ensued regarding whether this was actually the case. The result of this controversy was the 3.2 architecture branching from the main development tree in a continued refactoring effort, leaving the 4.0 version to become the main focus of the project. Tomcat 6 is the latest iteration of the Tomcat 4 architecture. Tomcat 6 supports the latest Servlet and JSP specifications, versions 2.5 and 2.1, respectively. Tomcat 6 consists of a nested hierarchy of components. Some of these components are called top-level components because they exist at the top of the component hierarchy in a rigid relationship with one another. Containers are components that can contain a collection of other components. Components that can reside in containers, but cannot themselves contain other components, are called nested components. Figure 4-2 illustrates the structure of a typical Tomcat 6 configuration. This diagram represents the most complete topology of a server. However, you should be aware that some of these objects can be removed without affecting the server s performance. Notably, the Engine and Host may be unnecessary if an external Web server (such as Apache) is carrying out the tasks of resolving requests to Web applications. This topology also allows components to be created and removed on-the-fly, or while the container is running. This is evidenced through the host-manager application, where you can add and remove Host objects at will. This is further demonstrated through the manager application where you are able to stop, start, deploy, and undeploy Web applications, which literally are Context objects.

For reliable and cheap web hosting services please check tomcat web hosting website.

Chapter 4: Tomcat Architecture . context.xml: The common

Thursday, January 29th, 2009

Chapter 4: Tomcat Architecture . context.xml: The common context.xml that is used by all Web applications. By default, this file is used to set up where to access the web.xml file in Web applications. . logging.properties: The default logging configuration used by the JULI logger. By default, it uses a ConsoleHandler and FileHandler and sets up the logging level on a per-application or package basis. . server.xml: The main configuration file for Tomcat. This file is used by the digester to build the container on startup to your specifications. This file follows the Tomcat architecture and will be discussed in more detail later in this chapter. . tomcat-users.xml: Used for security to access the Tomcat administration applications. It is used with the default UserDatabase Realm as referenced in server.xml. All credentials are commented by default and should be changed if uncommented. The Tomcat Administration application isn t accessible until entries are uncommented or placed into this file. . web.xml: The default web.xml file that is used by all Web applications. This web.xmlsets up the JSPServlet to allow your applications to handle JSPs and a default servlet to handle static resources and HTML files. It also sets up the default session timeout and welcome files such as index.jsp, index.htm, and index.html; and it sets up default MIME types for the most common extensions. In addition to these files, when an application is deployed to a Tomcat server, it creates the equivalent of a context.xml (usually named after the context path) with a structure following [engine name]/[host name]/[context path name].xml. As noted previously about the container-wide context.xmlfile, you can also create an [engine name]/[host name]/context.xml.default file where all Web applications under a specific host will adopt a set of default settings for the host s context. lib Directory The lib directory contains all of the JARs that are used by the container. This includes the Tomcat JARs and the Servlet and JSP application programming interfaces (APIs). This is the place where you place JARs that are shared across Web applications or JDBC JARs for connection pools. logs Directory This directory is used for the logging files that are produced while Tomcat is running. The JULI logging produces multiple files in this directory, and each log file is created for each day. temp Directory This is the temporary directory that Tomcat uses for scratch files and temporary use. webapps Directory The webapps directory is where your Web applications ultimately will live. If you are using an exploded WAR (a WAR file that is decompressed), it needs to be placed in this directory. Placing a WAR file in this directory also causes Tomcat to deploy the file. When you deploy a full WAR through the Manager console application or the Tomcat Client Deployer, your WAR file is also placed into this directory.

For reliable and cheap web hosting services please check tomcat web hosting website.

Chapter 4: Tomcat Architecture CATALINA_HOME /bin /conf /lib

Wednesday, January 28th, 2009

Chapter 4: Tomcat Architecture CATALINA_HOME /bin /conf /lib /logs /temp /webapps /work Figure 4-1: Tomcat directory structure bin Directory The bin directory contains the scripts and code required to execute the server. Depending on the version that you download, this directory may contain executable ( .exe) files for a Windows service installation, or it will just contain the standard Java starting scripts. Both Unix/Linux shell scripts ( .sh ) and Windows batch ( .bat) scripts exist here for the standard Tomcat download. Some JAR files also live in the bin directory, including bootstrap.jar, commons-daemon.jar, and tomcat-juli.jar . This directory is primarily used for starting and stopping Tomcat with either the startup or Catalina script. The startup.sh(bat) script is typically used for running Tomcat as a background process. Using the catalina.sh(bat) script allows you to have more fine-grained control over running Tomcat, such as running it as a foreground process, in debug mode. The startup.sh(bat) script actually runs catalina.sh(bat) and simply instructs it to run in the background. conf Directory The conf directory contains the files that are necessary to configure and set parameters for Tomcat when it executes. When Tomcat launches, it investigates the files in this directory and alters/creates the necessary objects and settings to run. The following is a list of the files along with a short description of their use. . catalina.policy: Contains the security policy statements that are implemented by the Java SecurityManager. It replaces the java.policyfile that came with your Java installation. It is used to prevent rogue code or JSPs from executing damaging code that can affect the container with calls such as system.exit(0). It is used only when Tomcat is launched with the -security command-line parameter. . catalina.properties: Contains lists of Java packages that cannot be overridden by executable Java code in servlets or JSPs, such as java.*or org.apache.tomcat.*, which could be a security risk. Also allows the setting to look for common JARs.

For high quality java hosting services please check tomcat web hosting website.

Tomcat Architecture Tomcat is a powerful Web container

Wednesday, January 28th, 2009

Tomcat Architecture Tomcat is a powerful Web container that is made up of pluggable components that fit together in a nested manner. The configuration of these components dictates how the server will run, including such settings as whether specialized filters are used, which ports and address a server may listen on, whether it uses security or not, what the virtual hosts are, and much more. Tomcat can be easy to use in its standard configuration because you are using a default configuration. However, when you begin to think about using Tomcat in a production environment, you need to make changes to the configuration to fit your requirements. This is where having good knowledge of Tomcat s architecture comes in handy. Tomcat s configuration files can appear cryptic and difficult to follow or understand, but they follow how Tomcat pieces together its components. Understanding Tomcat s architecture can give you insight into the way Tomcat works and how its subcomponents make up a configuration. This chapter explores Tomcat from an architectural perspective. The topics covered include: . Tomcat directory structure . Overview of the major Tomcat components . Relationships between the components to make a full-service container By the end of this chapter, you should have a comprehensive understanding of the Tomcat container architecture, its subcomponents, and their relationship to one another. Tomcat Directory Overview Before delving into the Tomcat architecture, understanding the Tomcat setup and directory layout will provide a solid understanding of where things live. When you download and uncompress the Tomcat bundle, it places all of its contents in a folder or directory named apache-tomcat-6.X.XX where X.XX represents the minor version numbers. This installation or top-level directory is what is known as the CATALINA_HOME and will be referenced as such from this point forward. When you download and install Tomcat, you are presented with the directory structure, as shown in Figure 4-1 .

For high quality website hosting services please check tomcat web hosting website.

Chapter 3: Tomcat Installation Summary This chapter provided

Tuesday, January 27th, 2009

Chapter 3: Tomcat Installation Summary This chapter provided a great deal of information about selecting and installing a JDK and Tomcat in a variety of ways. Key points of this chapter include the following: . In the majority of cases, installing the Tomcat server is a very straightforward process, because binary versions are available for the common platforms. . The Tomcat installation directory structure includes seven important directories. . Common installation problems include using the incorrect JVM version, the port number being in use, multiple instances running, and a proxy blocking access. The next chapter examines Tomcat s architecture.

For high quality website hosting services please check tomcat web hosting website.

Chapter 3: Tomcat Installation This will produce the

Monday, January 26th, 2009

Chapter 3: Tomcat Installation This will produce the normal startup messages, and any errors will be displayed. These errors also appear in the stdout.logfile in the $CATALINA_HOME/logssubdirectory. Some common problems are discussed next. Class Version Error Tomcat 6 requires Java SE 5 or later to run. If an earlier version of Tomcat is used, you will see the following exception during Tomcat startup. Exception in thread main java.lang.UnsupportedClassVersionError: org/apache/catalina/startup/Bootstrap (Unsupported major.minor version 49.0) Check your JAVA_HOME settings, and make sure they point to a Java SE 5 installation. The Port Number Is in Use One possible error is that the chosen port is already in use. The error message will look similar to the following: LifecycleException: Protocol handler initialization failed: java.net.BindException: Address already in use: JVM_Bind:8080 Tomcat uses port 8080 by default, as mentioned previously. You can determine whether another program is using this port by using the netstat utility on both Windows and Linux. Type netstat -aoon Windows and netstat -lp on Linux. Your shell/command prompt will list open ports on your system, which should indicate any process that is interfering with Tomcat. You have two options: shut the process down or change Tomcat s port as described earlier. Running Multiple Instances A common problem is trying to start a new Tomcat instance when one is already running. This is especially true if it s running as a daemon thread. Check to ensure that you aren t already running another instance of Tomcat. A Proxy Is Blocking Access If you have a proxy set up for all HTTP services, it may be blocking access to the server. You should bypass the proxy for all local addresses. Instructions are provided here. In Firefox 2, Choose Tools . Options. Next, choose Advanced, then Network Tab and then Settings. Select Manual proxy configuration and enter localhostand 127.0.0.1 in the No proxies for box. In Internet Explorer, choose Tools .Internet Options and then choose the Connections tab. Select the Lan Settings button and enter your proxy configuration by selecting the Advancedbutton in the window that opens. Enter localhostand 127.0.0.1in the Exceptions box. This should work in most versions of Internet Explorer.

If you looking for unlimited one inclusive web hosting plan please check cheap web hosting website.

Chapter 3: Tomcat Installation The APR JNI wrapper

Monday, January 26th, 2009

Chapter 3: Tomcat Installation The APR JNI wrapper sources are packaged, along with the Tomcat distribution, as the tomcat- native .tar.gzfile in /bin. The installation steps are provided in the code that follows. In the steps shown, the default apr_install_locationis /usr/local/apras shown in the earlier step. If you don t need OpenSSL support, you can use the –without-ssloption with configureto disable it. If you need OpenSSL, you can download it from www.openssl.org. The JNI wrapper gets installed under /usr/local/apr/lib, and as before, a –prefix option for configure can install it elsewhere. $ cd /path/to/tomcat/bin $ tar zxvf tomcat-native.tar.gz $ cd tomcat-native-x.y.z-src/jni/native $ ./configure –with-apr=apr_install_location –with-ssl=openssl_install_location $ make install . After installing, add the APR directory to your LD_LIBRARY_PATHas shown: $ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/apr/lib When you restart Tomcat, you should now see an INFO: Loaded Apache Tomcat Native library 1.1.9 message indicating that APR was detected and loaded. Chapter 10 explains the use of the APR Connector, which is an HTTP Connector for Tomcat developed using APR. Troubleshooting and Tips This final section deals with some common problems you may encounter after installing Tomcat. If you have further problems, you can find more information on the Tomcat Web site at the following URLs (as well as on various forums): http://tomcat.apache.org/ http://java.sun.com/ You should also read the release notes available with each download. Sometimes, when you attempt to launch Tomcat, the Tomcat window will appear briefly and then disappear. This usually occurs because of an error that causes Tomcat to crash and, thus, its window to disappear. The error message is also displayed, but because the window disappears so rapidly, the error cannot be seen. If Tomcat does not start, it can be run in the current shell or as a command prompt (as opposed to a new pop-up window) so that the problem can be seen. To do this in Linux, type the following: $CATALINA_HOME/bin/catalina.sh run Or, in Windows, type the following: %CATALINA_HOME%bincatalina run

For reliable and cheap web hosting services please check javaweb hosting website.

Chapter 3: Tomcat Installation Web applications, and a

Sunday, January 25th, 2009

Chapter 3: Tomcat Installation Web applications, and a global configuration file. Later chapters discuss these files in greater detail. . logs: The /logs directory contains the server logs. . lib: The /lib directory contains all the JAR files used by Tomcat. . webapps: This directory contains all the Web applications provided with Tomcat by default. This includes the Tomcat manager application that is discussed in Chapter 8 . User-developed Web applications will also be deployed to this directory. The structure of the webapps directory is discussed in greater detail in Chapter 7 . . work: The work directory contains temporary files, precompiled JSP pages, and other intermediate files. Installing APR An optional component with Tomcat is APR, or the Apache Portable Runtime. This is a library that was originally developed as a part of the Apache 2 Web server, but is now used in many other projects. Use of this library in Tomcat improves stability and performance, especially when Tomcat is used to connect to a native Web server like Apache. If you see a message such as the following: INFO: The Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path it is because the APR library is missing at Tomcat startup time. This is not an error, as the APR support is optional. Locations for APR native library binaries for some platforms are listed at http://tomcat.apache .org/tomcat-6.0-doc/apr.html; for example, Windows binaries are available from http:// tomcat.heanet.ie/native/. Download and save the tcnative-1.dll file from this Web site to the /bin directory. This DLL contains the native binaries for APR as well as for OpenSSL. For Linux/Unix, you need to install this from source. . If you don t have APR installed on your machine, download the source from http://apr .apache.org. Install APR using the following steps as the root user to install the APR in its default location (/usr/local/apr). If running as a non-root user, use the –prefixoption with configureto specify another install location. $ tar zxvf apr-x.y.z.tar.gz $ cd apr-x.y.z $ ./buildconf $ ./configure $ make install

For reliable and cheap web hosting services please check javaweb hosting website.