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
(badness 10000)
A blog about technology and software
Wednesday, March 5, 2014
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)
2014-02-04 10:12:25.320:WARN:oejut.
java.lang.
at org.eclipse.jetty.annotations.
at org.eclipse.jetty.annotations.
at org.eclipse.jetty.annotations.
at org.eclipse.jetty.annotations.
at org.eclipse.jetty.annotations.
at org.eclipse.jetty.annotations.
at org.eclipse.jetty.util.thread.
at org.eclipse.jetty.util.thread.
at java.lang.Thread.run(Thread.
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:
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.
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
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.
Saturday, June 29, 2013
Govhack Brisbane 2013
A month ago I attended the Govhack (http://www.govhack.org/) 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 http://hackerspace.govhack.org/?q=groups/travelhackz
Big thanks to the rest of the team for their efforts on this!
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 http://hackerspace.govhack.org/?q=groups/travelhackz
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 - http://www.yowconference.com.au/lambdajam/. 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 (http://www.playframework.com/documentation/2.0/Iteratees). This was presented by Nilanjan Raychaudhuri and looks very interesting, I plan on having a look at this sometime soon.
One thing that I do plan on looking up is the iteratee pattern in the play framework (http://www.playframework.com/documentation/2.0/Iteratees). 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 (http://hackandheckle.com/). 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.
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:
https://github.com/nebnagrom/jaxbInheritance
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:
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:
@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:
Stack trace of error you get with the House based version over the fold:
https://github.com/nebnagrom/jaxbInheritance
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
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:
- Using no generics meant that I got House member variables only, even when I annotated BlueHouse with annotation and added BlueHouses to the collection
- Using the parent class as the Generic gave me Marshalling exceptions, probably to be expected though.
Stack trace of error you get with the House based version over the fold:
Labels:
generics,
inheritance,
Java,
JAXB,
Jersey,
programming,
REST
Subscribe to:
Posts (Atom)