Mar 7 2006

Rails Book

I’ve had the Agile Web Development with Rails book authored by Dave Thomas and David Heinemeier Hansson for some time. Looking through Amazon I found out that there are several Rails book coming in the next few months. Dave Thomas is a good author, I also have his PickAxe book Programming Ruby: The Pragmatic Programmer’s Guide. In this post I want to quote some insights from Dave Thomas found in Agile Web Development with Rails.

The needs of the developer are very different when writing code, testing, code, and running that code in production. When writing code, you want lots of logging, convenient reloading of changed source files, in-your-face notification errors, and so on. In testing, you want a system that exists in isolation so you can have repeatable results. In production, your system should be tuned for performance, and users should be kept away from errors.

Why use an artificial primary key such as id?
The reason is largely a practical one – the format of external data may change over time. For example, you might think that the ISBM of a book would make a good primary key in a table of books. After all, ISBNs are unique. But as this particular books i being written, the publishing industry in the US is gearing up for a major change as additional digits are added to all ISBNs.

There are few absolutes when it comes to performance, and everyone’s context is different. Your hardware, network latencies, database choices, and possibly even the weather will impact how all the components of session storage interact. Our best advice is to start with the simplest workable solution and then monitor it. If it starts to slow you down, find out why before jumping out of the frying pan.

Use GET requests to retrieve information from the server, and use POST requests to request a change of state on the server.


Mar 6 2006

WebStart HeadStart

Java’s WebStart was to solve some deployment problems, but recently I’ve had two deployment issues with it. The first issue is as follows; using Internet Explorer I would get the following error when trying to open a WebStart JNLP file:

An error occurred while launching/running the application.
Category: Invalid Argument Error
Could not load file/URL specified:
C:\...\Content.IE5\...\webstart[1].jnlp

The Wrapped Exception states that this is basically a FileNotFoundException on the client side. What happened was that IE didn’t cache the JNLP file on the client side and WebStart can’t find the JNLP file when it tries to launch the application. I found some advice on forums after googling for ‘WebStart Content.IE5’ and other search terms. Some forums stated that I needed to clear IE’s cache. Others suggested that I had to move the IE cache to a different directory. What worked for me was that I had to explicitly tell IE to cache the JNLP file using some JSP code.

// Set IE HTTP/1.1 no-cache headers.
response.setHeader("Cache-Control",
   "post-check=900, pre-check=3600");
// Set standard HTTP/1.0 no-cache header.
response.setHeader("Pragma", "cache");

The other problem with WebStart that I have had in the past is in the way you auto-detect if WebStart is installed. To auto-detect Sun’s documentation provides you with some nasty client side JavaScript and Vbscript code. It is nasty because it is doesn’t even works properly, a bug is filed for this. I have two machines, both of which have Java 1.4.2_08 installed. But for some reason only one machine can create a JavaWebStart.isInstalled.1.4.2.0 object using the Visual Basic script on IE. This must be a Java plugin problem. A way around this is to use IE object tag. The following bit of code is what Sun provides you to auto-detect if your client has WebStart installed.

<script type="text/javascript" language="javascript">
var javawsInstalled = 0;
var javaws12Installed = 0;
var javaws142Installed = 0;

isIE = "false";
if (navigator.mimeTypes && navigator.mimeTypes.length) {
   x = navigator.mimeTypes['application/x-java-jnlp-file'];
   if (x) {
      javawsInstalled = 1;
      javaws12Installed = 1;
      javaws142Installed = 1;
   }
}else {
   isIE = "true";
}
</script>

<script LANGUAGE="VBScript">
on error resume next
set jws = "JavaWebStart.isInstalled"
set jws12 = "JavaWebStart.isInstalled.2"
set jws142 = "JavaWebStart.isInstalled.1.4.2.0"
If isIE = "true" Then
  If Not(IsObject(CreateObject(jws))) Then
     javawsInstalled = 0
  Else
     javawsInstalled = 1
  End If
  If Not(IsObject(CreateObject(jws12))) Then
     javaws12Installed = 0
  Else
     javaws12Installed = 1
  End If
  If Not(IsObject(CreateObject(jws142))) Then
     javaws142Installed = 0
  Else
     javaws142Installed = 1
  End If
End If
</script>