Skip to content


Automatic model validation using Jersey, Jackson, and Hibernate Validator

So you have a RESTful Java webapp built using Jersey, some POJO/JAXB models that you’d like to serialize using Jackson, and think it’d be sweet to validate models using annotations (JSR 303 – Bean Validation)? And you like your objects to be immutable (Effective Java Item #15). You’ve come to the right place. Hibernate Validator is the reference implementation for JSR 303 and arguably the best currently available, so we’ll use it along with Jersey and Jackson to form the backbone of this recipe.

The general idea behind the ValidatingJacksonJsonProvider is that we can annotate any of the parameters used in our resource classes with @Valid to have the object automatically validated during the Jackson JSON serialization process.

So, first, annotate your POJO/JAXB object with some constraints, like @Min(0) and @NotEmpty. Continued…

Posted in Tutorials.


Mocking static java.util.Logger with EasyMock’s PowerMock extension

We have a class that needs to limit the number of logged messages to avoid DDOSes. But this particular piece of software is still using JULI (yes, I know, not my decision though). Since JULI doesn’t support NDC or MDC, we needed to get creative to test this logging limit.

You probably create a static logger for your class, something like

public class LoggingClass {
    private static Logger logger = Logger.getLogger(LoggingClass.class.getName());
    ...
}

or the equivalent with SLF4J’s LoggerFactory.

PowerMock can help you mock this logger. Yes, its that powerful. First, Continued…

Posted in Tutorials.


Book Review: Forging Truth

After a number of years away, my love of reading (non-textbooks) has returned. In the last two months, I’ve finished 6 or 7 books. Last one was probably five years before. Ok, maybe an exaggeration, but you get the picture.

One of the books that got me back into fiction was Forging Truth, by Raymond Masters. (disclaimers below)

Although I expected Forging Truth to be a typical fantasy/sci-fi piece, it ended up being a big mystery as well. It was this aspect that hooked me from the end of Chapter 2. The protagonist (and the reader) go through a journey of discovery, trying to recover his lost memories that are key to solving a crime against humanity. The book twisted and turned til the end, feeding you just enough information and back-story to keep you intrigued but not so much that the next pages were obvious.

Situated in present-day America, the novel was centered around subjects normally reserved for other (usually more medieval) contexts. This juxtaposition made for a very interesting read. Given this modern context, the language was easy and the approach to magic was “light” (i.e., unrestricted, not manna-based, etc.). However, the actual content/subject matter was a bit darker in nature, with some moderately graphic scenes. Action-packed til the end, this book left me hanging for more. Can’t wait to read the second book!

disclaimers: the links above are Amazon-affiliate links and the author is my uncle. :)

Posted in Commentary.


Early Animation – The Zoescope

Today, Google highlighted Muybridge’s The Horse in Motion for his 182nd birthday. This early motion picture was created using a device Muybridge created called a zoopraxiscope that paved the way for modern cinematography. I’d like to follow it with another cool early animation device called the zoetrope that I learned about in my recent trip to California. The following clip uses the characters familiar from Toy Story, one of Pixar’s earliest hit animations.

The audio narration (in the voice of Woody) explains how the Zoetrope works, using a quickly-flashing strobe light and a rotating display. Pretty sweet, I think.

Posted in Commentary.


Sharebox – A Dropbox-like Sharing App using Ruby on Rails

A week ago, I posted a quick fix to a bug in the Sharebox tutorial. The next day, it appears that the site hosting this tutorial expired, and its content could be lost. Never fear! Google’s cached version is here. To make it easier for you, I’ve posted the source code developed through the tutorial to my Github and you can see Sharebox in action on heroku. Lastly, I’m also hosting a cached copy of the tutorial for safekeeping, in the event its lost overwritten in Google’s cache.

Hope this helps!

Posted in Tutorials.


Fixing the “unknown attribute: uploaded_file” error in the ShareBox Tutorial

While going through the (quite good) ShareBox Tutorial that teaches you to build a Dropbox-like sharing app, I stumbled on a nasty bug. The tutorial wisely uses the paperclip gem for file attachments, but after moving from local hosting to Amazon’s S3, I started getting an exception in the AssetsController create action.

  ActiveRecord::UnknownAttributeError in AssetsController#create
  unknown attribute: uploaded_file
  app/controllers/assets_controller:17:in `create'

At the time, Googling the error didn’t help (gasp!), so here are all the pieces together to help any wary travelers who may stumble here looking for the same answer. Continued…

Posted in Tutorials.


PyYAML using easy_install on Mac OS X (Lion)

Tried to install pyyaml today but got a couple nasty errors.

$ sudo easy_install  pyyaml
Searching for pyyaml
Reading http://pypi.python.org/simple/pyyaml/
Reading http://pyyaml.org/wiki/PyYAML
Best match: PyYAML 3.10
Downloading http://pyyaml.org/download/pyyaml/PyYAML-3.10.zip
Processing PyYAML-3.10.zip
Running PyYAML-3.10/setup.py -q bdist_egg --dist-dir /tmp/easy_install-8Co0C6/PyYAML-3.10/egg-dist-tmp-FYdiLy
build/temp.macosx-10.7-intel-2.7/check_libyaml.c:2:18: error: yaml.h: No such file or directory
build/temp.macosx-10.7-intel-2.7/check_libyaml.c: In function ‘main’:
build/temp.macosx-10.7-intel-2.7/check_libyaml.c:5: error: ‘yaml_parser_t’ undeclared (first use in this function)
...
lipo: can't open input file: /var/tmp//ccxDQipT.out (No such file or directory)

and

libyaml is not found or a compiler error: forcing --without-libyaml
(if libyaml is installed correctly, you may need to
 specify the option --include-dirs or uncomment and
 modify the parameter include_dirs in setup.cfg)

Fortunately, after piecing together a couple posts, the fix is easy. Use the following command to install PyYAML.

sudo python -m easy_install pyyaml

We must install this way because the problem is a bug in an Python’s setuptools. Its been fixed in later versions, but for now this did the trick for me.

Resources

  • http://pyyaml.org/ticket/186
  • http://pyyaml.org/ticket/94
  • http://andreasjacobsen.com/2008/10/10/using-python-setuptools-on-the-mac/

Posted in Tutorials.


Eclipse Start-Up Crash on Mac OS X Lion

Today, I was working from my parent’s home in Arkansas where we don’t have broadband, so my Mac was offline. I tried to start Eclipse and it just popped a dialog mentioning a log file with no other message.

After a bit of searching the errors in the log, Stack Overflow came to the rescue.

just add an alias for localhost to the network interface:

sudo ifconfig en0 alias 127.0.0.1

That’s all you have to do, really.

Posted in Tutorials.


Lost Your Kindle? Email A Last-Ditch Note to the Finder/Thief.

About a week ago, I lost my Kindle. This makes me sad. After tracking it on security cameras until it left the film of vision (left in cart at grocery store), I’ve devised a last ditch effort. Remember that convenience method of emailing documents to your kindle? Well, I’ve just created a PDF pleading for its return, including my contact info. Will it work? Maybe not, but it can’t hurt either. You can do this yourself.

  1. Write a “please return my Kindle” note in MS Word. I used size 20 font, all caps, and short sentences. Continued…

Posted in Tutorials.


Simple REST API Testing Setup using Vows.js, Tobi, and Node.js

I’m learning so many new things at BrightTag! Among them, I’m helping develop a new service in node.js. After piecing together a few articles online about using node for asynchronous testing of REST services, I thought I’d share the testing setup I’d settled on, in case it can help you. The setup is written for vowsjs and can easily be tailored to your situation. I’ve tried to make heavy use of asynchronization, macros, and contextualized requests. In the case below, I was integration-testing an oauth security middleware (simplified here for, well, simplicity). Continued…

Posted in Tutorials.




Log in here!