Thursday Oct 19, 2006

Using Custom Annotations in JAX-WS 2.1 to support HTTP Session State

Duke for GlassFish V2

Annotations are a first-class language feature in Java (tutorial, jsr-175). A standard specification like JAX-WS introduces standard annotations but custom annotations can be equally useful. Kohsuke uses a custom annotation to take advantage of a SPI (InstanceResolver) in the JAX-WS RI in GlassFish. The result is that adding a simple annotation (@HttpSessionScope, in the package) on a class tells the JAX-WS RI to create one instance of the class per each HTTP session.

Like any other non-standard mechanism, adding the annotation creates a dependency on a specific platform, but the dependency is explicitly declared (usually via an import statement), and the result is really clean an compact. Check Kohsuke's blog for details.