Mar 16 2009

Cloud Computing Streak Marks

In response to my post The Beginning of the Real Mess in the Clouds I received several emails / twitters / comments saying some variation of “these are easy problems to address” or “the cloud computing providers will quickly fix all this stuff and even my mother will be able to use cloud computing.”

Uh huh.  Here’s another one.  We’ve got hundreds of these already and it has only been 75 days since we started the company.

A heads up to anyone attempting to connect to Slicehost using Java:

There is a subtle bug in the JDK (including 1.6), such that long username/password combinations (like the long username used with the Slicehost API) are encoded improperly in an HttpURLConnection. If you include the username in the URL, you will get a 401 error; if you attempt to use an Authenticator you will get an exception from Java that there is an invalid line. The solution is to override the base64encoder and set the authorization property manually OR potentially use the Apache Http client rather than the built-in JDK client.

Here is the basic code for the solution:

static final String Credential = "my Slicehost API username here"; // the part before the @

class LongLineBase64Encoder extends BASE64Encoder { @Override public int bytesPerLine() { return 1024; } }

URL ServiceURL = new URL("https://api.slicehost.com/slices.xml");

HttpsURLConnection Conn = (HttpsURLConnection) ServiceURL.openConnection(); String EncodedUsername = (new LongLineBase64Encoder()).encode(Credential.getBytes());

Conn.setRequestProperty("Authorization", "Basic " + EncodedUsername); Conn.connect();

What part of mess wasn’t I clear about?  Oh, and my mother is really smart, but I’m betting that “The solution is to override the base64encoder and set the authorization property manually OR potentially use the Apache Http client rather than the built-in JDK client” doesn’t mean much to her.