Monthly Archives: May 2009

Creating a Restful Web Service Part 1

Objective: To develop a web service that is to be used internally by applications to retrieve and write data to an Oracle database.

I wanted to develop a web service that was designed with the REST framework in mind, SOAP is just too “noisy”, and overly complex.   The web service had to be able connect and interact with an Oracle database, it also had to return any data from the database as XML.  You can view the results directly from a web browser if it’s XML, but it is not really necessary as a web service is mostly a non-human readable resource.

So, I was developing with Java – and had to try an work out what the best tools, APIs would be, bearing in mind the myriad of tools out there on the web.  It took quite a while looking at all the various API’s out there (Spring, Hibernate, iBATIS, EclipseLink, Toplink – the list goes on), but I chose ones that matched the following criteria:
a) if a technology was already in use at work, then that had to be adopted – in order to stop a proliferation of different technologies being used, supported and maintained.

b) easy to use and understand.

c) have decent community support behind them – so if problems arise then at least someone out there may be able to lend a hand.

d) look likely to be well supported in the future without fading into obscurity in the next couple of weeks/months.

Choosing the Right Tools – My Software Stack

  • Java IDE – is Eclipse Europa v3.3.2
  • Apache Tomcat Application Server v5.5.17

A really nice and clean well supported framework.  Some of the tutorials were a bit raw but they have improved of recent and the documentation is getting better all the time.  They are constantly improving the API and stable releases are issued on a resonably regular basis.  They are keen to adopt good standards and it was pleasing to see that WADL is supported in their extended APIs for Restlet.

  • For Object Relational Mapping (ORM) with Oracle I chose Toplink  (version 10g Release 3 10.1.3.3.0) and the Workbench software- don’t even think about using raw JDBC API’s – it’s much less work to use Toplink rather than code everything from scratch.
  • For XML to Object ORM, I chose Sun’s JAXB v2.0 implemenation – so, so, so much better than Toplinks crummy efforts (so I am saying Toplink is good for database ORM but not for XML ORM) – I spent so many wasted development hours on this piece of crud – so don’t use it unless you want to a miserable life as a developer.  JAXB is nice, its from Sun so it should conform to some form of standard.  The docs are good and it takes seconds to run the JAXB compiler from a command line along with your XSD schema and generate your Java classes.  Pretty good all round.

In my next post I explain how I used the above to create my REST web service.