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

Empty request body in REST service

Sam Mc Kee
Greenhorn

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?

Thanks!
Sam

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