Meaningless Drivel is fun!*
The moose likes Web Services and the fly likes Processing arguments/Entity body in GET/POST/PUT Request - RESTFul WebServices Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "Processing arguments/Entity body in GET/POST/PUT Request - RESTFul WebServices" Watch "Processing arguments/Entity body in GET/POST/PUT Request - RESTFul WebServices" New topic
Author

Processing arguments/Entity body in GET/POST/PUT Request - RESTFul WebServices

John Champine
Greenhorn

Joined: Jul 03, 2007
Posts: 8
Greetings Folks,

I have been researching on RESTFul Webservices for a couple of weeks now. I currently work with JAX-RPC(SOAP). I believe I got the basic hang of it and I like how things are simpler in Rest in comparison to RPC.

I have looked at all the examples provided in jersey distribution, Doug Kohlers's blog entries(along with other Sun developers blogs) to understand how Resource classes/methods are working. I have looked through the JAX-RS spec as well.

The issue I am stuck with is how do I extract the arguments sent by the client through POST or Put or even GET requests from my resource http methods? I can grab values using UriParams, but how about the values sent through POST? I just can't seem to figure out how I can extract values from entity bodies(if I am using the correct term here).

I have come to the conclusion after looking at the jersey examples that I lack background knowledge in understanding how Response.builder, jaxb etc. is used to construct response and send those back. I can't seem to find examples describing how these methods are working in unison to construct response objects sent back to client. I saw in Doug's blog how jax-ws is used to extract values, but I don't want to use jax-ws. I want to stick to jax-rs.

Will anyone please provide me with a few links on where to start reading up on these? I am guessing JAXB tutorial and probably reading up on servlets will give me some starting point.

Thanks in advance.
Regards.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12678
    
    5
As far as extracting information from a REST style URL is concerned, here is what I played with to extract information from the request by examining the result from getPathInfo():



Where rMap is a Map where the key is the name of the RESTful service used in the URL and the value is the name of the class that takes care of those requests. This routine was used to simply determine that the service name exists in the Map and return the service name or null, and is called BEFORE trying to extract parameters with the usual servlet methods.

Extraction of further parameters from the pathInfo and the body of the request is up to the individual service classes. At this point the body of the request (if there is one) has not been read so you can get it with getInputStream() or getReader().

In the case of POSTed data, note that it may not be in the typical parameter-name / value format produced by HTML forms. It might be XML or a variety of other formats.


Bill


Java Resources at www.wbrogden.com
Peer Reynders
Bartender

Joined: Aug 19, 2005
Posts: 2906
I hacked a "Hello World" resource that works on the Jersey 0.5 (stable):
However it looks like the specification will continue to change.






"Don't succumb to the false authority of a tool or model. There is no substitute for thinking."
Andy Hunt, Pragmatic Thinking & Learning: Refactor Your Wetware p.41
John Champine
Greenhorn

Joined: Jul 03, 2007
Posts: 8
Bill, Peer thanks very much for your responses. Greatly appreciated!

I get the hang of it now. Reading your other posts in this forum, I started looking at Restlet Framework. Wow! They make things so much easier!

Only issue I am having with Restlet is to get it deployed on Sun App Server using Netbeans 6.0. But I should be able to figure that out in due time.

Thanks again. Happy Monday!!
Peer Reynders
Bartender

Joined: Aug 19, 2005
Posts: 2906
Originally posted by John Champine:
I started looking at Restlet Framework. Wow! They make things so much easier!


Note that J�r�me Louvel, Project Lead of the Restlet project, is a member of the JSR-311 Expert Group.
You may also find this blog entry of interest: Rails, JSR311, Restlet and Jersey.

In terms of studying the different approaches to implementing a RESTful web service Leonard Richardson/Sam Ruby's "Social Bookmarking Web Service" from Chapter 7 of their book Restful Web Services seems to have become a standard baseline.

The original Ruby implementation can be found in the code examples on O'Reilly's website (in the (ruby/ch7) folder).
The Restlet implementation is found under the (src/org.restlet.example/org/restlet/example/book/rest/ch7) folder of the distribution.
The (partial) Jersey implementation is found under (examples/bookmark) folder of the distribution.

Only time will tell whether JSR-311, which may be included in a future Java EE specification, will strip RESTful web services of their "simplicity of implementation". It also is important that a RESTful web services framework remain independent from Servlets as outlined here. This doesn't prevent it from being hosted by a servlet engine - it just should by design not be constrained by the Servlet specification.
John Champine
Greenhorn

Joined: Jul 03, 2007
Posts: 8
Thanks again Peer!! You are a great source of knowledge
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Processing arguments/Entity body in GET/POST/PUT Request - RESTFul WebServices
 
Similar Threads
SOA and REST with JBOSS
benefits of a serialization framwork like castor
Creating a webservice using XML over HTTP.
RESTful Webservice - What are the different ways to create it ?
web service framework for beginners with tutorials