dimanche 19 avril 2015

Return JsonObject in spring restful webservice

I am using spring framework. I have a webservice in Wepsphere server like that



@RequestMapping (value="/services/SayHello2Me" , method=RequestMethod.GET, headers="Accept=application/json")
@ResponseBody
public JSONObject SayHello2Me(HttpServletRequest request) throws Exception {
String input = (String) request.getParameter("name");
String output = "hello " + input + " :)";
JSONObject outputJsonObj = new JSONObject();
outputJsonObj.put("output", output);
return outputJsonObj;
}


When I call it form Chrome like http://myserver/services/sayHello2Me?name='baris', it returns me that error :



Error 404: SRVE0295E: Error reported: 404



If I change annotions in my webservice like that



@RequestMapping (value="/services/SayHello2Me")
@ResponseBody
public JSONObject SayHello2Me(HttpServletRequest request) throws Exception {

String input = (String) request.getParameter("name");
String output = "hello " + input + " :)";
JSONObject outputJsonObj = new JSONObject();
outputJsonObj.put("output", output);

return outputJsonObj;
}


then when I call it form Chrome like http://myserver/services/sayHello2Me?name='baris', it returns me that error :



Error 406: SRVE0295E: Error reported: 406



There is a jsonobject problem because if I return String insted of jsonobject in same webservice it returns me successfully.


How can I return Jsonobject in spring restful webservice?


Aucun commentaire:

Enregistrer un commentaire