java - Sending application/xml POST message to REST API doesn't work -
this post method jax-rs annotations:
@post @consumes(mediatype.application_xml) @produces(mediatype.text_plain) public response storeuser(user user) { boolean wasstored = jpauserstore.storeuser(user); if (wasstored) { return response.ok("user stored.").build(); } else { return response.status(status.bad_request).build(); } } and class user jaxb annotations:
@xmlrootelement @xmlaccessortype(xmlaccesstype.field) public user { @xmlelement(name = "name") protected string name; @xmlelement(name = "address") protected string address; public void setname(string name) { this.name = name; } public string getname() { return this.name; } public void setaddress(string address) { this.address = address; } public string getaddress() { return this.address; } } the rest web service runs on jetty. when send request message (using restclient firefox plugin) content type "application/xml" , body
<?xml version="1.0" encoding="utf-8"?> <user> <name>max</name> <address>main street 12</address> </user> to appropriate resource 400 bad request returned. according log method jpauserstore.storeuser(...) not executed.
what reason, why method annotated @post not executed , ok returned?
by default root element user class user, need use @xmlrootelement(name="user") match xml document.
Comments
Post a Comment