Vasanth
Vasanth

Reputation: 494

spring mvc restfull webservice handle post method " 415 Unsupported Media Type"

@Controller
public class Mycontroller {
@RequestMapping(method = RequestMethod.GET,value="/insertAdminUserInfo")
public void insertPerformanceInfo(HttpServletRequest request, Model model) throws Exception {
  String userId = (String) request.getParameter("user");
  String region = (String) request.getParameter("status");
  //my business logic
  model.addAttribute("result","success");

}
@RequestMapping(value="/insertAdminUserInfo",method=RequestMethod.POST)
public void insertPerformanceInfoPOST(@RequestBody UserInfo userInfo, Model model) throws Exception {
 //my business logic
model.addAttribute("result","success");
}
@RequestMapping(value="/insertAdminUserInfo",method=RequestMethod.PUT)
public void insertPerformanceInfoPUT(@RequestBody UserInfo userInfo, Model model) throws Exception {
//my business logic
model.addAttribute("result","success");
}
}

This my code , i am trying to send the json data using POST or PUT method, via SOAP UI or REst Client , i am getting below error .

FYI : working fine for GET method.

Response Header:
Status Code: 415 Unsupported Media Type 
    Connection: Close 
Content-Language: en-US 
Content-Type: text/html;charset=utf-8 
Date: Mon, 03 Feb 2014 12:34:44 GMT 
Server: WebSphere Application Server/7.0 
Transfer-Encoding: chunked </br>

Response Body :

Error 415: SRVE0295E: Error reported: 415

Please suggest some idea.

Regards Vasanth D

Upvotes: 1

Views: 7982

Answers (2)

sateesh
sateesh

Reputation: 11

Annotation "RequestBody" expects the Content-Type as "application/json". So make sure to set Content-Type before you make a call to api.

Upvotes: 0

Bart
Bart

Reputation: 17371

Your Content-Type header does not match the media type.

If you, for example, send a JSON body to your service the content type should be:

Content-Type: application/json

Upvotes: 3

Related Questions