Archive for April, 2009

Chapter 8: Web Application Administration In this example,

Thursday, April 30th, 2009

Chapter 8: Web Application Administration In this example, the previous property file is named tomcat-tasks.property. This then can be referenced in the build script as:
The deployer.classpath set in the path element in the previous code points to the JAR files needed by Ant for the Tomcat tasks, plus other JAR files as needed for building the Web application. Beginning with Tomcat 5.5, there is a neat shortcut to create the tomcat-tasks.propertyfile and set the JAR files for the Ant tasks. All you need to do is to add this fragment to your build script (assuming tomcat.homepoints to the right location): The catalina-tasks.xml file ships with Tomcat 5.5 and 6, and sets everything (taskdefs, JAR files) required to run Tomcat s Ant tasks. Next is the Ant target that performs initializations (in this case, creates the directories needed for the build): The compile target is shown here. This has the Ant instructions to compile all the Java files into class files. The hello application doesn t have any class files, so nothing will be done, but any serious Web application will contain Java files. Notice how the compiletask depends on the init task. This ensures that the initialization steps are performed before Ant compiles the Java files: The dist target builds the application WAR file:

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

Chapter 8: Web Application Administration The tag has

Thursday, April 30th, 2009

Chapter 8: Web Application Administration
The
tag has attributes for the name of the project and the default target. The default target in this case is called dist (i.e., create the distributable jar file). Running Ant with no options will invoke the tasks associated with this default target. The basedir attribute is the base directory for all path calculations in the Ant build script. This is set to . (i.e., the current directory), so all the paths for the build process are assumed to be relative to the directory from which Ant is run. The properties for the build are defined next, such as the location of the target directory where the WAR file is generated. Typical Web applications have Java code in them (Java beans, servlets), and thus the build file would have a property pointing to the source directory. Having these properties is not mandatory, but merely a convenience to avoid putting the full path names in multiple places in the build script, and thus introducing potential sources of errors. The following properties specify the access URL and username/password for the manager application. This password can be passed via the command line, or included from a property file.
The task definitions for the manager application now need to be specified. Ant allows for custom tasks that extend its functionality. Tomcat implements the custom tasks shown in the following example for executing the managerapplication commands. For example, org.apache.catalina.ant.DeployTask executes the deploycommand against the manager application: Instead of adding one line for each task, a more convenient mechanism is to list all tasks in a property file, as shown here: deploy=org.apache.catalina.ant.DeployTask list=org.apache.catalina.ant.ListTask status=org.apache.catalina.ant.JKStatusUpdateTask jmxget=org.apache.catalina.ant.JMXGetTask jmxquery=org.apache.catalina.ant.JMXQueryTask jmxset=org.apache.catalina.ant.JMXSetTask reload=org.apache.catalina.ant.ReloadTask remove=org.apache.catalina.ant.RemoveTask resources=org.apache.catalina.ant.ResourcesTask roles=org.apache.catalina.ant.RolesTask serverinfo=org.apache.catalina.ant.ServerinfoTask sessions=org.apache.catalina.ant.SessionsTask start=org.apache.catalina.ant.StartTask stop=org.apache.catalina.ant.StopTask undeploy=org.apache.catalina.ant.UndeployTask

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

Chapter 8: Web Application Administration Figure 8-4: Successful

Wednesday, April 29th, 2009

Chapter 8: Web Application Administration Figure 8-4: Successful deployment of a Web application Before you can start using Ant to manage Web applications, you need to do the following: 1. Install Ant if you do not already have it installed on your system. Refer to Appendix B for more details. 2. Copy the $CATALINA_HOME/ lib/catalina-ant.jar file into Ant s library directory ($ANT_ HOME/lib) or add it to the Ant CLASSPATH. This JAR file contains the Tomcat management task definitions for Ant. 3. Add $ANT_HOME/binto your PATH. 4. Add to your custom build.xmlscript the elements that call the Tomcat manager commands. 5. Of course, as with the Web-based manager UI, you need to add a user with the manager role to Tomcat s user database if such a user does not exist. The following sample build.xmlfile builds and deploys the hello Web application discussed at the beginning of the chapter:
(continued)

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

Chapter 8: Web Application Administration . Sessions: Indicates

Tuesday, April 28th, 2009

Chapter 8: Web Application Administration . Sessions: Indicates the number of active sessions for the Web application. Clicking the link for the number of sessions returns the session statistics for that particular Web application. . Commands: These are the links to the start, stop, reload, and removecommands for the Web application. The manual commands for this were shown earlier, but using the Web application manager saves the effort (and possible errors) of typing a command URL for performing these tasks. The commands are pretty much self explanatory: the List Applications link shows all deployed Web applications, and each Start/Stop/Reload/Undeploy link allows you to perform the desired task. . Deploy: The WAR file for the Web application is uploaded from the client machine to the machine on which Tomcat is running, and copied into the application base directory of the given virtual host. The deployed application is automatically started (i.e., available for use by Web clients). . Stop: Send a signal to the Web application to stop. The application is then no longer available to users, although it still remains deployed. If the list command is run again, the state of the application is shown as stopped. . Start: Start up a stopped Web application. . Reload: Signal the Web application to stop and then restart. This causes the class files and properties to be reread. The deployment descriptor is, however, not re-read. . Undeploy: Signals the application to shut down (if it is still running) and then deletes the Web application directory and the application WAR file. If there is a entry for the Web application in $CATALINA_HOME/conf/server.xml ,it gets deleted too. Deploying a Web Application A new Web application can be deployed using the manager application both locally ( Deploy directory or WAR file located on server ) as well as remotely ( Upload a WAR file to deploy ). Some of the options available via the HTTP command interface (such as the tag, update, and pause parameters) are not currently usable from the Web interface. Figure 8-4 shows the manager Web interface after successfully executing the deploycommand to deploy the hello application. As you can see, Tomcat adds another row for the application in the list of deployed applications. Tomcat Manager: Managing Applications with Ant The Tomcat management commands can also be run from an Ant build script. Ant is a Java-based build tool from the Apache Software Foundation. The capability to manage the Web application right from the build script is a very powerful feature. Appendix B provides a detailed introduction to Ant for those unfamiliar with it.

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

Chapter 8: Web Application Administration Information such as

Monday, April 27th, 2009

Chapter 8: Web Application Administration Information such as the class load time, processing time, and so on, on every servlet class/JSP for all the deployed Web applications, can be obtained using the Complete Server Status option (visible while viewing the server status). Managing Web Applications Administrators can start, stop, reload, and remove Web applications by clicking on the relevant links provided at the end of each application (see Figure 8-3 ). Figure 8-3: Commands for Tomcat Manager s Web interface Click the List Application link. You should see the Web page shown in Figure 8-3 . The Applications table has five columns: . Path: Lists the Web application path. The pathname links to the URL for the Web application. . Display Name: Picked up from the element in the application s deployment descriptor (web.xml). . Running: Indicates the running status for the application (true if the application is running, and falseotherwise).

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

Chapter 8: Web Application Administration Tomcat Manager: Web

Monday, April 27th, 2009

Chapter 8: Web Application Administration Tomcat Manager: Web Interface Tomcat has a Web interface for the manager application that enables you to start, stop, remove, reload, and deploy new Web applications without having to modify configuration files. To access the Tomcat manager Web application, access http://localhost:8080/manager/html(or the actual hostname/port, as the case may be). You will then be prompted for a username and password. Use the same username and password that you entered into tomcat-users.xml. This will take you to the manager application home page, as shown in Figure 8-1 . Displaying Tomcat Server Status The status command retrieves miscellaneous information about a running instance of Tomcat (such as the free and total memory used by the JVM, number of threads, and so on). This is accessible via the Server Status link. Figure 8-2 shows the output of this command. Figure 8-2: Output of the server status command

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

Chapter 8: Web Application Administration The web.xml(the deployment

Sunday, April 26th, 2009

Chapter 8: Web Application Administration The web.xml(the deployment descriptor) defines, among other things, the security constraints on the manager application. The following snippet describes the default security constraint definition for the manager Web application. The defined here (shown in bold) specifies that only users in that role can access the manager Web application: HTMLManger and Manager command /jmxproxy/* /html/* /list /sessions /start /stop /install /remove /deploy /undeploy /reload /save /serverinfo /status/* /roles /resources manager The authentication mechanism for the manager application is also defined here. The default setting is BASIC authentication, as shown in the following code. Administrators could set up a more rigorous mechanism for manager application authentication for example, a client-certificate based mechanism (set to CLIENT-CERT): BASIC Tomcat Manager Application The lists all the roles that can log in to the manager application. In this case, it is restricted to only one user role (that is, the manager role): The role that is required to log in to the Manager Application manager

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

Chapter 8: Web Application Administration As you can

Saturday, April 25th, 2009

Chapter 8: Web Application Administration As you can see in the figure, the response for a successful command execution (the Messageparameter) is an OK string. A missing OK is an indication of failure, and the rest of the message provides the cause. The possible causes of failure for each command are listed later in this chapter in the section Possible Errors. During installation of Tomcat on Windows, using the installer executable (and not the Zip file), the installer asks the user for the admin username and password. The username and password entered at install time are used to generate entries for the tomcat-users.xmlfile for both the manager and admin Web applications. Hence, no configuration is needed in this case, unless another user with manager privileges is to be added or the manager password is to be changed. Manager Application Configuration The previous section looked at tomcat-users.xml, which defines the username and password for the manager role. The other manager application related configuration parameters are the manager context entry and the deployment descriptor. No changes have to be made for the manager application to work the settings are configured by default. They can, however, be modified for deployment requirements for example, to change the security constraints for the manager application, to change the authentication mechanism for users in the manager role, or even to change the name of the role from manager to some other name if required. This section covers these configurable parameters for the manager application. Manager Application Context Entry In Tomcat 6, unlike Tomcat 5/5.5, the manager context is configured in the same way as the other application contexts. Following is the default configuration for the manager application context from the $CATALINA_HOME/ webapps/manager/META-INF/context.xmlfile: This only difference from a standard web application is the setting of the privileged attribute to true. This enables the application to access the container s servlets. This attribute is false for a normal Web application deployed in Tomcat. In Tomcat 5/5.5, the context was defined in the $CATALINA_HOME/server/webapps/manager/ manager.xmlfile. Manager Application Deployment Descriptor The tomcat-users.xml file shown earlier defined the username and password for the manager role. This section discusses how the security constraints for this role are specified. The manager application s deployment descriptor for versions prior to Tomcat 4.1 is $CATALINA_HOME/webapps/manager/WEB-INF/web .xml. In Tomcat 5, the web.xmlfile moved to $CATALINA_HOME/server/webapps/manager/WEB-INF; however, it is back to the original location under $CATALINA_HOME/webapps/manager/WEB-INF/in Tomcat 6.

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

Chapter 8: Web Application Administration In a User

Saturday, April 25th, 2009

Chapter 8: Web Application Administration In a User Database Realm, the usernames and their supporting information are stored in memory and are initialized at startup from an XML configuration file ( $CATALINA_HOME/conf/tomcat-users.xml) kept on the file system. This file needs to be edited to add a user with a role of manager. In the following entry, the username and password for this role are adminand secret , respectively: Tomcat now needs to be restarted to make it reread the tomcat-users.xml file. To determine whether the manager application setup was successful, browse to the default Tomcat URL ( http:// localhost:8080), and click the Tomcat Manager link, or go directly to the manager application URL http://localhost:8080/manager/html. The user is then prompted for a username and password. After entering the values set in the tomcat-users.xml file, the Web page of the manager application shown in Figure 8-1 should be displayed. Figure 8-1: The Tomcat Web Application Manager Keeping the password for the manager application in clear text may be okay for a development environment, but not suitable for anything else. The Security Considerations section at the end of the chapter addresses this and other security concerns.

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

Chapter 8: Web Application Administration Following is a

Friday, April 24th, 2009

Chapter 8: Web Application Administration Following is a summary of some of the tasks that the manager application can perform: . Deploy a new Web application . List the currently deployed Web applications, as well as the sessions that are currently active for those Web applications . Reload an existing Web application . List the available global JNDI resources . List the available security roles . Start a stopped application . Stop an existing application, but not undeploy it . Undeploy a Web application . Display session statistics An application can be deployed manually, too. Following are the ways to do this: . Add a entry in Tomcat s server.xmlconfiguration file. This enables you to place the Web application in a location other than the default $CATALINA_HOME/webappsdirectory. . Copy the entire application directory into the $CATALINA_HOME/webapps directory. The server.xmlfile does not have to be edited in this case. . Copy the WAR file for the application into the $CATALINA_HOME/webapps directory. In this option, too, the server.xmlfile does not have to be edited. However, there are advantages to using a managerapplication. First, all these methods of deploying just described require you to restart Tomcat. When deploying is done via the manager application, Tomcat is not restarted and, hence, the other running Web applications are not affected. Alternatively, the autoDeployattribute in the Host(see server.xml) could be set to true, which is actually the default in Tomcat 6. This causes any Web application dropped into Tomcat s application base to be deployed automatically. Doing this compromises performance, however, because Tomcat must continually monitor the application base directory; hence, autoDeployis often set to false. If autoDeploy is set to false, then copying the Web application or the WAR file to the webapps directory will not deploy the Web application. You would need to either restart Tomcat or use the deploycommand. Another advantage of using the manager application is that it supports remote installs. That is, the Web application directory (or WAR file) doesn t need to be transferred via FTP or some other means to the host machine running Tomcat. The deploy command takes care of transferring the Web application WAR file from the local development machine to the remote machine running the Tomcat server. Enabling Access to the Manager Application Before using the manager application, the server needs to be configured to enable access. Access to this application is controlled via a Security Realm. Any Realm implementation can be used (Memory, User Database, JDBC, JNDI, or JAAS). This example uses the default Realm, the User Database Realm, for simplicity.

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