Welcome!

Java Authors: Don MacVittie, Maureen O'Gara, Liz McMillan, Walter H. Pinson, III, Yakov Werde

Related Topics: Java

Java: Article

Remote Benchmarking with Servlets and JSF

Wringing Out Performance

Tomcat binaries can be downloaded from http://jakarta.apache.org/site/binindex.cgi.

The latest Tomcat release is Tomcat 5. The differences between versions aren't important to this article. We assume you'll use a Tomcat 5 servlet container.

The installations described here are straightforward; no additional comments are needed.

From here on out for brevity's sake it's assumed you're using a Windows XP Pro box. What to do with a Linux box is pretty much the same and will also be described below.

To work with JSF and Tomcat 5 you need to download the JSF reference implemetation JARs that are zipped in a file jsf-1_1.zip from Sun at http://java.sun.com/j2ee/javaserverfaces/download.html.

Unzip it in a directory where a set of subdirectories will be created. Suppose, for a moment, that you downloaded jsf-1_1.zip in C:\Documents and Settings\My Documents\jsf 1.1. A set of subdirectories in C:\Documents and Settings\My Documents\jsf 1.1\jsf-1_1 will be created when your unzip the file.

You will need the following files from C:\Documents and Settings\My Documents\jsf 1.1\jsf-1_1\lib for your Web application:


commons-beanutils.jar
commons-collections.jar
commons-digester.jar
commons-logging.jar
jsf-api.jar
jsf-impl.jar
jstl.jar

You will also need a standard.jar file that can be downloaded from http://archive.apache.org/dist/jakarta/taglibs/ standard/binaries/jakarta-taglibs-standard-1.0.1.zip. You may want to use another location for more recent version. Unzip the downloaded .zip file in a directory and locate standard.jar. All these jars should be copied under {Tomcat Home}\ webapps\{Directory with Your Application}\[auxiliary directory\]WEB-INF\lib. Usually {} brackets enclose mandatory values, while [] brackets enclose values that can be omitted. Tomcat Home is a full path to the directory that contains Tomcat. If Tomcat Home is C:\jakarta-tomcat-5.0.19, the directory with your application is DwhetSF, the auxiliary directory is WebContent, which will be written as:


C:\jakarta-tomcat-5.0.19\webapps\DwhetSF\WebContent\WEB-INF\lib

Configuration

server.xml
Though it's possible to run JSF-based Web applications for remote benchmarking without changing Tomcat's server.xml, I strongly recommend that you change it when you're developing on your local box and ask your provider to change it on the server to make it more convenient to do other things (like working with databases using JNDI). So it's important to have experience related to working with server.xml.

The file is located under {Tomcat Home}\conf. For remote benchmark applications the only change you need to make in server.xml is to insert this line tag in the file:


<Context path="/{Directory with Your Application}"
reloadable="true" docBase="{Tomcat Home}\ webapps\
{Directory with Your Application}[\auxiliary directory]" debug="0" />

In our example above notation will be written as:


<Context path="/DwhetSF" reloadable="true"
docBase="C:\jakarta-tomcat-5.0.19\webapps\DwhetSF\WebContent" debug="0" />.

This tag should be inserted after:


<Logger className="org.apache.catalina.logger.FileLogger" directory="logs"
prefix="localhost_log." suffix=".txt" timestamp="true"/> tag and before </Host> tag.

faces-config.xml and web.xml
These files should be located under {Tomcat Home}\ webapps\{Directory with Your Application}\[auxiliary directory\]WEB-INF\.

The standard contents of web.xml can be used in most of your development. I recommend the following sample of web.xml: www.javaranch.com/newsletter/200404/files/web.xml.html

You will need to change faces-config.xml for each new application. For remote benchmarking, faces-config.xml can be written as shown in Listing 1. The listing will be commented in the next sections.

Property Files
These files aren't mandatory but can be useful for various messages. For brevity's sake, the property file related to the application is omitted.

JSPs
As you can see in Listing 1 we need input.jsp and response.jsp. The first page is for user input handling and validation; the second one is used for remote benchmarking output. The connections with the managed bean described below are provided by the JSF Expression Language expressions that begin with the symbols #{. The JSPs are shown in Listings 2 and 3.

An auxiliary simple index.jsp is used to point the browser at input.jsp. Mentioned pointing is provided by the tag <jsp:forward page="faces/pages/input.jsp" />. The index.jsp is located under {Tomcat Home}\ webapps\{Directory with Your Application}\[auxiliary directory\]

Managed Bean
This bean provides the main computations for remote benchmarking. It gets user input from input.jsp and provides information to be used in response.jsp. The source code is given in Listing 4.

You can use any IDE that supports J2EE 1.4 or even Ant (the Apache tool) and a command-line compiler to build the class from the source code. The built class should be put under {Tomcat Home}\ webapps\{Directory with Your Application}\[auxiliary directory\]WEB-INF\classes\{package name}\

How to Test
To test you need to start Tomcat and point your browser at http://localhost:8080/{Directory with Your Application}/.

Figure 1 shows the input of the application and Figure 2 shows the results.

How to Deploy on a Remote Server
After you will test the application on your local box, you'll want to deploy it. Ask you provider if you can deploy .war files. If the answer is yes, create a .war file and ftp it in the appropriate directory on the remote server.

If you can't deploy .war files then you need to ftp class, jsps, the configuration, and, if needed, property files. Submit the changes in server.xml to your provider or do it yourself if you're allowed.

Conclusion

This article offers a simple but powerful JSF- and servlet-based Web application for remote benchmarking. You should now be able to do remote benchmarking and develop simple- to medium-level JSF- and servlet-based Web applications. I strongly recommend that you check the Web sites mentioned here for updates.

References

  • David Geary, Cay Horstmann. (2004). Core JavaServer Faces (Sun Microsystems Press Java Series). Pearson Education.
  • Hans Bergsten. (2004) JavaServer Faces. O'Reilly.
  • More Stories By Anatoly Krivitsky

    Anatoly Krivitsky has a PhD in computer science and has more than 24 years of working experience in the IT field. He's the author of 20 published papers and books and five patents. For more information, please visit http://www.myjavaserver.com/~akrivitsky/index.html.

    Comments (0)

    Share your thoughts on this story.

    Add your comment
    You must be signed in to add a comment. Sign-in | Register

    In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.