Wednesday, December 12, 2007

Lab 5 Finished

Now I hope I have everything working (it seems to be). I would have to say that this lab gave me the most stress. It might be due to the end of the semester as well, but I had a lot of difficulty getting this lab to work and being able to port it to another machine (more on this later). I'm mainly posting most of this information for my own benefit. So, if I ever do something like this again, I know where to look.

First of all, I chose Java to implement the approval client. I started writing it out in Swing, and thought there's got to be a better way. I noticed that some of you used NetBeans, so I gave it a try. I love NetBeans 6.0; it is extremely easy to create the layout for the UI.

After I built the UI, I tried tackling communicating with Amazon SQS. It was tricking finding a library that would work for me, but I found typica quite useful. This site tells you the jar files needed and gives an example of accessing the SQS queue. I incorporated the jar files into my project, and typica worked wonders.

Then I needed to parse and create XML for the ideas. I used the DOM feature. It might not be the best way to do it, but recently I have been programming in Javascript to open an XML (I wanted on offline search feature in HTML/Javascript). I used DOM plenty of times in Javascript. The javax.xml and DOM library acted very similar. So, it was quite easy to implement.

Lastly, I tried to implement Whois feature. This caused me the most pain. I downloaded Eclipse and Apache Axis 2.0 WSDL2java generator. I was able to generate java from the wsdl file, but I could not figure out how to use those java files. I tried some other wsdl/soap libraries, but had trouble using those as well. Then I tried implementing my own version of soap, by creating an http connection and sending XML. That failed as well. Then I looked for ways to use wsdl in NetBeans. And I found one. Right click on your project, create new web service client, and there's an option for WSDL. Create a packet name for the Java files, click finish and BAM! you have complied Java files.

To get whois info, I used:
Whois wi = new Whois();
WhoisSoap wisoap = wi.getWhoisSoap();
whoisData = wisoap.getWhoIS(domain);

And then I had my client working. . . WRONG! It only worked on my on computer through NetBeans. I got the error: "java.langLinkageError: JAXB 2.0 API is being loaded from the bootstrap classloader, but this RI (..) needs 2.1 API," when running from command prompt or another machine. It took me forever to solve this problem, and I couldn't bring my computer in to pass off since it's a desktop. Anyways, here is the solution:
  1. Download jaxws 2.1 if you haven't done so or isn't already installed. It would be in under java1/modules/ext in NetBeans directory if installed.
  2. Copy the folder api in jaxws21 to your project's directory.
  3. Then add the following to the java -jar command:
    1. -Djava.endorsed.dirs="[project_path]/api"
  4. What that does is it overrides the classbootloader to load JAXB 2.1 instead of 2.0.
And there you have it.