Comments
Richard Davies wrote: The UK has a good crop of technology pioneers in cloud computing - for example ElasticHosts, FlexiScale, Flexiant, OnApp - and also some strong government initiatives such as G-Cloud. We will have to see whether this kind of technical leadership converts into swift mass-market adoption or not.
Cloud Expo on Google News


2008 West
DIAMOND SPONSOR:
Data Direct
SOA, WOA and Cloud Computing: The New Frontier for Data Services
PLATINUM SPONSORS:
Red Hat
The Opening of Virtualization
GOLD SPONSORS:
Appsense
User Environment Management – The Third Layer of the Desktop
Cordys
Cloud Computing for Business Agility
EMC
CMIS: A Multi-Vendor Proposal for a Service-Based Content Management Interoperability Standard
Freedom OSS
Practical SOA” Max Yankelevich
Intel
Architecting an Enterprise Service Router (ESR) – A Cost-Effective Way to Scale SOA Across the Enterprise
Sensedia
Return on Assests: Bringing Visibility to your SOA Strategy
Symantec
Managing Hybrid Endpoint Environments
VMWare
Game-Changing Technology for Enterprise Clouds and Applications
Click For 2008 West
Event Webcasts

2008 West
PLATINUM SPONSORS:
Appcelerator
Get ‘Rich’ Quick: Rapid Prototyping for RIA with ZERO Server Code
Keynote Systems
Designing for and Managing Performance in the New Frontier of Rich Internet Applications
GOLD SPONSORS:
ICEsoft
How Can AJAX Improve Homeland Security?
Isomorphic
Beyond Widgets: What a RIA Platform Should Offer
Oracle
REAs: Rich Enterprise Applications
Click For 2008 Event Webcasts
SYS-CON.TV
Top Links You Must Click On


Remote Debugging with Symantec Cafe
Remote Debugging with Symantec Cafe

Java applets can be used to provide better dynamic interaction with the user on Web pages than simple CGI scripts and html forms. However, like any programming language, the code does not spring forth perfect, but rather is designed, implemented, and then debugged.

Debugging code that lives on a Web page can be difficult. The old standby of trace printfs (or System.out.println in Java terminology) is always available, but tedious at best. The JDK, available from JavaSoft, contains a debugger, jdb, but it really serves best as a sample implementation rather than as a development tool. If your applet does not do any communications back to the Web server it comes from, then debugging the applet can be done completely off-line.

The problem comes about when your applet needs to communicate with the Web server host in order to function correctly. Perhaps the applet is doing CGI GETs to a backend-database, and then validating entry fields. Or maybe it is a simple page-hit counter storing the result back to the server. No matter how simple or complicated the applet, the security model of Java is such that an applet must come from a host before it can communicate with that host.

This security model, which exists to protect you from a malicious applet being pulled over your corporate firewall by an unwitting user and then attacking the now unprotected hosts from within, works against you when it comes to debugging. In this article, I discuss a way to debug applets which must communicate with the Web server using a product from Symantec, Cafe. Symantec Cafe is an integrated development environment (IDE) which contains a graphical debugger. This IDE is good for stand-alone applet development, but it also can be used to debug your applets from your Web server while they are 'live' and communicating with it.

In order to accomplish this, the CLASSPATH environment variable is used to cause the Symantec IDE to fetch classes from your local disk. [Note: In Cafe, CLASSPATH is not an environment variable, but is stored instead in the project file. The result is the same]. At the same time, you tell Cafe the html page you are using is on your Web server, using http as the protocol. The directory hierarchy used locally is the same as the one you will eventually use on the Web server. While you are debugging, it doesn't matter if the .class files exist on the http server or not; they won't be used.

It doesn't matter what architecture your http server is...it could be a large UNIX server...all of the debugging, user interface, input, output, etc., is done on your PC. You won't even use the Web server host for anything other than serving you html pages, and whatever CGI communications your applet needs to perform.

As far as the applet is concerned, it really came from that Web server, and its getCodeBase(), getDocumentBase(), etc., methods will indicate the applet came from the Web server using http, just as if it really were fetched from there. This means you don't need to modify your code for the purpose of debugging.

Perhaps the simplest way to explain this is with an example.

My Web server is called 'www'. My development PC is called 'xdb4'. I wish to write and debug an applet which validates IP addresses as they are entered, and communicates the result back to the http server in a CGI post. This applet has a single text field, and when the user hits enter, checks to see if it contains a valid IP address. If it does, it posts it to the CGI script as 'IP=value'. If it does not, it should inform the user with a dialog or otherwise.

On host www, my directory hierarchy is such that /usr/local/www/htdocs is my DocumentRoot [i.e. the URL http://www/file.html will fetch /usr/local/www
/htdocs/file.html]. I have a cgi script called 'cgi-bin/post-ip.cgi' and the HTML page is called 'ipEntry/enter-ip.html'. I wish to have a Java applet called ipVerify.class that will go in the same directory as the HTML page.

Thus, my Web server has this directory structure:

/usr/local/www/htdocs/cgi-bin/post-ip.cgi
/usr/local/www/htdocs/ipEntry/enter-ip.html
/usr/local/www/htdocs/ipEntry/ipVerify.class

The HTML file, 'enter-ip.html', which specifies the applet looks like this:

<HTML>
<HEAD>
<TITLE> Enter IP Address </TITLE>
</HEAD>
<BODY>
<APPLET CODE="ipVerify.class" WIDTH=100 HEIGHT=100></APPLET>
</BODY>
</HTML>

The Java source file I used is shown in Listing 1. There are four methods in it: ipVal() validates the IP address; postVal() sends the value to the CGI server; init() starts the applet, and handleEvent() checks for the return key. This source code is saved in the file ipVerify.java (Listing 1).

Now, in Cafe, on the 'Project' menu, select 'Project Settings'. Select the 'Target' tab at the top, specify 'http://www/ipEntry/enter-ip.html' for the HTML file as shown in Figure 1. In the same dialog, 'Project Settings', select the 'Directories' tab; specify a CLASSPATH of '.;/Cafe/Java/Lib/symclass.zip;/Cafe/Java/Lib/classes.zip'. It doesn't matter where you place the .java or .class file on your PC.

What this means is that Cafe will now use 'http://www/
ipEntry/enter-ip.html' for the HTML page. Whenever you click 'Start/Restart Debugging' or 'Run', the debugging appletviewer will fetch that page. [Note: I've been unable to get the standard 'Run' command in Cafe to fetch this page, but the debugger will, which is all that counts]. The CLASSPATH you specified means that when it needs to find a .class file, it will first look in the current directory ('.'), then in symclass.zip, then in classes.zip. If it finds it in none of these, it will look where the HTML file came from on the Web server. In our situation, the debugger will fetch ipVerify.class from the current directory on 'xdb4'.

To debug this now, select 'Rebuild All' from the toolbar. When Cafe has finished rebuilding the applet, click 'Start/Restart' debugging from the toolbar. When the hourglass goes away, set your breakpoints, watch your data, etc., just as if the applet were completely local. Note that when the applet calls getCodeBase(), getDocumentBase(), etc., it always reports that the applet has come from http://www/ipEntry.

So the sequence of events would be:

  • Cafe starts appletviewer
  • appletviewer fetches file 'http://www/ipEntry/enter-ip.html' from 'www' to 'xdb4'
  • appletviewer loads ipVerify.class from the current working directory on 'xdb4'
  • ipVerify.class writes IP=value pair to 'www' from 'xdb4' with CGI POST.

    You may use the debugger on any aspect of the execution of ipVerify.class...it won't interfere with the client-server interactions at all. If you wish to verify that the data came through correctly on the CGI side, you can modify the 'post-ip.cgi' script to log its operations into a file on its local disk.

    When you have your applet working correctly, and all debugged, transfer the .class files to the appropriate place on the Web server. In this example, transfer ipVerify.class to /usr/local/www/htdocs/ipEntry/ipVerify.class. Verify your work by running Netscape [which won't fetch the applet from the CLASSPATH, so will be forced to fetch it from the http server].

    Using this technique, I have been able to debug many applets that do complex multi-part interactions with CGI posts and gets. It has saved me hours of frustrating trace statement debugging.

    About Don Bowman
    Don Bowman is a software designer with Hewlett-Packard. He is the co-webmaster for his division. Don has worked with Java on HP-UX and Windows 95 environments.

  • In order to post a comment you need to be registered and logged in.

    Register | Sign-in

    Reader Feedback: Page 1 of 1

    Enterprise Open Source Magazine Latest Stories . . .
    Apache Deltacloud, the Red Hat-contributed ReSTful API that abstracts differences between clouds so services on any cloud can be managed – provided of course there’s a driver – has graduated from the Apache Foundation’s incubator and is now a full-fledged Top-Level Project (TLP). The...
    With Cloud Expo 2012 New York (10th Cloud Expo) just four months away, what better time to start introducing you in greater detail to the distinguished individuals in our incredible Speaker Faculty for the technical and strategy sessions at the conference... We have technical and st...
    AMD said late Tuesday that its chief sales officer Emilio Ghilardi had left the company and that CEO and president Rory Read is going to do his job while a replacement is sought. AMD didn’t say why Ghilardi left but it’s assumed Read wants his own people. Read is relatively new to th...
    During the lifespan of M3 (Monitis Monitor Manager) there has always been something lacking – timers. M3 execution procedure was outlined in this previous article. The execution mentioned in the latter was a one-time-execution, whereas server monitoring requires periodic invocati...
    Red Hat is putting its bought-in Gluster scale-out NAS storage technology, acquired in October, on the Amazon cloud. It’s styled Red Hat Virtual Storage Appliance for Amazon Web Services and other clouds are supposed to follow in short order.
    A new episode of the screencast series is now available at the OpenNebula YouTube Channel. This screencast demonstrates the new easily-customizable self-service portal for cloud consumers. Its aim is to offer a simplified access to shared infrastructure for non-IT end users. The scree...
    Subscribe to the World's Most Powerful Newsletters
    Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
    Click to Add our RSS Feeds to the Service of Your Choice:
    Google Reader or Homepage Add to My Yahoo! Subscribe with Bloglines Subscribe in NewsGator Online
    myFeedster Add to My AOL Subscribe in Rojo Add 'Hugg' to Newsburst from CNET News.com Kinja Digest View Additional SYS-CON Feeds
    Publish Your Article! Please send it to editorial(at)sys-con.com!

    Advertise on this site! Contact advertising(at)sys-con.com! 201 802-3021


    SYS-CON Featured Whitepapers
    ADS BY GOOGLE