Saturday, August 21, 2010

Web Services with Apache CXF and Cayenne

This new module shall show the integration with a standard web service framework. Apache Cayenne provides a web services framework with Hessian, but with this example it shows how you could use Cayenne with CXF.

As parts of the application will be running in different JVM, we need data transfer objects. Apache Cayenne is used on the server side, while the client uses only distributed DTO's and handlers.

First of all the choice of Apache CXF instead of Axis2 was mainly because of the tighter integration of Java web service standards and the opportunity of OSGi usage in the future. The documentation on some parts of Java web services is not the best today (in 2010) but many googled resources indicate that the web service arena is still in heavy development to enable enterprise like programming requests and interopability between Java and other platforms such as .NET.

The example shall show a hello world like example but based on yafra using a database backend through Cayenne as ORM and some basic session functionalities. As the web service server is started as standalone server the usage of a singleton is needed to set the Cayenne context at startup. Basic session handling is possible and will store session id and some stuff like username or others.

Requests to handlers/functions/processes can be simple web services, even accessible outside of a full application client but as well fully integrated with session access to verify that a session was allowed before you get other data.

As many of the standards within web services are not yet mature enough like servlets or EJB's, many things are still proprietary to an implementation like Apache CXF or subject of changes in the future. Therefore the example is only a basic one.

The key idea was to have an adapter within the Eclipse RCP fat client to exchange the server handling between EJB's and Web Services. This needs still to be worked out and of course is only useful for this framework in sense as an example of Java technology usage.

1 comment: