File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Services and the fly likes How to build RESTful Web services in Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "How to build RESTful Web services in Java" Watch "How to build RESTful Web services in Java" New topic
Author

How to build RESTful Web services in Java

Sagar Kar
Greenhorn

Joined: Sep 03, 2004
Posts: 25
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?


Warm regards,<br />Sagar Kar.<br />SCJP 1.4, SCBCD 1.3
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42358
    
  64
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).


Ping & DNS - my free Android networking tools app
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12809
    
    5
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
Marshal

Joined: Mar 22, 2005
Posts: 42358
    
  64
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

Joined: Mar 22, 2000
Posts: 12809
    
    5
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

Joined: Jan 10, 2002
Posts: 61447
    
  67

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.)


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42358
    
  64
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

Joined: Mar 22, 2000
Posts: 12809
    
    5
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

Joined: Nov 14, 2008
Posts: 3
hey Bear Bibeault

can you send me the procedure to build a simple webservice using REST?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42358
    
  64
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

Joined: Aug 19, 2005
Posts: 2922
    
    5
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 ]
     
    Consider Paul's rocket mass heater.
     
    subject: How to build RESTful Web services in Java