• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to build RESTful Web services in Java

 
Sagar Kar
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We have built a set of web services. However few of our clients are not able to understand web services. Hence we need to build some wrapper over our web services so that they can send in http request and receive xml responses.
I have heard that REST can do something similar.
Are their any framework which can help me build some REST services to wrap around my web services?
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's an emerging Java standard called JAX-RS which lets you build RESTful WS. It's implemented by the Jersey library (which you can find on dev.java.net).
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13071
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Although the Jersey project and the JSR-311 standard it is based on are still evolving, Jersey is quite usable in its present form. If you use NetBeans there is even a plugin.

Bill
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just noticed that, as of Monday, JSR-311 -the JAX-RS standard- is final. I expect Jersey to reach version 1.0 very quickly now.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13071
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSR-311 final
That is really great - the evolution process of this JSR has really been astonishingly rapid considering that the expert group has been in existance only a bit more than a year.

I think this reflects the rapidly increasing developer mind-share that REST has claimed and the complexity of SOAP standards and toolkits.

Jersey and IBM's project zero essentiall throw SOAP away and start fresh.

Bill
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65124
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One of the first tasks in my new job (started two weeks ago) is to create a RESTful web service for the product. So far, using the Jersey reference implementation of JSR133 has been very helpful in getting this up and running quickly.

As usual, the documentation is pretty poor, but even with that (and the fact that they assume that you are using Netbeans and Glassfish, neither of which I use) it's pretty easy to get things working. (The JSR133 Specification is actually a lot more helpful than the Jersey documentation.)
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bear Bibeault:
and the fact that they assume that you are using Netbeans and Glassfish, neither of which I use


That's a major gripe of mine lately. NetBeans, GlassFish and Maven are just supposed to be used, when it's rather obvious that many people don't.

I'm still waiting for a packaged binary of Jersey 1.0. Right now the download instructions point to a page full of Maven instructions; anyone not using it needs to hunt down at least 5 jar files on the web site.

I don't understand this: don't they want to make it easy to use?
[ October 16, 2008: Message edited by: Ulf Dittmer ]
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13071
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's a major gripe of mine lately.


Mine Too!

I do not want to be forced into installing and coping with somebody elses' idea of a great programming environment. Keeping up with the enormous number of jar files used is bad enough.

Bill
 
vinay ravaranch
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey Bear Bibeault

can you send me the procedure to build a simple webservice using REST?
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello "Vinay javaranch"-

On your way in you may have missed that we have a policy on screen names here at JavaRanch. Basically, it must consist of a first name, a space, and a last name, and not be obviously fictitious. Since yours does not conform with it, please take a moment to change it, which you can do right here.

As to your question, everything you need to get started with JAX-RS/Jersey is mentioned in this topic.
[ November 14, 2008: Message edited by: Ulf Dittmer ]
 
Peer Reynders
Bartender
Posts: 2968
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by vinay ravaranch:
can you send me the procedure to build a simple web service using REST?


You have to actually design an actual RESTful web service before you can build it. And Resource-Orientation is different from Object-Orientation.

Restful Web Services is in excellent resource for that. It for example outlines the design steps for a read/write resource:
First
  • Figure out the data set
  • Split the data set into resources


  • Then for each resource
  • Name the resources with URIs
  • Expose the subset of the uniform interface
  • Design the representation(s) accepted from the client
  • Design the representation(s) served to the client
  • Link the resource to existing Resources (using hypermedia links and forms)
  • Consider the typical course of events: what's supposed to happen?
  • Consider error conditions: what might go wrong?



  • Basically there is precious little that Jersey (JSR-311) can teach you about RESTful web services. You'll have to be well versed in the RESTful principles and practices and you'll need to know and understand the HTTP protocol (HTTP: The Definitive Guide) pretty well, better that most people who build regular web sites. Once you understand all that, you can use Jersey (or RestLet) to implement the RESTful service in Java - either framework does not guarantee that you will create a genuinely RESTful Web service just like Java can't guarantee that you will implement a genuinely Object-Oriented solution.
    [ November 14, 2008: Message edited by: Peer Reynders ]
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic