Tuesday, May 14, 2013

Using Restlet to build a Java API

I'm working on building a Restful Web Services API for a Java Application that I'm active on. My initial direction for getting started was to look into JAX-RS (Java's API for building restful web services), and then noticing that JAX-RS 1.0 has been out for quite some time, and then noticing that JAX-RS 2.0 was getting approved right before my eyes. Assuming that JAX-RS2 is the successor to JAX-RS1, one might as well stay on the latest edge. JAX-RS 2.0 is now approved by the Java Community Process, so, assuming there are implementations worth using, you can get going now!

Well, I'm stumbling through this "decision matrix" of which implementation to choose, and Stack Overflow only gets you so far. So, for now, I'm doing a technology "Spike", and am working through researching RESTlet to be my horse to build an API upon.


I've recently picked up some Rails development, and I'll note that documentation and getting started started guides are rampant throughout that ecosystem. So, Rails is a nice platform that provides as little friction as possible to someone getting started.

Getting Started with Restlet

I found some Maven settings to add to a new project pom.xml, which allowed me to get started quickly. (Note: I had used this originally, while the Restlet version was pegged at 2.0.0)
Add to your pom.xml to add Restlet 2.1.2 to your maven project.

I then started reading the book "Restlet in Action", and hit a stumbling block with the following code:

public class AccountServerResource extends ServerResource implements AccountResource {
    private int accountId;

    protected void doInit() {
        this.accountId = Integer.parseInt(getRequestAttributes().getAttribute("accountId"));

This .getAttribute("accountId") does not exist in Restlet 2.0.0, so I did a bit of panic, and tried to re-write the code to something analogous I guess, like: 

    protected void doInit() {
        this.accountId = Integer.parseInt(getRequestAttributes().get("accountId").toString());

Not as pretty, but if it works.. But then I'm stuck with not being able to follow along with the book. And I'm assuming that the book was reviewed. So, I take a different approach, maybe I'm using the wrong version of Restlet? I jumped to the Restlet maven repo, and found that the latest stable version, and the version that matches the book is 2.1. So, I changed my pom to use version 2.1.2, previously I was using Restlet 2.0.0.

Thus far, Restlet is so-far-so-good. But, its a lot of learning, when I really just want to get to "done" faster. I'm not sure what getting-started route I would recommend for another developer that I would on-board to this project. i.e. I layed this groundwork, build on top of that, and read some getting started guides, as opposed to starting from scratch with the book.

The application that I'm actively working on is DSpace, the institutional repository, asset management system.

Wednesday, March 20, 2013

I've managed to run out of memory with 16GB!

I've been upgraded to a MacBook Pro with 16GB of memory, not 4GB, not 8GB, but 16GB.

And.. Thats somehow not enough, since I've been able to (through normal work) run out of memory. I don't blame Java. (Kidding...)

[INFO] ------------------------------------------------------------------------
[INFO] Java heap space
[INFO] ------------------------------------------------------------------------
[INFO] Trace
java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOf(Arrays.java:2882)

Maven skip license check

I recently ran mvn install on a big Java project that I work on, but it kept failing due to some files not having the proper license headers. Well, thats not my concern right now, how do I skip that?

To skip the maven license check, add:


So, my full command (which also skips running the unit tests) is:
mvn clean install -DskipTests=true -Dlicense.skip=true

I suppose you should add yourself a future task of eventually making all of your files have the proper license headers, but you can continue on what you meant to do for now.