Wednesday, July 8, 2009

JSR 311 plugin for Grails

Project homepage: grails-jaxrs

Recently, I wanted to make a full two-weeks mountain bike tour through the Alps but bad weather on a few days caused me to make detours on the less rocky roads of JSR 311 (JAX-RS: The Java API for RESTful Web Services). I took the chance reading the spec, did some hacking with Jersey and I must really say I like to work with it. I liked it so much that I started to use it inside Grails to combine it with features such as GORM and XML and JSON marshalling.

From my experiments I factored out what I think is reusable into a Grails plugin named grails-jaxrs and made it open source. The plugin takes care of initializing Jersey inside a Grails application, implements a controller that does the dispatch to Jersey and provides some Grails-specific entity provider implementations.

Here's a very simple example of a resource class that represents a collection of notes and that makes use of Grails object relational mapping (GORM) and XML marshaling:

import grails.converters.*

import javax.ws.rs.Consumes
import javax.ws.rs.GET
import javax.ws.rs.Path
import javax.ws.rs.PathParam
import javax.ws.rs.POST
import javax.ws.rs.Produces
import javax.ws.rs.core.Response
import javax.ws.rs.core.UriBuilder

@Path('/notes')
class NotesResource {

@POST
@Consumes('text/plain')
@Produces('text/xml')
Response addNote(String text) {

// Create new Note object and store save it to DB
def note = new Note(text:text).save()

// Construct the URI for the newly created note
URI uri = UriBuilder.fromPath(note.id as String).build()

// Return an XML representation of the note object
// along with a Location response header with the URI
Response.created(uri).entity(note as XML).build()
}

@GET
@Produces('text/xml')
Response getNotes() {

// Find all notes in the database and return
// an XML representation of the note list
Response.ok(Note.findAll() as XML).build()
}

}

A note is an object that contains some text. Notes are instances of the Note Grails domain class. A collection of notes are made available through a RESTful service interface using the above NotesResource class and the grails-jaxrs plugin. A POST to http://host:port/notes/ creates a new note. A GET to http://host:port/notes returns an XML repsresentation of all existing notes in the database. For more details refer to the getting started tutorial.

Sunday, May 24, 2009

Moving towards IPF 1.7

Work on the next IPF release is in progress and focuses on

  • Components for implementing IHE actor interfaces (XDS.a, XDS.b, PIX, PDQ). Implementing IHE actor interfaces will be as simple as using other Camel components for communication (e.g. the HTTP component). IPF IHE components represent transactions in IHE profiles. For example, to create a web service for the server-side of the ITI-41 transaction (provide and register document set) from the XDS.b profile just write from('xdsb-iti41:service1') in your route definition. xdsb-iti41 is the name of the component, service1 the endpoint name. The rest of the route has to deal with connecting to (proprietary) backend systems that implement the corresponding actor functionality (document registry/repository). For more detailed information refer to this article (section Outlook).
  • DSL (Groovy builder) for creating CDA documents. This DSL supports the creation of structurally correct CDA documents by enforcing CDA-relevant schema definitions but without dealing with low-level XML details. See also outlook on IPF's CDA support.
  • Extension of OSGi support. Not all features of IPF have been fully OSGi-enabled with release 1.6, like the large binary support or the event infrastructure. This will be fixed with IPF 1.7. You'll also be able to use the new IHE components on OSGi platforms. We also plan to extend existing Camel components to make use of standard OSGi services such as the HTTP service.
  • Better IDE (Eclipse) integration, especially for developing IPF OSGi applications. This includes application development and packaging with Eclipse PDE tools and providing an Eclipse update site for downloading the IPF runtime. Code completion for DSL extensions is currently under discussion.
  • Performance testing framework. DSL extensions to performance-measure IPF applications including calculation and reporting of message processing statistics during load tests.

In parallel we will also create a SVN branch for experimenting with Camel 2.0 milestone releases. I'll let you know about our upgrade/migration experiences in a separate blog post.

Monday, April 13, 2009

Open eHealth Integration Platform 1.6.0 released

Last week we've released the Open eHealth Integration Platform (IPF) version 1.6.0. IPF is an extension of the Apache Camel routing and mediation engine. It has an application programming layer based on the Groovy programming language and comes with comprehensive support for message processing and connecting systems in the eHealth domain. Please see the release notes for further details.

Give it a try! We welcome your feedback!