I started by creating the HTTPFacade class as the intermediate layer between the HttpClient and the Domino Agent class. I could have extended tha HttpClient but that would mean that I would be reliant on the underling libraries. I decided against that.
The first thing that needs to happen is to extract all of the information that the HttpClient needs so that we can set those values through either the constructor or setters. I used member variables as part of the class to store things such as the url, usernames and passwords. This brings me to eclipse tip #1. One of the features of eclipse that I like is that if you create your member variables and then right click source > generate getters and setters eclispe will create all of the code.
Once I had the facade ready but without the authentication I ran it against a secure website. The following message came up in the exceptions. It give you some solid information as to how to start setting up the authentication options.
May 17, 2007 9:23:16 PM
org.apache.commons.httpclient.auth.AuthChallengeProcessor selectAuthSchemeINFO:
basic authentication scheme selectedMay 17, 2007 9:23:16 PM
org.apache.commons.httpclient.HttpMethodDirector processWWWAuthChallengeINFO: No
credentials available for BASIC 'By Invitation Only'@web:80
A quick look at the documentation and a few refactors later I ended up with the following addition to the original code.
I also added a few other methods to the standard executeMethod, such as executeMethodWithWebsiteCredentials and executeMethodWithWebsiteAndProxyCredentials. Yes I know long names, but at least you can tell what they do.if (this.isWebsiteCredentialsUsed())
{
client.getParams().setAuthenticationPreemptive(true);
Credentials defaultcreds =
new UsernamePasswordCredentials(this.getWebsiteUser(),
this.getWebsitePassword());
client.getState().setCredentials(new AuthScope(this.getHost(),
this.getPort(),
AuthScope.ANY_REALM),
defaultcreds);
}
Next I had two choices. One, test this in Domino or Two, create a unit test class that I can unit test the facade. For simplicity sake I chose the java unit test, by creating a mockAgent object.
Here comes eclipse tip #2. Document your methods, getters and setters as you go, that way when you type ahead inspects your code you get a nice description to help you write the your code. For something this simple it's probably not that much of an issue, but if you have lots of custom code then it a great help. This is one of the feature that I so, so would like to see in Domino designer.
I've included attached the two java files. I've included the proxy authentication which might or might not work. I now have access to a proxy server so I will get around to testing this, but I didn't want to delay publishing this bit so far.
Link : Java Source.
Next Part : Integrating into a Domino application.
No comments:
Post a Comment