Sorry for never posting a solution to this. The problem above was the manual setting of the authetication headers incorrectly. Basic Authentication headers must be set following the defined protocol for HTTP requests, which is very well documented and a great example of how to do it can be found here: http://en.wikipedia.org/wiki/Basic_access_authentication#Protocol
Basically, the Authorization header should look similar to the following:
Authorization: Basic QWxhZGluOnNlc2FtIG9wZW4=
Above example set the header but did not Base64 encode the authentication string. Encoding the string using the above code should get you authenticated using Basic authentication over Java. As Shannon has pointed out in other threads, Basic authentication is depricated. In future versions of the API, we will no longer support Basic Authentication and when we depricate the current version of the API, likely next year, there will be an end of life put on Basic Authentication. We highly recommend taking the time now to understand and implement OAuth 2.0 now rather than have to implement Basic Authentication now and then learn OAuth 2.0 later on.
... View more
I looked into your code which was written with Apex from salesforce which is a language I am not all to familiar with. However I can see some errors in your code specifically with the connection. Please take a look at my exampl of my connection string:
String apikey = 'myapikey';
String username = 'myname' ;
String password = 'mypwd' ;
Blob headerValue = Blob.valueOf(apikey + '%' + username + ':' + password);
This should fix your 401 error.
Please let me know what the results are.
... View more