Monday, April 23, 2007

Extending Domino with Java - Part 2 - Simple Java

Now that we've downloaded eclipse, lets install the IDE and take a look. The eclipse install is easy - just unzip the folder to a directory of choice, it doesn't update the registry - simple and easy. I usually navigate to eclipse.exe and add a short cut to the desktop.

When I startup eclipse and I get the following error which means that I forgot to install the JSDK.

After I installed the JSDK eclipse starts up and stops to prompt you for the location of the workspace. I've chosen c:\workspaces\workspace so that I can keep them in one easy to backup location.

Next, close the Welcome screen and you then be in the Java perspective. Perspectives are the way that eclipse organises the files for different users and tasks. The default for the WTP is the Java perspective.

From the File > New > Other select the Java Project and enter an appropriate name and leave the default JRE selected.

The next Step is to get the HTTPClient code that we want to reuse. Using open source code can be hit and miss on the documentation front. Newer versions of projects do not have a great deal of documentation. However, the established project usually have more than enough examples, documentation and tutorials to get you started.

We'll download the HTTPClient 3.1 rc 1 version from the HTTPClient Project. We'll also need the other prerequsite projects, although we can skip the Junit project. Each zip file contains documentation and the *.jar files. These are the libraries that we want to reuse. I usually collect them into one single directory of jars that I want to reuse, in this example c:\lib.

Select the new project and in the properties > java build path select to add external jars. Navigate to the single directory and add each one.

So lets finish with a simple test - to confirm that we've got all the files that we need. There is a complete example in the HttpClient website. Select File > New > Class and enter the name of the class as HttpClientTutorial. The copy and paste the tutorial code. If everything is ok there should be no errors or warnings in the problems tab.

So lets execute the program. Select the java class file in the package explorer and then select run > run as > java application. This runs the class and starts with the main method. In the console tab you should see the html code for the website.

That's it a simple java program that gets the xhtml from a website using a http client. However, in this format is not easy for domino to consume. We will need to be able to pass parameters and decide how to handle errors, essentially hiding some of the complexity.

In the next post we'll build a facade to the HttpClient for use in Domino and add in authentication - ready for integration into a domino java agent.

Sunday, April 22, 2007

Extending Domino with Java - Part 1 IDE

When I answered the post on codestore I was sure that somewhere I had a working sample of domino and the HTTP client code that I did on a very short project. I searched on every dvd archive, thumbdrive and folders on my workstations to no avail.

So what next ?

Well, it didn't take long to write the code in the first place. The projects was only two days worth of consulting (over a year ago), so over the next week (or maybe two) in my spare time in the evenings we'll build it from scratch. To answer Rafaels question - yes I did get the authentication working with the proxy server. However, I don't have access to one for this exercise, so you might have to do some trial and error. I can point you in the right direction though.

It's not a bad idea to revisit the sample and using all of the latest code versions and libraries.

So where should I start ? I don't want to go over stuff that you may already know and I don't want to leave out important steps for the newbies to java and domino. For the experienced you can skip to the bits that interest you.

I think that maybe the first thing to do is start with the a decent Java IDE as Java in the Notes Designer leave a lot to be desired.

For this exercise I'll use Eclipse as its free and is the foundation for Rational Application Developer (RAD) so its familar when you are switching between them. Of course deciding on Eclipse is not that simple as there a few choices for eclipse.

First there is the standard IDE - around 90Mb - great for pure java programming but not many wizards or tools for anything else.

Next there is the Eclipse Web Tools Project (Eclipse WTP) - around 200 Mb - which provides tools for web and j2ee development.

Then there is the Eclipse Callisto Distribution from IBM - around 300 Mb - which bundles Web Tools Platform (WTP), Graphical Modeling Framework (GMF) and
Test and Performance Tools Platform (TPTP).

It's also worth mentioning MyEclipse they have an annual subscription service for a standard version for $30 USD or $50 USD for the professional version. For that you get all the updates plus support.

And the most feature rich of all the eclipse IDE variants is IBM's Rational Application Developer . It also has a price to match - 5,452.99 AUD.

There are other Java IDE's that are out there but I use the eclipse variants because sometime I have to use RAD as that's what the client uses and sometimes they don't have RAD and so the free versions are easier to install for some simple Java development. The bundles are good as they take some of the hard work out of ensuring that all the prerequisite components are installed too.

Lets use Eclipse WTP 1.5.3 and download the 'all-in-one' file from the download area. You'll also need to download a java sdk I would suggest picking one that matches the JVM version supplied with the version of Domino that you are using - that way the IDE will highlight any problems that you would otherwise encounter when you come to include the java code in Domino. So for Domino 6 - that's JSDK 1.3 and for Domino 7.0.2 that is JSDK 1.4.2. We'll use 1.4.2_13 from the Sun archive area.

Anyway that's enough for one night - next session we'll install Eclipse and the Java SDK, download the HTTP client jars and build the first test.