Note that there are some explanatory texts on larger screens.

plurals
  1. POError on Spring REST webservice call
    primarykey
    data
    text
    <p>I have following webservice call</p> <pre><code>@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; } </code></pre> <p>I am using following client method to access above REST webservice. </p> <pre><code>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(); </code></pre> <p>I always get "The server refused this request because the request entity is in a format not supported by the requested resource for the requested method" error. What is wrong in my code. I am able to access other webservice calls without using @RequestBody and using simple path variables. The issue is with @RequestBody and how i am using HttpPost.</p> <pre><code>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; } } </code></pre> <p>JSON string i am posting is {"description":"updated"}</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload