Tuesday, November 13, 2007

Lab 4 Postmortem

To start, I grabbed the Java libraries for Akismet and SQS services. They were so simple that the submit process work first shot. WOW! I took me another 2 hours to shore-up the error checking.

Lab 3 Postmortem

UI Implementation
The templating engine I chose to use is Velocity. This is great because all I have to do is:

1) determine which objects will be visible to the velocity template and use it in teh html (actually *.vm) file to populate the dynamic data.
2) in the servlet, inject the Java objects I used in step (1) into the template context.

Getting the listings
Here, I used HttpClient to maje the "GET" calls.

Overall coding
This lab required a bit more programming than the previous labs. This was mainly because I wanted to add some smarts to the page navigation.

Lab 2 Postmortem

Mapping the URLs
The most complex part of this lab was matching the URL signatures. I played with Tomcat for a while, but realized that using mod_rewrite with Apache would be much easier. Here are the steps:

1) mod_rewrite comes with Apache 2.2 so just uncomment the module in the httpd.conf file.
2)add the following lines to the end of httpd.conf:

# Send cs462 labs to worker named default
JkMount /cs462lab2/* default

This will send all URI's which start with "/cs462lab2" to tomcat.
3) add the file ".htaccess" to the default docs dir of Apache. This file contains the regex rules for rewriting the URL.

4) add the following lines:

RewriteEngine on
RewriteRule ^index$ cs462lab2/SiteLister?option=index [NC]
RewriteRule ^domain/(([a-z0-9]([-a-z0-9]*[a-z0-9])?\.)+((a[cdefgilmnoqrstuwxz]|aero|arpa)|(b[abdefghijmnorstvwyz]|biz)|(c[acdfghiklmnorsuvxyz]|cat|com|coop)|d[ejkmoz]|(e[ceghrstu]|edu)|f[ijkmor]|(g[abdefghilmnpqrstuwy]|gov)|h[kmnrtu]|(i[delmnoqrst]|info|int)|(j[emop]|jobs)|k[eghimnprwyz]|l[abcikrstuvy]|(m[acdghklmnopqrstuvwxyz]|mil|mobi|museum)|(n[acefgilopruz]|name|net)|(om|org)|(p[aefghklmnrstwy]|pro)|qa|r[eouw]|s[abcdeghijklmnortvyz]|(t[cdfghjklmnoprtvwz]|travel)|u[agkmsyz]|v[aceginu]|w[fs]|y[etu]|z[amw]))/?$ cs462lab2/SiteLister?option=domain&domain=$1 [NC,L]

That's it!

Calling HTTP Get
Because I'm using Java and Servlets, I have the luxury of choosing from many open-source libraries.
1) To call S3 for the data, I used HttpClient which is great for Http Get and Post calls.
2) To convert the JSON data to Java types, I used json-lib.
3) To format the XML, I used JDOM.

These libraries minimized the code I had to write.