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 - http://vimeo.com/88095270, the slides are available on slide share - http://www.slideshare.net/benjaminedwinmorgan/jax-rstalk and the code is on github - https://github.com/nebnagrom/qldjvmJaxRs2

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.
QueuedThreadPool:qtp1736120767-24:
java.lang.IncompatibleClassChangeError: org/eclipse/jetty/annotations/AnnotationParser$MyClassVisitor
    at org.eclipse.jetty.annotations.AnnotationParser.scanClass(AnnotationParser.java:971)
    at org.eclipse.jetty.annotations.AnnotationParser.parseJarEntry(AnnotationParser.java:953)
    at org.eclipse.jetty.annotations.AnnotationParser.parseJar(AnnotationParser.java:906)
    at org.eclipse.jetty.annotations.AnnotationParser.parse(AnnotationParser.java:828)
    at org.eclipse.jetty.annotations.AnnotationConfiguration$ParserTask.call(AnnotationConfiguration.java:111)
    at org.eclipse.jetty.annotations.AnnotationConfiguration$1.run(AnnotationConfiguration.java:472)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:607)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:536)
    at java.lang.Thread.run(Thread.java:744)
 
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 - https://www.coursera.org/course/progfun 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 - https://www.coursera.org/course/reactive 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 (https://github.com/Netflix/RxJava) 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.