Wednesday, March 5, 2014

RESTful web services with JAX RS 2

Recently I had the chance to present to the Brisbane JVM group on JAX RS 2 which was released last year. I gave a brief overview of the basics of JAX RS followed by a run through of some of the new features in JAX RS 2 - client api, filters and interceptors and ayschronous resources.

Thanks to Rob the video is now up at vimeo -, the slides are available on slide share - and the code is on github -

Tuesday, February 4, 2014

Jersey and Maven Jetty plugin

Recently I ran into an issue working with Jersey and the Jetty Maven plugin. The application is built for Glassfish so I had marked the Jersey libraries as provided. In the Maven Jetty plugin configuration I put Jersey in the configuration for the dependency but when I went to start the server I got the following error:

2014-02-04 10:12:25.320:WARN:oejut.
java.lang.IncompatibleClassChangeError: org/eclipse/jetty/annotations/AnnotationParser$MyClassVisitor
    at org.eclipse.jetty.annotations.AnnotationParser.scanClass(
    at org.eclipse.jetty.annotations.AnnotationParser.parseJarEntry(
    at org.eclipse.jetty.annotations.AnnotationParser.parseJar(
    at org.eclipse.jetty.annotations.AnnotationParser.parse(
    at org.eclipse.jetty.annotations.AnnotationConfiguration$
    at org.eclipse.jetty.annotations.AnnotationConfiguration$
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(
    at org.eclipse.jetty.util.thread.QueuedThreadPool$
After a bit of digging around I found that changing the Jersey dependencies to compile resolved this issue. I figure I must be doing something bad to the Jetty class loader where by loading in the container's classloader is breaking something.

In the end I settled for setting the dependency scope to 'test' and adding the test classpath on the Jetty classpath. This is not ideal as it doesn't really express the dependencies properly of the application.

Hopefully this helps someone else who runs into this issue!

Thursday, January 9, 2014

Functional Programming Principles in Scala and Principles of Reactive Programming on Coursera

At the end of 2014 I completed two Coursera courses on Scala and functional programming. I have been slowly trying to learn Scala and these courses were a great help for me to learn the language. This post is about my experience with the course and thoughts on it.

The first course I did was Functional Programming Principles in Scala - which goes through the basics of functional programming in Scala. I found this course to be quite fun and the assignments were good. There was one week, I think week six where I felt the assignment was hard and took more time than the others.

The topics that I found particularly interesting were:
  • immutable collections
  • pattern matching
  • for comprehensions and fold, map and filter
  • lazy evaluation and infinite streams
The second course was Principles of Reactive Programming - which goes through reactive programming in Scala. The format was the same as the first course but had three different lecturers. This course felt more like a run through of several different frameworks which was good but not quite what I expected.

I found the lectures in week three and four to be interesting and they covered futures and stream processing with the Reactive Extensions for Java ( which is a port of the .Net RX framework. The RX framework is definitely worth investigating and offers some very nice ways of handling Futures and asynchronous code. I was also lucky enough to see the talk on RX at the 2013 Yow conference by Ben Christensen and this course really helped me understand how it is being used at Netflix.

Weeks five, six and seven were focused on the Akka framework which uses the Actor model. I found the first assignment for Akka to be quite challenging, mainly around having to learn a bunch of ancillary stuff for the framework which was not related to the assignment. This was good however as it gave me a feel for what Akka would be like to configure and setup, although I'm not sure that I am smart enough to right concurrent code that is correct!

Overall I thought the courses were very good and I enjoyed them for the most part. This session was the first time the Principles of Reactive Programming has been run and I think that it showed a little as the assignments were not as polished as the first course. It is a real privilege to be able to enroll in these courses for free and many thanks must go to the organisers for putting this on.

Saturday, June 29, 2013

Govhack Brisbane 2013

A month ago I attended the Govhack ( event which was run around Australia to see what could be done with Government data in a weekend.

This was quite a bit of fun although I only had a day available to work on it the team had a cool idea for planning a trip using the Australia tourism data. We called it travelhackz and the summary is available at

Big thanks to the rest of the team for their efforts on this!

Lamdba Jam 2013 (Brisbane)

A month ago I went to the YOW Lambda Jam conference in brisbane - This was quite a bit of fun and had plenty of interesting talks.

One thing that I do plan on looking up is the iteratee pattern in the play framework ( This was presented by Nilanjan Raychaudhuri and looks very interesting, I plan on having a look at this sometime soon.

Hack and Heckle

Recently I joined Darren and Leigh in their Hack and Heckle podcast ( We talk about technology and the news that we've seen in the week as well as the local meetups and whatever side projects we happen to be working on.

This has been quite a bit of fun so tune in if you are interested.

Wednesday, June 5, 2013

Jersey, JAXB and json with generics and inheritance

A month or two ago I ran into an issue where I was marshalling Objects to json using Jersey with JAXB annotations on my pojos but only the Super Class attributes were being marshalled. I have uploaded some code to github to demonstrate this:

In this contrived example we have a Super Class House which has a member variable which is a String and an @XmlRootElement annotation. There are three child Classes of House:
  • BlueHouse which has an additional Integer
  • RedHouse which has an additional String
  • GreenHouse which has an additional Boolean
We then also have a HousingEstate<T extends House> which wraps a typed collection of houses. In this example it has no behavior but in the situation I had we had behavior on this collection as well.

The issue occured once I started trying to return HousingEstate objects from my RESTful resource. When you invoked the resource you only got back member variables from the House class, i.e. something like this:

 {"houses":[{"houseName":"first blue"},{"houseName":"2 blue"}]}

 When what I wanted was more like:

{"houses":[{"houseName":"first blue", "blueAttribute":1},
           {"houseName":"2 blue", "blueAttribute":2}]}
After a bit of digging I found that I needed to add another annotation on the House class - @XMLSeeAlso like this:

@XmlSeeAlso({ GreenHouse.class })

After I added that I started getting the results I wanted.

I also tried this without generics or just using the Super Class but this did not work either. Interestingly I found that:
  1. Using no generics meant that I got House member variables only, even when I annotated BlueHouse with annotation and added BlueHouses to the collection
  2. Using the parent class as the Generic gave me Marshalling exceptions, probably to be expected though.
I haven't really tried to dig into what is going on here, I assume that there is something with generics and type erasure that makes it impossible for JAXB / Jackson to know that there is a child class that it should be looking at for the marshalling.

Stack trace of error you get with the House based version over the fold: