08 February 2008

Groovy 01 - SOAP Server

As much as I like BeanShell (bsh), once I found Groovy, I don't think that I've done any new bsh development. I'm going to follow up on my earlier bsh blog entry where I promised to show cool bsh features but first I really want to lay the ground work for an Enterprise Service Bus (ESB) -like tool that I've been playing with called XMLBlaster. Now XMLBlaster doesn't call themselves an ESB. Instead they say they're MOM (Message oriented Middleware) with a lot of features.

They're website says XmlBlaster is a publish/subscribe and point to point MOM server which exchanges messages between publishers and subscribers. The message is described with XML-encoded meta information. Messages may contain everything, GIF images, Java objects, Python scripts, XML data, a word document, plain text. Communication with the server is based on CORBA (using JacORB) or RMI or XmlRpc, clients are free to choose their preferred protocol. Other protocols like email, socket or SOAP may be plugged in.

Like usual, I'm starting to get ahead of myself as I want to talk about Groovy. If you're not familiar with this great language, you must pick up Groovy In Action (GINA) as this is the Groovy Bible.

I have a Groovy SOAP Server as one "end point" or client and a number of other legacy app nodes. I'm currently using Groovy 1.0 but 1.5.4 is the latest. This new version brings features like Java 5 annotations, generics and enums, it provides significant performance gains, new meta-programming capabilities, new and improved tooling support like the new joint Groovy/Java compiler, the new interactive shell, or the Groovy Swing console, and a few other additions in its syntax, like the new Elvis operator or the ability to omit parentheses in methods with named arguments to make DSLs even more readable. Sounds great. I'm convinced so I'm upgrading as I'm writing this entry.

Grab the Groovy download and give it a try.

All installed? Great, let's move along. SOAP is a lightweight protocol intended for exchanging structured information in a decentralized, distributed environment. Groovy has a SOAP implementation based on Xfire which allows you to create a SOAP server and/or make calls to remote SOAP servers using Groovy. Get the Groovy SOAP jar and drop it into the $GROOVY_HOME/lib folder.

[edit 19 Feb 2008]
The Groovy website seems to have a broken link to download the soap jar. Try to get the jar at the link mentioned above but if that fails, try this:
http://momupload.com/files/77499/groovysoap-all-1.0-0.3-snapshot_jdk1.5.0.jar.html
[/edit]

First we're going to make an incredible simple SOAP server and then test it with the browser. Create a file named LogServer.groovy that looks like this or grab a copy here.

---------LogServer.groovy---------

import groovy.net.soap.SoapServer

// define the API
void log(logTime, logMessage) {
// real code goes here but we're just printing to stdout for now
println(logTime + ' : ' + logMessage)
}

// start server on localhost.
// use whatever port you want
def server = new SoapServer("localhost", 6980)
server.setNode("LogServer")
server.start()

-------------------------------------------

One of the great things with Groovy is that you can call Java classes from Groovy and Java can call Groovy. Because Groovy is Java. With this in mind, your SOAP server can invoke any Java legacy app. In the example above, we're just writing to std out.

Start it up by typing: groovy LogServer.groovy

In your browser, enter: http://localhost:6980

And you should see an XFire page of the available webservices at that port:

Available Services:
  • LogServerInterface [wsdl]

  • Generated by XFire ( http://xfire.codehaus.org )
Pretty neat, huh? Click on the Web Service Definition Language (WSDL) link and you'll see all the wsdl that was generated auto-magically from our very simple SOAP server.

Next time we'll write a quick SOAP client and test this server out. Until then, buy the book and read the Groovy.

07 February 2008

BeanShell 01

I first ran across BeanShell (bsh) in early 2006 while looking for a way to better automate an Ant build. For the first few months, it was pure love. I couldn't get enough and I drove everyone at work nuts with my constant white board examples and endless emails. JSR 274 "The BeanShell Scripting Language" had recently been passed and I was sure that everyone would soon be loving Beany. Wikipedia says "BeanShell is an open source project and has been incorporated into many applications, such as OpenOffice.org, Apache Ant, BEA WebLogic Application Server, jEdit, and many others". Unfortunately, I haven't seen anything new written about bsh. The developer of BeanShell, Pat Niemeyer, hasn't updated the website not made a new release forever. I've sent Pat a few emails to ask about status but haven't received a reply. I guess the project is dead which is too bad because they're some really cool things that you can do with bsh.

So... what cool things can be done you ask? Patience grasshopper. Let's first get it installed. It'd be great if you'd review the "Getting Started" section of the bsh manual, but in a nutshell:

Grab the latest bsh jar which is currently 2.0b4. Either drop the BeanShell JAR file into your Java extensions folder or add it to your classpath:

Install as an extension. Place the bsh.jar file in your
    $JAVA_HOME/jre/lib/ext folder
Or add BeanShell to your classpath like this:
   nix: export CLASSPATH=$CLASSPATH:bsh-xx.jar
   windows: set classpath %classpath%;bsh-xx.jar

You can then run BeanShell in either a GUI or command line mode:
    java bsh.Console // run the GUI
or
    java bsh.Interpreter // run as text-only on the command line
or
    java bsh.Interpreter filename [ args ] // run a script file

It's also possible to call bsh from within native Java applications, to reach it in a remote server mode for debugging (very cool), to use it as a servlet, or even in an applet.

Let's check that it's installed and do some basic stuff. From a cmd line, type java bsh.Console and you should see the GUI start up and then have a workspace like the picture to the right. If not, check your classpath and try again.

I'm a hacker at heart so one of the first things that I did was to fire up the class browser (in the workshop, type classBrowser(); ) and started explorer classes in my classpath. This simple tool has helped me understand APIs and undocumented methods for many classes. Just select a package and then class and the browser will reveal the constructor(s), method(s), and field(s). Plus you can see the file system path of the class which has helped me several times when I had classes loaded multiple times.



There's much more to talk about but this entry is getting long. Next time, I'll discuss more Console commands and some bsh examples. In the mean time, download bsh and read thru the manual. I think you'll agree - BeanShell has so much potential.

02 February 2008

Quotes 01

Robert Heinlein wrote "A human being should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, fight efficiently, die gallantly. Specialization is for insects."

Now that's a great quote! When I first read those words in high school, I had to scribble them down in my notebook. I wanted to live those words. 25 years later, I still can't conn a ship, design a building, write a sonnet, and probably would fail at the invasion planning but I think I'm doing alright on the others. As a married man, I'm near expert on changing diapers, taking orders, fighting, and pitching manure!

30 January 2008

Stay Sharp - Free College Courses

I'm really floored when I hear about the lack of reading and self-help effort that the average engineer does after graduating. I recently saw a survey that showed most engineers read one technical book per year. Wow. That's incredible - how can an engineer survive? I know, some (most?) will say that they get their info on the web and who has time to read a book? But didn't you become an engineer because you have that drive to learn, to make things better? What happened?

I'll never forget a meeting about 12 years ago with department heads and the VP of Engineering. The topic was upgrading the office PCs from Windows 3.11 to this thing called Windows 95. We had the budget to upgrade but no funds for user training. I was an unknown geek at the time and spoke up "Why don't we buy a few books and let the users learn on their own? Windows 95 isn't very difficult". The VP glared at me and said "These people are adults, we can't expect them to learn on their own". Floored. I was absolutely floored by his comment. I kept my mouth shut and the company stayed with Windows 3.11 for another two years. That experience though has stuck with me. Too many adults think they need a training class for everything. Very
few are willing to try a new application on their own. Is it fear of failure?

This fear also stops many from bettering themselves by taking random college classes at local schools. I love to look thru the current catalog and see if I can fit in a class. Last year I took a robotics class and an advanced design patterns class. My job will pay for tuition if the class is even remotely related to my job. And if a passing grade is obtained. I know a few engineers that won't take a class because if they don't pass, then they're out of the bucks. What an attitude. Take the class, participate, learn, and it's darn near impossible to not pass.

I'm trying to encourage people at work to take a few of the free web classes that many great schools are sharing. I know a few guys (including me) that have recently taken the excellent Java Passion on-line courses. I've been saving off the links to these web classes in my del.icio.us education tag but now that I've stumbled across Online Education Database's wrap-up post Skip the Tuition: 100 Free Podcasts from the Best Colleges in the World and 200 Free Online Classes to Learn Anything, I think I have enough to keep me busy.

For the past year or so, I've trying to watch/listen to at least two class sessions a week of the various free web courses. This isn't hard to do. I rarely watch or listen to one straight thru. Usually start one late at night and then finish it in bits and pieces over the next day or so. The key is just do it and make it fit into what time I have available. Right now, I'm doing a few from MIT's Aircraft System Engineering course which was put together by shuttle astronaut and MIT Professor Jeff Hoffman and Professor Aaron Cohen, who was the Space Shuttle Orbiter Project Manager.

Many people have said to
me "I'm too busy, how can you find the time to do those?" I always want to reply "How can you afford not to?"

If you enjoyed this post please use the links below to add it to StumbleUpon, Delicious, or Digg
stumble upon | delicious | digg

29 January 2008

Kits

I'm looking for something to help get my youngest interested in making/engineering. He's a young geek, reads lots of books, watches MythBusters, SmashLabs and such. I want to find a something to pique his interest in building stuff.

In this month's Robot magazine, he saw a two-page ad for Tamiya robocraft kits. He's really been pushing for me to spring for the racehorse. It looks kinda cheap and I hate to waste the money. It's only $14 so I guess it won't drive me all the way to the poor house but I hate buying crap. I can finds lots of places selling these kits but haven't seen a review.

When he's a few years older, I hope he's interested in building stuff like the nerdkit. When I was a kid, my dad occasionally would build things from HeathKit. He made a heath kit oscilloscope around 1973 that was still working great at least 20 years later. I loved watching him make circuit boards, fix broken motors, etc.

For myself, I bought a gumstix kit with the dream that I'll build an Unmanned Ground Vehicle (UGV) that will roam my backyard. So far I've managed to spend lots of money, destroy my son's Hummer R/C, and make a very large pile of crap on the garage bench. And I've enjoyed every minute of it.

28 January 2008

ESB 01

Enterprise Service Bus (ESB). Nice name. Every time I see something with "enterprise" in the title, I get the "ooh"s. Or is it the "aah"s? I simply can't walk past a book titled "Enterprise blah blah" without stopping to thumb thru it. It's only $59.99 and it's shiny. Should I impulse buy it now or add it to the Amazon cart for later?

ESBs. I've messed with a few of them, probably used Apache's ServiceMix the most. Using servicemix, I had a Groovy SOAP server working with a JMS app in about 10 minutes. Maybe it was 15. I tend to exaggerate. Whatever time, it was short and servicemix was easy. Speaking of MQ, have you read Linda's Open Message Queue Blog? It looks pretty good but she hasn't updated since October 2007.

Some guys at work are using BEA's Aqua Logic. I've not had the chance to use it but they seem to like it, especially the message transformations. I've got a demo disc sitting on my desk and anyone can download a demo. I should test drive this soon. Last summer I used both JBoss and WebLogic JEE servers and I found that WebLogic was much more stable. I think the price is a little steep for mortals but the product was better.

There's also Mule which I've never tried. I've stumbled across an interesting article "Exploring ESB Patterns with Mule". Yet another thing to work thru and try out when I have a spare hour or ten.

Bluetooth Dongle Crap

Yesterday I mentioned that my new Bluetooth adapter was packaged in an odd case. Although I found the "deal" on bargain jack, the crap came from meritline. Other than selling the device, meritline did nothing wrong, the transaction was smooth,they did fast shipping and I'll definitely buy more crap from them in the future.

The actual bluetooth device isn't much bigger than a quarter but was in a case pretending to be much more.

Okay. I'm being tough on them by calling a a device crap that actually works. It does appear to work just fine with my cell phone and other bluetooth devices, I just had a problem using any stack other than Toshiba's to pair with a wiimote. That plastic stick masquerading as an antenna just gets me. Why would they do that? To get suckers like me to buy their crap.

The bluetooth chip is Cambridge Silicon Radio (CSR) but I can't quite make out the markings. As you can tell, my camera is not the best at taking close-ups. It appears to read BC212 015BD A21AA. I'm guessing that it's one of CSR's BlueCore3 ROMs. A quick Google leads to quite a few hits - I'll need to look into this in more detail.

Also talked yesterday about the BlueTunes app that lets me use a wiimote as a remote control for Media Player. Even though the crap adapter pairs with my cellphone all the way across the house, I've found that unless the wiimote stays about 10 feet from the adapter, BlueTunes reports a problem and puts up an error dialog every few seconds. When I noticed the problem, I had over 100 dialogs that I had to click OK. Cool app, dumb bug.

wiimote 01

Finally some success. Ever since a friend showed me Johnny Chung Lee's wiimote projects, I've been wanting to try 'em out for myself. It's taken me a few weeks but I finally had something working this weekend.

The coolest wiimote app that I've tried so far is bluetunes. My laptop can be across the room and I can sit on the couch and wave the wiimote around to change tracks, up/down the volume, and play/pause. Yeah, nothing amazing but I'm lazy when it comes to music and remotes.

Now I'm messing with Johnny Lee's whiteboard app but I lack a good IR source. I'm using my tv remote and it kinda works but not very reliable. Tomorrow, I'm going to break open an old remote to make an IR pen.

I think I told you the story about my lost bluetooth adapter. A while back I bought an adapter to use with my gumstix. I've looked everywhere for that thing but it's now been declared MIA. So this past week, I bought another adapter thru a deal for $8.99 that I found at bargainjack.com. Remember kids - you get what you pay for. See that really cool antenna? Fake. It's just a plastic stick. See the thumb drive sized case? Empty. The whole actual bluetooth card is about the size of the USB plug. It's like a bag of potato chips. All air and a tiny board. No idea why they did that. The adapter works pretty well and pairs with my cell phone on the other side of the house so it has range. Just weird crap.

The new adapter came with BlueSoleil drivers which seem to work ok with my cell phone and my GPS but just wouldn't work with the wiimote. It would discover the device as "Nintendo RVL-CNT-01" but then wouldn't start the Human Interface Device (HID) service. During the 23 odd times of installing/uninstalling/reinstalling, I saw that I also had a Toshiba bluetooth stack installed but I couldn't get it working with the wiimote either so it was dumped.

I then tried the widcomm drivers but they didn't work at all with my adapter. No fault of the drivers, they've worked for me before. I was losing patience and probably didn't spend enough time with them.

I've finally reinstalled the Toshiba bluetooth and it works great. Unfortunately, it says it's a 30 day trial but has no option to buy.

The final secret for it to work for me seems to be pressing and holding down the the wiimote keys during both the discovery and pairing process. When the software asks you to type in a pairing key, type nothing and just hit return.