Saturday, September 23, 2006

AJAX - Towards a Rich Web Interface

A fundamental determinant of the richness and usability of a website is the ability of the site to respond quickly to a user request. This may appear at first glance to be an easy task however there are a number of subtleties involved. Indeed some of the very strengths of the internet and n-tier architectures can result in a weak user experience. For example, the use of thin clients results in all computation and processing taking place on the server. This implies that any change in the user capabilities requires the client to go to the server to obtain the next page. This results in a large amount of requests being sent to the server and back to the client. To make matters worse the HTTP protocol that the requests use is inherently slow on account of the fact that utilizes TCP/IP. TCP/IP is a protocol that controls the movement of small pieces of data (packets) over the internet. The primary strength of TCP/IP is reliability. However, it achieves this at the expense of speed. These and a few other factors cause the response times of web based applications to be slow. This results in lower user productivity and experience.

AJAX is essentially an optimization to the way web sites are built. By using AJAX a programmer is essentially reducing the amount of traffic that needs to go across the web. This is achieved by transporting only the necessary amount of data between the server and client. For the most part AJAX uses technologies a programmer is already familiar with. These include JavaScript, XML, Webservices and SOAP.

A typical routine that will work within Internet explorer will make use of a DOM object to make a request to a server or webservice. The resulting response to the request is then parsed to extract the information desired. This information is then used to update the page being displayed to the user.

The Request
In the first step a programmer will initialize an ActiveX object as follows:
request = new ActiveXObject("Microsoft.XMLHTTP");

Next the request is initialized to indicate whether it is secure or not. The URL that the request is headed to is also specified here.
request.onreadystatechange = callback;
request.open("POST", URL, true);


Next, the request header is specified to identify the web service (SOAP Action) being used and the content type
request.setRequestHeader("SOAPAction", "http://www.ignyte.com/whatsshowing/GetTheatersAndMovies");
request.setRequestHeader("User-Agent", "Mindreef SOAPscope 4.1.2000 (http://www.mindreef.com")
request.setRequestHeader("Content-Type", "text/xml; charset=UTF-8");


Finally the request is sent to the server or webservice
request.send(xml);

The Response
The response to the request is processed as follows:
The programmer defines the ActiveX object that will store the response.
var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");

The response text is then loaded from the request to the response
xmlDoc.loadXML(request.responseText);

The values are then extracted from the response and the document is built from the response and request.
extractValues(xmlDoc);
document.getElementById("request").value = request.responseText;
document.getElementById("result").innerHTML = html;


The resulting document is then redisplayed.

Conclusion
The above code shows us that AJAX is not a novel technology. However, it is a novel concept. It ensures a clean separation of user interfaces from the underlying code. This enables website to deliver richer content with faster response times.

Friday, August 19, 2005

Script to detect a modified file

Some times it is necessary to detect whether a file has been modified before performing a number of activities. These activities could be defensive in nature if the file was not to be changed for security reasons, for example, or it could be routine in nature such as archiving the file. Here is an example script that will identify a file change.

The script simply runs a infinite loop that checks whether the fingerprint of the file (the md5 checksum) has been modified. If it detects a change the script will notify the administrator via an email.

#!/bin/sh
target=target.txt
baseline=/tmp/passwd.base
timer=60
md5sum $target > $baseline
while [ 1 = 1 ] ; do
if [ "`md5sum $target`" != "`cat $baseline`" ] ; then
echo File $target was changed at `date` mail -s "$target changed!" root
exit
fi
sleep $timer
done

However, the reader should note that the above file will not detect changes if the intruder made an attempt to cover his tracks. One way of detecting whether someone has changed files and then covered his tracks is to use the suditing facilities provided within the operating system kernel. For example is Solaris, the reader could use the BSM audit facility to determine who did what to the file under consideration.

The applications every java developer needs in his/her portfolio

Other Tools
XDoclet - This tool will save you lots of time. It generates code based of metatags added by the developer to his code.
JBrowser - Helps you peek into a library to determine what its interfaces look like. There are a number of situations where you may not be able to decompile a library but will be allowed to inspect it for its interfaces. Hey its a little better than code without any documentation.
InstallAnywhere - If you ahve installed an application by yourself, chances are that you ahve used installAnywhere. It supports the installation of software onto virtually any platform.
JavaDoc - FOr God's sake and the love of a fellow java developer who will come after document your code. With a tool like javadoc, the only excuse you really have to not writing well documented code is your own laziness.
WinZip - I do not need to add much, when it comes to this tool. It can help you peek into libraries, move compressed code via email (remember that time when CVS just did not work) and much much more.
APT - The annotation processing tool is new with the latest release of Java. It works the same wonders by enabling the use of metatags. Might signal the end of XDoclet.
ExtCheck - This tool helps resolve conflicts within java libraries.
Ant - Like its real world counterpart, this tool lifts ten times its weight. Its flexibility allows a developer to create utilities on the fly if needed.

Decompilers
Jad - If you have ever had to maintain Java code for which no documentation was available, then you understand how miserable life can be. This decompiler, does a decent job of unpackaging archives and generating the source code. Now tie this in with any reverse engineering tool that ships with most commercial grade design application and voila, you have a object model that can help keep suicidal thoughts at bay.

Debuggers
Assure - If threads are what you love then this tool will assuredly help you fly. It helps walk through some of the grittiest thread contention problems.

Text Editors
Notepad - A standard utility that is shipe with every Windows install. It is very handy for viewing content of files and eliminating garbage characters
EditPlus - A step above notepad but not yet a full fleged IDE. Allows for multiple syntax, text highlighting and ftp.


IDE
Eclipse - This freeware version is rapidly becoming the IDE of choice in the Open Source world. It is built on an open framework, has tons of plugins that make most tasks like ORM mapping a breeze.

Continuous Integration
Cruise Control - Another open source application that allows for running test scripts and prescheduled times. Perfect for moving most of the automated testing to off peak hours when developers are not around.

Unit Testing
Junit - 'Never has so much been owed to so little code' - Martin Fowler. Need I say more. If you believe in test oriented development then this is a must have.
JCover - If you need to ensure that your testing covers the code adequately, then JCover will help you go a long way. The great thing aobut it are the metrics it generates. THe fluff guys on the team really like those.

Bug Tracking
In house - no hooks to source control

Profiling
Jprofiler and Jprobe

Source Code Control
CVS - With this in place your programmer cannot use the "Computer ate my homework" excuse.

Build Tools
JAR and WAR Files (not sure what they are thinking here?)


Application Framework
Spring

Grid Computing Framework
DataSynapse

Logging
Jakarta commons logging

XML
javax.xml

Web Front-end
Struts
Spring/Tiles

ORM/Database
Hibernate
TOAD - This tool is definitely the best on the market. It is a pity that it now comes with a license and one has to pony up quite a penny for it. But the time and effort that are saved are invaluable.

Messaging
Joram

Reporting
JFreeChart - THis utility allows you to create nifty charts and integrate them into your reports. Worth a try