wood burning stoves 2.0*
The moose likes Web Services and the fly likes Empty request body in REST service Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "Empty request body in REST service" Watch "Empty request body in REST service" New topic

Empty request body in REST service

Sam Mc Kee

Joined: Aug 20, 2010
Posts: 3
I have a REST service that accepts JSON in the request body. The method is defined as follows:

In the body of the request is a list of JSON objects representing ShoppingListItem objects, and this works fine. However, I would expect it also to work if the request body is empty--that the items variable would simply be null. However I get a 500 error before it even reaches my service when I post a request with an empty body.

Is this behavior normal/expected?


Sujoy Choudhury
Ranch Hand

Joined: Sep 17, 2008
Posts: 136

I guess you are using Jersey, and in that case Jersey won't be able to find the matching method to call.
As far as I know, this is expected but I would wait for some experts to shed some more lights here.

Thanks and Regards,
Sujoy Choudhury
Ranch Hand

Joined: Sep 17, 2008
Posts: 136

My answer was wrong and I guess I didn't read your post well.
I was thinking about the uri and not the POST message being blank.

As per the REST architecture, you will call POST only if you want to UPDATE the resource.
And in your case you are calling POST without any payload.
This is an interesting thing. Let me try this.
I agree. Here's the link: http://aspose.com/file-tools
subject: Empty request body in REST service
Similar Threads
How to submit JSON data as request body in Apache CXF jax-rs (REST)
how correctly produce json by RESTFUL web service on Fuse ESB?
I am not able to get parameter value in @PathParam("userID") of REST webService
Map<Integer, String> or String[] ?
Send PUT to different RESTful webservice running on the same local Tomcat?