I'm trying to send POST data to my JAX-RS web service. The only thing in my
POST body is the JSON I wish to submit:
{ "Book": {"name":"Gulliver's Travels", "ISBN": "12345678"} }
There is nothing else in the POST body; no parameters or anything. Just the
above JSON. Here is my service class:
===========
@Path( "/bookService" )
public class BookService {
@POST
@Path( "/add" )
@Consumes( "application/json" )
public void addBook( @FormParam( "" ) Book book ){
// where's my book?
}
}
===========
My understanding is that @FormParam( "" ) will grab all of the POST body; is
this correct?
The above returns an empty (not null) Book when I execute my client request.
Switching the parameter type to String results in an empty string. I've
tried changing the @FormParam annotation to @QueryParam, removing @FormParam
altogether, switching from POST to GET and sticking the JSON in a GET
request parameter, etc... The only thing that works is retrieving the
String value as a QueryParam when using GET (of course, while switching the
client side to perform a GET request and sticking the JSON in a GET
parameter, and setting the @Consumes type to text/plain).
ContentType/@Consumes is probably not the problem, as the function is
definitely being called with every request. The JSON is also valid. I've
also tried switching to XML but have the same problem.
How should I be sending the POST data? Should the JSON be in a parameter,
or can the JSON string be the only thing in the POST body?
I'm sure I'm missing something basic... Like sending an improper POST
request. :) I'm using ExtJS to make an AJAX request to the addBook()
method:
Ext.Ajax.request({
url: '/bookService/add',
jsonData: record.data,
method: 'POST'
});
Any help would be greatly appreciated. Thank you!
- Dave
--
View this message in context:
http://www.nabble.com/POST-body-data-and-JAX-RS-tp21588171p21588171.html
Sent from the cxf-user mailing list archive at Nabble.com.