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 Invoking REST webservices. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "Invoking REST webservices." Watch "Invoking REST webservices." New topic
Author

Invoking REST webservices.

Venkataramanan Amirthalingam
Greenhorn

Joined: Nov 27, 2008
Posts: 20
Hi All,

I am new to REST webservices. We have a need to invoke REST webservices. Which tools/frameworks can we use? I heard about Jersey, Wink, Axis2,
etc, but do not know them in detail. Please suggest/let me know the popular and best tool for invoking REST webservices.

--venkat
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41812
    
  62
Jersey is the reference implementation of the JAX-RS API, so I'd start by looking into that.

While Axis2 can be used as client to any web service, it doesn't support JAX-RS specifically, which would rule it out in my book. It's really a SOAP stack, and that's what one should use it for.


Ping & DNS - my free Android networking tools app
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
Three other web service stacks that support JAX-RS are:
- Apache CXF http://cxf.apache.org/
With XML and JSON data binding "out of the box".
- RESTlet http://www.restlet.org/
Very lightweight and easy to use. My first choice if I am to quickly get a standalone (not running in any kind of container) RESTful webservice up and running.
With the Grizzly extension it also works very well under quite heavy load.
- JBoss RESTeasy http://www.jboss.org/resteasy/
Regretfully, I don't have any experiences with this one yet.
Best wishes!
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12781
    
    5
IF all you are doing is GET operations, plain old Java may be sufficient with HttpURLConnection.

IF you are dealing with big name REST servers like Yahoo or Amazon or Google, you can probably find great sample code in a variety of languages on their site.

Bill
Darvesh Niz
Ranch Hand

Joined: May 12, 2008
Posts: 119
Hi William

We are in a process of calling a .NET Rest WS which returns back an xml document

We are also evaluating the best framework which we can use since our requirement is to only do a pull and we are not creating any Rest service.
Any opinion which way to approach it.

There are many framework in the market like Jersey, Restlet etc...

Thanks
darniz
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12781
    
    5
I see no need for a "Framework" at all. The standard Java library has all you need - for example HttpURLConnection.

Do a GET, grab the return as a stream, input to standard XML parser and boom - you got a DOM that you can pick at with standard XPath etc etc.

It really is that simple. Which is why so many people are wondering exactly why they got so deeply involved with some framework.

Bill

Darvesh Niz
Ranch Hand

Joined: May 12, 2008
Posts: 119
Thank a lot
Thats whats i thought about it.
just wanted to get an opinion about it.

darniz
Darvesh Niz
Ranch Hand

Joined: May 12, 2008
Posts: 119
The other question is that how can i handle connection timeout if i adopt this approach.

Rashid
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
The failure to issue a request to a RESTful web service can be handled in a number of ways, depending on the requirements of your application. For example:
- Log the error and discard the request.
- Implement a retry mechanism that retries failed requests a certain number of times, perhaps with a certain delay between the retries.
- Use queuing and remove a request from the queue only when a request has been successfully issued.
If a request fails, it can be put to the end, or some other location, of the queue and it will thus be retried after some time.

Best wishes!
Darvesh Niz
Ranch Hand

Joined: May 12, 2008
Posts: 119
Thanks

i might be using apache httpclient so that i can also put timeout on the request, since i dont want my invoker to wait for an unlimited time if hte response is too slow.

Apart from that all other issue like badurl etc.. can be handled.

darniz
Samuel Behrman
Ranch Hand

Joined: Oct 02, 2009
Posts: 49
Hi.
You can refer to the url below, and I believe it will be useful.
http://www.devx.com/Java/Article/40659


RAQ Report: Web-based Excel-like Java reporting tool.
Deiveehan Nallazhagappan
Ranch Hand

Joined: May 27, 2002
Posts: 33
I tried using Apache Wink and it seems to be pretty simple - I was able to run a simple program within minutes.


Deiveehan N - SCJP, SCWCD, SCBCD, IBM-484, SCEA
You may be in the right track, but if you sit there, you will get run over !!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Invoking REST webservices.