PUT and POST getting 405 Method Not Allowed Error for Restful Web Services
Notice Allowed methods in the response
Connection: close
Date: Tue, 11 Feb 2014 15:17:24 GMT
Content-Length: 34
Content-Type: text/html
Allow: GET, DELETE
X-Powered-By: Servlet/2.5 JSP/2.1
It accepts only GET and DELETE. Hence, you need to tweak the server to enable PUT and POST as well.
Allow: GET, DELETE
Well, apparently I had to change my PUT calling function updateUser
. I removed the @Consumes
, the @RequestMapping
and also added a @ResponseBody
to the function. So my method looked like this:
@RequestMapping(value="/{id}",method = RequestMethod.PUT)
@ResponseStatus(HttpStatus.OK)
@ResponseBody
public void updateUser(@PathVariable int id, @RequestBody User temp){
Set<User> set1= obj2.getUsers();
for(User a:set1)
{
if(id==a.getId())
{
set1.remove(a);
a.setId(temp.getId());
a.setName(temp.getName());
set1.add(a);
}
}
Userlist obj3=new Userlist(set1);
obj2=obj3;
}
And it worked!!! Thank you all for the response.