ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.


AddThis Social Bookmark Button

Monitoring Applications with Palm OS & Tomcat
Pages: 1, 2, 3

What's Mission Critical?

Until now, the average database administrator (DBA) has had a pretty miserable lot in life. When a page comes in reporting a mission-critical problem with their database, they have to find a connected PC to fix the problem -- which often cuts into their personal time. Wireless devices that enable the DBA to fix the problem remotely could save lots of time, and the same is true for professionals in other lines of work.

There are many schools of thought on exactly what constitutes a mission-critical system. And, of course, these schools of thought are generally contradictory and mutually exclusive. I offer two heuristics for determining whether or not systems are truly mission-critical.

• How important is the data?
• How much work is stopped if the data can't be interpreted?

At Expand Beyond Corp., we are primarily concerned with the first of these points. We manufacture a product that safeguards a company's Oracle databases against becoming unavailable due to the unavailability of administrative personnel. By giving database administrators wireless access to these systems, mission-critical databases are protected.

In other cases, corporations have needs that go well beyond the database tier. Large, enterprise-level applications like customer-relationship-management (CRM)- and human resource packages need to stay up to keep a company running. In these cases, the remote user would need to execute commands much more complex than the simple "listener starter" example that we show here. The same technology, however, may be used.

All that JAS

Having seen the interface for our PQA in all its glory, you may now actually want to do something useful with it. Demanding, aren't you?

Fortunately, you are in luck. In this section, we will construct the server-side logic needed to support remote invocation of operating system commands from mobile devices. To do this, we will be downloading and installing a Java Application Server.

There are many Java Application Servers (JAS) out there, and the list grows every month. Some are commercial solutions that carry hefty licensing fees for their use. However, at Expand Beyond, we have fallen in love with the Jakarta/Tomcat JAS and standardized it as the sole-supported JAS for use with our server-side application.

Few applications are as easy to install as Tomcat. If you have already installed a compatible Java Development Kit (JDK) and/or Java Runtime Environment (JRE) on your system, then installing Tomcat typically only requires a few steps:

  1. Downloading,
  2. Unpacking, and
  3. Setting the right environment variables.

Tomcat comes out of the Apache Free Software project, and you can download it for no charge at their Web site.

If you want to get up and running fast, select a binary distribution package; explaining how to compile a source distribution is beyond the scope of this article. When looking through the various binaries, you should try to find the most recent release build, which will represent the most stable code base.

Once it's downloaded, unpack it using WinZip or GZip, whichever tool is right for your operating system.

Before you try Tomcat, you have to set an environment variable to tell it where to find Java on your system. Set JAVA_HOME to point to the bin directory of your JDK or JRE installation. Once you have done this, navigate to the bin directory beneath wherever you unpacked Tomcat. In this directory you will find two start-up scripts: one for Windows, one for Unix. Execute the appropriate one and you should see some text scroll across your display.

Once this has finished, try hitting port 8080 on your local box with a Web browser. If Tomcat is working properly, you should see something similar to Figure 3.

Screen shot.
Figure 3.

You try!

Once Tomcat is up and running, you're ready to write a servlet capable of

  1. Receiving a request from the PQA running on the Palm OS device,
  2. Interpreting it, and
  3. Executing it.

In this section, we will show you how the request is received and interpreted. We'll leave the execution of the request and notification of the client for the next section.

The code for this servlet is shown in Listing 2.

import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class StartListener extends HttpServlet {

  public void doGet(HttpServletRequest request, HttpServletResponse response)
  throws IOException, ServletException
    doPost(request, response);

  public void doPost(HttpServletRequest request, HttpServletResponse res)
  throws IOException, ServletException
      String cmd = request.getParameter("command");
      PrintWriter out = res.getWriter();
       out.println("<title>Listener Response</title>");
       out.println("<meta name=\"PalmComputingPlatform\" content=\"true\">");
       out.println("<meta name=\"PalmLauncherRevision\" content=\"1.0\">");
      out.println("command = " + cmd);

To try this code, save it to a text file named StartListener.java and compile it, making sure that the file servlet.jar from Tomcat's lib directory is in your classpath. Once you have a class file, you are ready to install it in the JAS. The easiest way to do this is to make it part of an existing Web application by copying your new class file to: \jakarta-tomcat-3.2.1\webapps\examples\WEB-INF\classes

Pages: 1, 2, 3

Next Pagearrow