J2EE Web Application Servers

One of the many ways you can call the PopChart Server is through the servlet redirector. By using your web/application server's servlet invoker with PopChart you will gain the ability to communicate using Secure Sockets (SSL), and also eliminate the need to expose another port outside of your firewall. All communication to PopChart Server from the clients will pass through the servlet redirector.

To install the Servlet redirector

1. Locate the folder from which your web application server serves Java Servlets. In some cases this folder will be called WEB-INF. In other cases it will be called servlet. We will refer to this folder as the web application server's servlet folder.

If you do not know where this folder is, consult the server's documentation. The location for some of the more common web application servers are discussed later in this section.

2. Copy the pcRedirector.jar file from the dev_tools/servlet_redirector folder to the lib subdirectory of the servlet folder.

The pcRedirector.jar file contains the PopChart redirector Servlet.

3. Register the servlet with your web application server.

You will need to register the popchart class.
The procedure for registering a servlet is different for each web application server. You should consult your web application server's documentation for details. The procedures for some of the more common web application servers are mentioned later in this section.

4. Set the initialization parameters for the servlet.

The PopChart servlet has one possible initialization parameter, PopChartServer. This parameter is optional, but unless you are running PopChart Server on the localhost over port 2001, you will need to set the PopChartServer parameter.
You should set the value of this parameter to the address and port that your PopChart Server is running on. For example, if PopChart Server is running over port 2001 on the machine at the address 10.0.0.53, you would set this parameter as follows:

PopChartServer=10.0.0.53:2001

This IP address and port needs to be accessible from the machine where the PopChart servlet is running. The address can be to a computer behind a firewall, as long as that computer is visible to the web server where the servlet is running. You can also specify a computer name instead of an IP address, as long as the name can be resolved to an IP address.
The procedure for initializing a parameter is different for each web application server. You should consult your web application server's documentation for details. The procedures for some of the more common web application servers are mentioned later in this section.

5. Restart your web application server.

6. Test your servlet by hitting it directly. It should return version information.

For many web application servers, you can "hit" the PopChart redirector servlet by going to the address http://mycomputer/servlet/popchart, where mycomputer is the address of the web application server. For other web application servers, such as Tomcat, you will need to go the address http://mycomputer/default/servlet/popchart. Consult your web application server for more information if neither of these addresses work.

7. Web clients will now be able to request images from the address that you tested in the previous step.

You should modify your PopChart Embedder code or HTTP requests to PopChart Server so that they use the address of the redirector instead of the address of PopChart Server, as described in "Using HTTP Redirection" in Chapter 12.

Notes for WebLogic

For Weblogic, your servlet folder will probably be /myserver/servlet/lib/.

To register the servlet with Weblogic, you will need to modify the weblogic.properties file and add the following line:

weblogic.httpd.register.popchart = popchart

To set the initialization parameter, add the weblogic.httpd.initArgs.popchart variable in this file. For example, if your initialization parameter (see step 4) is PopChartServer=10.0.0.53:81, you would add the following line to weblogic.properties:

weblogic.httpd.initArgs.popchart = PopChartServer=10.0.0.53:81

Notes for Tomcat

The servlet folder on Tomcat will be tomcat/webapps/default/WEB-INF, where tomcat is the install directory for Tomcat, and default is the name of the application that you are adding the servlet to. For example, if you are using the default web-application, you would add the popchart.class to the following location: tomcat/webapps/default/WEB-INF/lib/pcRedirector.jar.

To register a servlet in the Tomcat environment, you will need to create a file named web.xml (if it doesn't already exist) in the WEB-INF directory for your application. Below is an example of what you will need to include in this file. If the file already exist, then just add the portion between the <servlet> tags.

Example 12.1 Registering the Servlet redirector with Tomcat's web.xml File

<web-app> 

   <servlet> 

      <servlet-name> 

         popchart 

      </servlet-name> 

      <servlet-class> 

         popchart 

      </servlet-class> 

      <init-param> 

         <param-name>PopChartServer</param-name> 

         <param-value>localhost:2001</param-value> 

      </init-param> 

   </servlet> 

</web-app>

To properly set the initialization parameter, you should change the value in the <param-value> tag to match the address and port of the machine running PopChart Server.

Notes for JRun

On JRun, servlets usually go in the <application>/WEB-INF/lib/ directory, where <application> is the JRun install directory. For example, if you are using the JRun Default Server, then you would want to put the popchart.class file in the following location on UNIX: /usr/JRun/servers/default/default-app/WEB-INF/lib/pcRedirector.jar. On Microsoft Windows, this location might be: D:\JRun\servers\default\default-app\WEB-INF\lib\pcRedirector.jar.

To register a servlet in the JRun environment, you will need to start the management console (JMC) and select Application > Servlet Definitions. For example, if you are installing the servlet under the Default Server, select JRun Default Server > Web Applications > Default User Application > Servlet Definitions from the left sidebar.

From here, you can add the definition for the PopChart Servlet. You will need to set the Name value to popchart, the Class Name value to popchart, and the Init Argument to your initialization parameter (see step 4). Click on Update and restart the JRun Default Server when you are done.

Troubleshooting

If the servlet is not functioning properly, you will most likely either receive an error message when you try to test the servlet (step 6) or see a message displayed on the web server's console. Below are two common errors that you might find:

java.lang.NoClassDefFoundError: popchart (wrong name: popchart)

This error will most likely occur if you have not put the pcRedirector.jar file in the correct directory structure, or you haven't restarted the web application. The .jar file must be in the right directory for servlets, and must also be registered with your web application server. Refer to your web applications server's documentation and the section to correct this problem.

Error: PopChart Image Server does not appear to be running at 127.0.0.1 port :2001.

This error will show up in your browser if the servlet cannot contact PopChart Server running on the localhost port 2001. You may need to create an PopChartServer init parameter for your environment (see step 4 of the installation procedure). The directions listed in the browser with this error should help to correct this problem.