Java / Web Developer Job Opening: Southern Massachusetts

Don’t bother applying unless you live in or around southern Massachusetts or are willing to relocate to southern Massachusetts. I work for the largest golf company in the world and I’m looking for a partner in crime. Strong Java, Struts and Hibernate experience will get you in the door (proving that you know Java inside and out will work too); loving your work will get you a job. Email me your resume if you’re interested.

The ‘using’ keyword

Joe pointed out that the C# PGP decryption code that I wrote could be better; specifically I should be checking the xExitCode property of the Process instance and the code would also be better served if I made certain that I disposed of the Process instance by calling the Close() method when I’m done using it. The ExitCode improvement is relatively simple to add; start the process, read any lines of output and then check the ExitCode to see if everything went smoothly:

Process process = Process.Start(psi);
while(!process.HasExited) {
... // do stuff
if (process.ExitCode != 0) {
// something went wrong..

The second thing that Joe mentioned was the ‘using’ statement, which is a novel feature of C# that provides “… an easy way for C# code to acquire and release unmanaged or otherwise precious resources.” The code I originally wrote didn’t destroy the handle to the process; after all was said and done I should have called the Close() or Dispose() method of the process:

Process process;
try {
process = Process.Start(psi);
} catch {

The ‘using’ statement is syntactic sugar that’s a shortcut for the well worn try / catch idiom and shortens the above example to:

using (Process process = Process.Start(psi)) {
... // do stuff w/ the process

which then automatically calls the Dispose() method of the process.

Joe goes on to hijack the ‘using’ statement in some other novel ways which should you check out when you have a chance.

Conflicting mindsets of C# vs. Java: Part II

You all read the the ‘Conflicting mindsets of C# vs. Java‘ weblog post right? And you all noticed that the guys running the Lucene.NET project on sourceforge closed up shop, took all their toys and went on home right? I’m gonna go out on a limb and say that they’re related.

The way I see it, *in general* the .NET community conversation is dominated by talk about the latest and greatest that microsoft is putting out; there’s talk about MapPoint Location Server, SQL Server, Longhorn, ASP.NET 2.0 and Visual Studio; all products of Redmond. The same group of Java developers are talking about JBoss, Hibernate, Struts and Eclipse: none of which came out of the Silicon Valley.

Malcolm’s mindset #1 says that .NET developers accept the tools and services that are provided them by Microsoft and I think for the most part this is true. You don’t see .NET developers spending their cycles on persistence layers, web application frameworks or caching solutions probably because Microsoft has provided Microsoft solutions for all these problems. But if it’s just providing tools, then why aren’t JSF, JDO and NetBeans dominating the javablogs conversations? Seriously, take a look at ASP.NET and JSF. They aren’t that different and yet ASP.NET is widely used in conjunction with Visual Studio while JSF is rarely lauded and more often derided. I think he’s right, it’s really a mindset.

Which brings me back to the Lucene.NET guys. Why would they close up shop? Why not continue to donate their time and energy to an excellent cause? Maybe the Microsoft mindset has something to do with it. How about this: a search on google for ‘lucene’ within the domain yields exactly 17 results. The same search on yields 2570 results. Admittedly, Lucene has been around longer, but maybe one of the reasons that the Lucene.NET guys packed it up (and are now trying to sell their work) is that no one paid any attention to them because they were all too busy working with SQL Server full-text indexing, a tool given them by Microsoft (but one that costs thousands of dollars per processor). Another reason that a project like Lucene or Struts or Tomcat flourishes is because there is a certain amount of prestige working on a big open source project. If you work on open source projects for the prestige and you’re not getting the attention you think you deserve, you find another motivation. In their case money was a motivation, so they closed up project on sourceforge and they’re selling a personal edition and a business edition. They might make a couple bucks, but I bet in 1 year there won’t be many people writing about

So what’s my point? That all .NET developers are greedy and don’t care about the community? Not really. I think it’s that the two communities have different bus drivers: .NET developers look to Microsoft to provide the tools they need to do their jobs… and if they look elsewhere or copy something else, Microsoft will eventually come in and make a product of their own that does the job, thereby negating any work the developers do in the meantime. Microsoft drives the bus. Java developers look at the products and specs that Sun puts out and then go and build their own tools or frameworks or applications to do the job. Sun will eventually put out something through the JCP that does the job…. but the developers in the Java community will only use it if they want too, witness the continued popularity of Struts and the lack of interest in JSF. In the Java camp, the developers drive the bus.

Sending your Outlook calendar using Python

At work we’re required to send an email with our personal schedules at the beginning of the month to everyone in our group so that (at least until your schedule changes) everyone knows where everyone else is. Sure, we could be using a online calendar or some kind of group collaboration software but we’re stuck using Lotus Notes, which is the worst email client I’ve ever used (don’t believe me?). I switched to MS Outlook because a) I’ve used it before and b) the Notes Connector gives me access to the Notes server. Anyway, I’ve been wanting to tinker with Python for the last couple months and this seemed like the perfect project for it. Using the excellent win32com package, I was able to get a collection of all the items in my Outlook calendar, filter those events for the current month, put a message together with the subject, start date/end date and start time/end time and then send an email to an Outlook distribution list.

Since I’m new to Python, I’m going to walk through the code, narrating what I *think* is happening as I go along. A link to the finished product is available at the end, please let me know what, if anything, I’m doing wrong…

First things first, I import the appropriate modules (or packages?):

import win32com.client
import time
import datetime

After that I dive headfirst into Outlook getting an Outlook Application object, log on to the MAPI namespace, and retrieve all the items in the Outlook Calendar. Most examples I saw using ‘olCalendar’ as the argument to the GetDefaultFolder() method, but got the impression that ‘olCalendar’ is some sort of intrinsic constant that I didn’t have access too. This page that listed all the Outlook constants was where I got the number nine.

outlook = win32com.client.Dispatch("Outlook.Application")
namespace = outlook.GetNamespace("MAPI")
appointments = namespace.GetDefaultFolder(9).Items

Next I sort the events by Start Date (right?) and flip the ‘include recurring events’ flag to true:

appointments.IncludeRecurrences = "True"

After that I do a bit of date munging to get the starting month/year and the last day of the month/year, use the Restrict() method to filter out only events in the current month and sort the events again:

# start date
monthNow = now.month
yearNow = now.year
begin =, now.month, 1)
# end date
nextMonth = begin + datetime.timedelta(days=35)
end =, nextMonth.month, 1)
appointments = appointments.Restrict(
  "[Start] >= '" + begin.strftime("%m/%d/%Y") +
  "' AND [End]
Now I'm left with a filtered and sorted collection of Outlook calendar items so the next step is to loop over the results, adding the subject, start time and end time to a message string:

appointment = appointments.GetFirst()
message = begin.strftime("%B, %Y") + " Meetings & Events for Aaron Johnson\n"
message += "

daily links

· The guys at Search Engine Watch have a blog now…

· Python date handling tutorial

· Java Open Single Sign-On Project: an open source J2EE-based SSO infrastructure aimed to provide a solution for centralized platform neutral user authentication.

· Better Software magazine: delivers relevant, timely information to tackle the challenges of building better quality software, regardless of your role in the software development lifecycle.

· Better Software magazine on Continuous Integration

· CruiseControl: I need to start using this…

· No balls. No babies.

PGP Decryption using C#

Sorry if the PGP meme is getting old, I had to write some new code yesterday that decrypted a file full of ciphertext and I didn’t see any other examples on the net, so it gets posted here for posterity. Just to frame the issue, the ciphertext is actually stored in the database, so I first extract the ciphertext from a text column, write the ciphertext to a file, decrypt the file, read the results and then delete the file:

// get ciphertext from DB
// and write to a file
// ...
string passphrase = "my_passphrase";
string filename = "myapp\encrypted.asc";
ProcessStartInfo psi = new ProcessStartInfo("pgp");
psi.UseShellExecute = false;
psi.RedirectStandardInput = true;
psi.RedirectStandardOutput = true;
psi.RedirectStandardError = true;
psi.Arguments = filename + " -m -z " + passphrase;
Process process = Process.Start(psi);
string line = null;
string message = null;
while((line = process.StandardOutput.ReadLine()) != null) {
message = line;
Console.WriteLine("message = " + message);

If you’re scoring at home, I used the ProcessStartInfo and Process classes from the .NET Framework to invoke pgp.exe from the command line passing the -m flag so that the decrypted message is printed out to the screen (instead of pgp.exe decrypting the message to a new file) and passing the -z flag so that I can send the passphrase as an argument as well. In my project the message is only one line so I iterate over the lines of output until I get to the last line… where the message is then saved in the message string instance.

Peeling away the code, you end up with this:

C:\pgp6.5.8>pgp c:\myapp\encrypted.asc -m -z my_passphrase
Pretty Good Privacy(tm) Version 6.5.8
(c) 1999 Network Associates Inc.
Uses the RSAREF(tm) Toolkit, which is copyright RSA Data Security, Inc.
Export of this software may be restricted by the U.S. government.
moreflagFile is encrypted. Secret key is required to read it.
Key for user ID: Aaron Johnson
1024-bit DSS key, Key ID ******, created 2004/09/02
Key can sign.
Just a moment...
this is the message

A caveat: if you run the above code from an ASP.NET web application make sure that ASPNET user has access to the private key.

By the way, the folks over at Bouncy Castle have a C# port of the their excellent Java encryption libraries, but it doesn’t appear that the org.bouncycastle.openpgp package has been ported just yet, otherwise I would have used that.

daily links

· Stop Win XP from Searching Within ZIP Files: how annoying is it when you try to open a folder and Windows XP thinks it has to list the contents of all the zip files in that folder?

· RIM Blackberry Mobile Feed Reader – seeking beta testers

· The Harvard Book Store’s bestseller list

· Michael J. Radwin’s talk on HTTP Caching @ the 2004 Oreilly Open Source Convention

· Peter Saint Andre: “… a short list of what I see as deficiencies in the Jabber community”

· Ibm on groovy

· Fun project to add to your daily build

· Parsing an MP3 with java

· Get your nutch t-shirt today