Links: 11-28-2007

Java ZipEntry bug on Windows

I rolled out the Clearfox plugin on the Jive Software Community site a couple weeks ago and got some good feedback and some bad feedback. A number of people said they tried to install the Firefox part of the plugin, restarted Firefox and then didn’t see the Clearspace icon like my screenshots / screencast showed. There were no errors in the Clearspace error logs and no errors showed up in the Firefox JavaScript debug console. Through the help of a couple customers, I was able to narrow it down to running Clearspace on Windows: for some reason the zip file (really the XPI file) that the Clearfox plugin creates on the fly was invalid, at least according to Firefox. If you opened the XPI file using any common zip file utility the contents appeared to fine. As always, google came to the rescue and pointed me to this bug filed on, which has two parts. The Unicode file name bug didn’t matter to me, but this one did:

Within a ZIP file, pathnames use the forward slash / as separator, as required by the ZIP spec. This requires a conversion from or to the local file.separator on systems like Windows. The API (ZipEntry) does not take care of the transformation, and the need for the programmer to deal with it is not documented.

which wouldn’t hurt so much if it hadn’t been filed back in… get this… 1999. Are you kidding me?

Anyway, long story short: if you’re writing Java, creating a zip file that has paths while on a Windows based machine and deploying said zip file to a place that actually cares about the zip file specification (or violates Postel’s Law), then make sure to do something like this in your Java code:

String zipFilePath = file.getPath();
if (File.separatorChar != '/') {
  zipFilePath = zipFilePath.replace('\\', '/');
ZipEntry zipAdd = new ZipEntry(zipFilePath);

noting that even the workaround they give in the aforementioned bug is incorrect because they show

... file.getName();

which doesn’t contain the path separators. Awesome.

Java, Commons HTTP Client and HTTP proxies

If you’re living at a giant corporation during the day and you want to browse the web you’re probably going through some sort of proxy to the outside world. Most of the time you don’t care, but if you’re writing a Java application that needs to access resources on the other side of said proxy (ie: the rest of the world), you’ll eventually end up over here. That wonderful document will hook you up with all your need to know about setting the proxy host, port and optionally a username and password for your proxy as long as you’re using URLConnection, HttpURLConnection or anything that deals with the class URL. If you’re really a go-getter you might even browse over here and read all about how to utilize those properties on the command line, in code or when you’re deployed inside of Tomcat.

Some of you won’t be so lucky: you’ll eventually want to use some advanced tools that abstract you away from having to fetch InputStreams to get your feeds and will instead depend on the Commons HTTP Client, which unfortunately (or fortunately depending on your point of view), doesn’t care about those nice little system properties that likes and instead goes off and uses sockets directly. No, instead you have to do something like this:

HttpClient client = new HttpClient();
HttpConnectionManager conManager = client.getHttpConnectionManager();
client.getHostConfiguration().setProxy("", 8080);

and if you want to provide a username and password for said proxy:

HttpState state = new HttpState();
state.setProxyCredentials(null, null,
   new UsernamePasswordCredentials("username", "password"));

which is all fine and dandy but sometimes I just wish the world were simpler. Ya know?

Books, the last 12 months

It’s been almost exactly a year since I last pointed to my reading list, turns out I’ve read about 30 books in the last 12 months, highlighted by seven in the month of July (mom-in-law got me a gift certificate to Barnes & Noble for my birthday so I splurged and then read them all in quick succession). Here’s the list in reverse chronological order with no spacing:

The World Is Flat A Rumor of War The Ghost Map The End of Poverty The Design of Everyday Things Purple Cow: Transform Your Business by Being Remarkable
Small Things Considered: Why There Is No Perfect Design The Soul Of A New Machine The Last Night of the Yankee Dynasty: The Game, the Team, and the Cost of Greatness Seven Seconds or Less: My Season on the Bench with the Runnin’ and Gunnin’ Phoenix Suns The Teammates: A Portrait of a Friendship Stiff: The Curious Lives of Human Cadavers Mountains Beyond Mountains: Healing the World: The Quest of Dr. Paul Farmer Collapse: How Societies Choose to Fail or Succeed Acts of Faith Traveling Mercies Founders at Work: Stories of Startups’ Early Days Micro-ISV: From Vision To Reality To End All Wars SR-71 Revealed: The Inside Story The Architecture of Happiness Don’t Think of an Elephant: Know Your Values and Frame the Debate The Scandal of the Evangelical Mind Skunk Works: A Personal Memoir of My Years of Lockheed Next Crossing the Chasm The Man Who Shocked the World: The Life and Legacy of Stanley Milgram Clemente: The Passion and Grace of Baseball’s Last Hero This Beautiful Mess Love Me, Hate Me: Barry Bonds and the Making of an Antihero

I haven’t come across many new books lately (I keep my to-read list at Amazon and my have-read list here) so ping me ( if you’ve read something cool lately.