web services - Error on Spring REST webservice call -
i have following webservice call
@requestmapping(value = "modifyuser/{userdn}", method = requestmethod.post, headers="accept=application/json") public @responsebody jsonobject modifyuser(@pathvariable string userdn, @requestbody directoryuser directoryuser) { // modify user boolean modifieduser = this.authenticationservice.modifyuser(userdn, directoryuser.getpassword(), directoryuser); // build jsonobject jsonobject jsonobject = new jsonobject(); jsonobject.put("modifyuser", modifieduser); return jsonobject; }
i using following client method access above rest webservice.
string url = "http://www.local.com:8080/commonauth-1.0-snapshot/api/authentication/modifyuser/"; defaulthttpclient httpclient = new defaulthttpclient(); httppost httppost = new httppost(url + "user6.external") jsonobject ob = new jsonobject(); ob.put("description", "updated"); system.out.println(ob.tostring()); stringentity entity = new stringentity(ob.tostring()); entity.setcontenttype("application/json"); httppost.setentity(entity); httpresponse httpresponse = httpclient.execute(httppost); httpentity httpentity = httpresponse.getentity();
i "the server refused request because request entity in format not supported requested resource requested method" error. wrong in code. able access other webservice calls without using @requestbody , using simple path variables. issue @requestbody , how using httppost.
public class directoryuser { private string displayname; private string fullname; private string username; private string firstname; private string lastname; private string description; private string country; private string company; private string phone; private string emailaddress; private string password; private boolean expirepassword = true; public string getdisplayname() { return displayname; } public void setdisplayname(string displayname) { this.displayname = displayname; } public string getfullname() { return fullname; } public void setfullname(string fullname) { this.fullname = fullname; } public string getusername() { return username; } public void setusername(string username) { this.username = username; } public string getfirstname() { return firstname; } public void setfirstname(string firstname) { this.firstname = firstname; } public string getlastname() { return lastname; } public void setlastname(string lastname) { this.lastname = lastname; } public string getdescription() { return description; } public void setdescription(string description) { this.description = description; } public string getcountry() { return country; } public void setcountry(string country) { this.country = country; } public string getcompany() { return company; } public void setcompany(string company) { this.company = company; } public string getphone() { return phone; } public void setphone(string phone) { this.phone = phone; } public string getemailaddress() { return emailaddress; } public void setemailaddress(string emailaddress) { this.emailaddress = emailaddress; } public string getpassword() { return password; } public void setpassword(string password) { this.password = password; } public boolean isexpirepassword() { return expirepassword; } public void setexpirepassword(boolean expirepassword) { this.expirepassword = expirepassword; } }
json string posting {"description":"updated"}
try { /* code */ if (httpresponse != null) { inputstream in = httpresponse.getentity().getcontent(); stringbuffer out = new stringbuffer(); int n = 1; while (n > 0) { byte[] b = new byte[4096]; n = in.read(b); if (n > 0) out.append(new string(b, 0, n)); } system.out.println(out.tostring()); } } catch (exception e) { e.printstacktrace(); }
can check status code says? also, please check if https.
Comments
Post a Comment