Friday, September 4, 2009

JavaFX 1.2+ Spring + Hibernate

Related to discussions going on in BoJUG, I was tempted to develop a Proof-of-Concept for using JavaFX as view technology in a web application backed by spring and hibernate stack . Well Spring already provides remoting support for communicating to rich clients. Currently,spring supports four remoting technologies .
In my application, I am using Spring's HTTP Invoker which allows for Java serialization via HTTP, supporting any Java interface (just like the RMI invoker). The corresponding support classes are

1) org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean

is a factory bean for HTTP invoker proxies. It behaves like the proxied service when used as bean reference, exposing the specified service interface. Serializes remote invocation objects and deserializes remote invocation result objects.

2) org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter

is an HTTP request handler that exports the specified service bean as HTTP invoker service endpoint, accessible via an HTTP invoker proxy.It deserializes remote invocation objects and serializes remote invocation result objects.

I started of with developing an application that fetches and displays employee data using JavaFX,Spring and Hibernate.
The whole application was developed as 2 separate Netbeans projects.

1)empFXClient : is a JavaFX application.
2)empRemote: is a web application that uses empFXClient as view by embedding it as an applet inside a web page.

You can browse the code for both the projects online here . If you have Netbeans 6.5 and/or an SVN client then you can check out both the netbeans projects locally from kenai using the following URL and play with it. (requires kenai registeration)

We require 2 config files on the server side









Spring Http invoker uses Java serialization just like RMI, but provides the same ease of setup
as Caucho's HTTP-based Hessian and Burlap protocols. As springs api docs says "HTTP invoker is the recommended protocol for Java-to-Java remoting.
It is more powerful and more extensible than Hessian and Burlap, at the expense of being tied to Java. Nevertheless, it is as easy to set up as Hessian and Burlap, which is its main advantage compared to RMI".

There is a nice example available which shows integrating JavaFX with JBoss Seam/spring using Flamingo DS through Hessian protocol.