Sunday, April 24, 2011

REST and Bugs

Sometimes the need to code out ideas just infects the mind or becomes an obsession enough that you have to get it out. Maybe that's the normal mode of operation when you are actually interested in the work.

Lately I've been working with Jersey, the JAX-RS (JSR 311) REST library.
I've worked with servlets, I've worked with JAX-WS annotations, and this seems to merge the two nicely.
My initial reaction was that it was super easy to create simple GET methods and return XML or JSON using JAXB annotated classes.

My second reaction was that I couldn't organize the services the way I wanted. For example, Jersey doesn't allow the resources to share the same path. This is exactly what I wanted. First to be able to put it only on the interface and share it in both the real and test resources. Then to be able to use a path annotation for the package and have path annotations only on the resource methods to differentiate them. And I'm guessing this would be possible if the path namespace was by method (or package/class/method) and not by class.
But although it works, path annotating interfaces is annoying because of the ugly logged warning messages.

My third reaction was that inputting data wasn't as simple as returning data. While the GET return handled the conversion to JSON/XML well, it proved more difficult for the incoming parameters. I was attempting to pass in both simple string parameters and complex JSON or XML data together with the later being automatically converted to the JAXB entities like the method return values. I eventually found that I could accomplish what I wanted using a POST with query params, where the body contained the structured data and the Consumes annotation (like the Produces) determined how to interpret it.

In other news, I've tried out the PMD (again) and FindBugs maven plugins, both helping to point out and prevent bugs in code.
In testing I saw results pointing out string concatenation in a loop, not closing resources for certain conditions, bad null check logic, unused fields and imports, empty catch blocks.
Finding faulty null logic with findbugs has been very useful to point out where these assumptions are different in code (passing null in one location and assuming it is not null in another).
My only complaint with findbugs is not being able to generate the html report outside the site goal like the pmd plugin.

I'm not sure if it exists, but what would be useful is a tool to point out classic test lines in code. I mean where two adjacent lines of code both define a value for the same field, but one is commented out and the other is not. This is especially true where one of the lines defines a hardcoded value.
But I guess the answer is to have a proper unit test that says "hey, you left this crap line here". And to use version control and review your commits thoroughly.

Tuesday, April 19, 2011

Last PA DnD Podcast

I didn't realize that I was mostly through the last episode of series 4 in the Penny Arcade DnD podcasts, but I finished it and the bonus on the way into work this morning.

Now I am sad to say that I have run out of these podcasts (until more are made). These were fun to listen to and I flew through them. I eagerly await more to devour.

TV Sidenote

Enjoyed the s02e14 episode of Community with its DnD game, especially the evil Pierce. It was a much more free form game than I expected, but fun.

In a related note, haven't finished the latest DnD podcasts yet, but still watching lots of PATV, going through the latest season.

Still enjoying White Collar, now on season 2. But one thing I despise are the green screen clips for Elizabeth. They should have setup the plot to have her away, maybe only on phone calls, but instead there are these aweful looking and obviously staged clips. ugh.

After finally watching an episode of Supernatural after a long break, watching other shows, I really had missed it.

Saw some of the Social network the other day and remembered how much I like the soundtrack (of course since I'm a NIN fan), that I have it, and now I am listening to it again.

Monday, April 11, 2011

VirtualBox

I spent most of the weekend trying to setup a new dev environment.
This machine is already filled up enough and I'd rather not clutter it up more.
So the answer of course is... virtual machine!

But it wasn't a simple or short process.
I had VirtualBox installed previously, Innotek version.
And I found a ready Fedora image, since I've usually worked with Linux under RedHat/Fedora/CentOS.
But I decided to upgrade to a newer VirtualBox version.
I tried the latest Oracle 4.0.4 version but it failed to start.
So then I tried a Sun 1.6.6 version, this installed and started fine.
It did warn about upgrading my previous Innotek settings, apparently the reason the Oracle version failed to start. Only a warning, it then updated the settings and continued on.
But after several attempts at trying to add the guest additions, I found I couldn't use this version.
So I removed the old settings and went back to the Oracle version.
Success. I was also able to add the guest additions (despite the mixed/lack of great documentation).
I found this newer version (unlike the two Sun/Innotek previous) already had mouse integration, so I mainly needed the additions for the video support (larger view).
To add the additions I roughly did the following: yum update, yum install dkms gcc kernel-headers kernel-devel, reboot, mount additions iso, run linux additions.
The kernel-headers and kernel-devel will be for the latest kernel version, hence the reason for the update (especially the kernel to match).
Having the original OS image came in very handy, being easy to start the process over and over and over.

Now I continued on to install the minimal pieces I needed: Java, Maven, SVN.
For Java it was the Sun rpm download and install, for Maven it was just the download and env vars (java_home, m2_home, path in .bashrc), for SVN it was the package installer.
All different paths but all the same end, I could run from the command line.
But for another reason I wanted to use the Java plugin in Firefox, but luckily I was able to find reference to link the Sun libnpjp2.so in jre lib to libjavaplugin.so in mozilla plugins.
In the end the original VM image grew by almost 2G with all these updates and installs.

Friday, April 8, 2011

Words, DND, Dead

I've gotten addicted to Words With Friends recently on iPod
I had a run with some good points, including wandS + joustS (52) - could have played gnawS (73), loving (30), Oracle + gO (48)
Those were in the same game, giving a 150+ lead. Also played hand (42) in another game.
I played best when I planned my next moves right after playing a word, so I had options and their points.

Finished Series 3 of the PA DND podcasts with the fall of Aeofel.
Just started Series 4, switching out Chris Perkins for Jerry as DM and adding Kris Straub. Definitely a different feeling, but a nice change. I do hope to see/hear more DND adventures with the previous characters and Chris.
I've also been catching up on older PATV, including the DND episode.

On the topic of DND, although I'm interested in it, I've never played.
I've mostly grown up playing video games:
Atari with Star Wars, Combat, Dig Dug, Off the Wall, Jungle Hunt, Frogger
Gameboy with Tetris, Super Mario, Metroid,...
Any arcade games like Centipede, Pac Man, Mortal Kombat, Street Fighter, Tekken, especially liked Spy Hunter,...
PC with Wolfenstein, Doom, Diablo, lots of free games on CDs including Descent,...
A friend's Nintendo with Super Mario, Double Dragon,...
A friend's Sega with Sonic
Tons of Super Nintendo with Donkey Kong Country, Ninja Turtles, Super Mario, Shaq Fu, Smart Ball, Super Ghouls & Goblins, F-Zero, Super Punchout,...
Other friend's consoles including Playstation like Tony Hawk and Guitar Hero,...
Wii with Sports and Super Smash Bros
More PC like GTA, Max Payne, Battlefield 2, Combat Arms, Half Life, Counter Strike, Left 4 Dead, Minecraft, Portal,.....
Ok, I'll stop, there are just too many to attempt to list and no way I will remember them all
But the point is, I've been a video game guy
And yes, I've played card and board games but definitely not as much, so DND is completely new for me

Read through the latest Walking Dead comic #83 and wow, it finally hit the fan in a big way. It came out a week early but I didn't get to finding out or reading it till this week.